蓝图 (Blueprint)

Tests Generate and publish docs Linter

用于 iOS 的声明式 UI 构建库,使用 Swift 编写

Blueprint 极大地简化了随着应用程序状态变化构建和更新视图的任务。

let view = BlueprintView(element: Label(text: "Hello from Blueprint!"))

这个库的作用是什么?

Blueprint 提供了一个架构,允许你:

我应该在什么时候使用它?

任何时候你想显示一个视图层级结构,但不想管理视图生命周期时,都可以使用 Blueprint(提示:管理视图生命周期是大多数传统 UIKit 代码的主要部分)。 有时你*想要*管理视图生命周期(例如,复杂的动画和过渡),对于这些情况,你可能想坚持使用传统方法。

它如何与 UIKit 交互?

Blueprint 不是 UIKit 的替代品! 从一开始,Blueprint 就被设计为对平台提供的所有强大工具的补充。 你可以使用 Blueprint 来管理单个视图控制器的显示,或者管理代表屏幕一小部分的单个视图的显示。 同样,在 Blueprint 层级结构*内*托管标准视图和控件也很简单,始终为你留下一个“逃生出口”。

它如何与 SwiftUI 交互?

它们服务于类似的目的,并且 SwiftUI 极大地影响了 Blueprint 的 API。 但是,Blueprint 早于 SwiftUI,并且工作方式略有不同。 你可以在 SwiftUI 中托管一个 BlueprintView 以将 Blueprint 嵌入到 SwiftUI 中,你还可以使用提供的 ElementView 来创建 Blueprint 的 Xcode 预览。 因为 SwiftUI 由 UIViewController 托管,而 Blueprint 由 UIView 托管,所以我们没有提供将 SwiftUI 嵌入到 Blueprint 中的方法。

入门

Swift Package Manager

SwiftPM compatible

如果你正在开发自己的包,请确保在 Package.swift 中的 dependencies 中包含 Blueprint

dependencies: [
    .package(url: "https://github.com/square/Blueprint", from: "5.1.0")
]

在 Xcode 11+ 中,使用 File > Swift Packages > Add Package Dependency... 将 Blueprint 直接添加为项目的依赖项。 提示时提供 git URL:git@github.com:square/Blueprint.git

提供了两个模块

文档

API 文档可在 square.github.io/Blueprint 获得

入门

  1. Hello, World

  2. 元素层级结构

  3. 构建自定义元素

  4. 布局

参考

  1. Element (元素)

  2. BlueprintView

  3. ViewDescription (视图描述)

  4. Transitions (过渡)

教程

教程设置说明

  1. 在视图控制器中使用 Blueprint

  2. 使用 Blueprint 构建收据布局

本地开发

本项目使用 MiseTuist 来生成用于本地开发的项目。 请按照以下步骤进行 zsh 的推荐设置。

# install mise
brew install mise
# add mise activation line to your zshrc
echo 'eval "$(mise activate zsh)"' >> ~/.zshrc
# load mise into your shell
source ~/.zshrc
# tell mise to trust Blueprint's config file
mise trust
# install dependencies
mise install

# only necessary for first setup or after changing dependencies
tuist install --path SampleApp
# generates and opens the Xcode project
tuist generate --path SampleApp

版权所有 2019 Square, Inc.

根据 Apache License, Version 2.0(“许可证”)获得许可;除非符合许可证的规定,否则不得使用此文件。 您可以在以下位置获得许可证副本:

https://apache.ac.cn/licenses/LICENSE-2.0

除非适用法律要求或以书面形式达成协议,否则按“原样”分发的软件不提供任何形式的明示或暗示的保证或条件。 请参阅许可证,以了解管理权限和限制的具体语言。