此包允许使用来自 The Composable Architecture(由 Point-Free 提供)进行自定义提示框的呈现。
在 Xcode 中作为包依赖项安装。
https://github.com/Naturally-Inviting/swift-tca-custom-alert
。要创建一个提示框,您需要有一个 store,它可以限定 CustomTcaAlert.State
和 CustomTcaAlert.Action
的更改范围。然后传入一个视图作为提示框内容。
import TCACustomAlert
struct MyView: View {
let store: StoreOf<MyFeature>
var body: some View {
VStack {
ContentView()
}
.customTcaAlert(
store.scope(
state: \.alertState,
action: \.alert
),
content: {
VStack(spacing: 16) {
Text("Hello")
.font(.headline)
Button("Dismiss", action: { store.send(.alert(.dismiss)) })
.padding(.top)
}
.padding()
.background()
.cornerRadius(8)
.padding(.horizontal)
}
)
}
}
可以通过 TCACustomAlert.xcworkspace
访问此演示应用程序。
呈现演示 |
---|
![]() |