Blueprint 极大地简化了随着应用程序状态变化构建和更新视图的任务。
let view = BlueprintView(element: Label(text: "Hello from Blueprint!"))
Blueprint 提供了一个架构,允许你:
任何时候你想显示一个视图层级结构,但不想管理视图生命周期时,都可以使用 Blueprint(提示:管理视图生命周期是大多数传统 UIKit 代码的主要部分)。 有时你*想要*管理视图生命周期(例如,复杂的动画和过渡),对于这些情况,你可能想坚持使用传统方法。
Blueprint 不是 UIKit 的替代品! 从一开始,Blueprint 就被设计为对平台提供的所有强大工具的补充。 你可以使用 Blueprint 来管理单个视图控制器的显示,或者管理代表屏幕一小部分的单个视图的显示。 同样,在 Blueprint 层级结构*内*托管标准视图和控件也很简单,始终为你留下一个“逃生出口”。
它们服务于类似的目的,并且 SwiftUI 极大地影响了 Blueprint 的 API。 但是,Blueprint 早于 SwiftUI,并且工作方式略有不同。 你可以在 SwiftUI 中托管一个 BlueprintView
以将 Blueprint 嵌入到 SwiftUI 中,你还可以使用提供的 ElementView
来创建 Blueprint 的 Xcode 预览。 因为 SwiftUI 由 UIViewController 托管,而 Blueprint 由 UIView 托管,所以我们没有提供将 SwiftUI 嵌入到 Blueprint 中的方法。
如果你正在开发自己的包,请确保在 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
。
提供了两个模块
BlueprintUI
包含核心架构和布局类型。BlueprintUICommonControls
包括代表一些常见 UIKit
视图和控件的元素。API 文档可在 square.github.io/Blueprint 获得
本项目使用 Mise 和 Tuist 来生成用于本地开发的项目。 请按照以下步骤进行 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
除非适用法律要求或以书面形式达成协议,否则按“原样”分发的软件不提供任何形式的明示或暗示的保证或条件。 请参阅许可证,以了解管理权限和限制的具体语言。