TCACustomAlert

📝 描述

此包允许使用来自 The Composable Architecture(由 Point-Free 提供)进行自定义提示框的呈现。

安装

在 Xcode 中作为包依赖项安装。

  1. 文件 菜单中,选择 添加包...
  2. 在包 URL 字段中输入 https://github.com/Naturally-Inviting/swift-tca-custom-alert

基础

要创建一个提示框,您需要有一个 store,它可以限定 CustomTcaAlert.StateCustomTcaAlert.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 访问此演示应用程序。

呈现演示

🏎️ 路线图