73 lines
1.3 KiB
Swift
73 lines
1.3 KiB
Swift
import ComposableArchitecture
|
|
import SwiftUI
|
|
|
|
@Reducer
|
|
public struct InfoViewFeature {
|
|
|
|
public init() { }
|
|
|
|
@ObservableState
|
|
public struct State: Equatable {
|
|
let titleText: String
|
|
let bodyText: String
|
|
|
|
public init(
|
|
title titleText: String,
|
|
body bodyText: String
|
|
) {
|
|
self.titleText = titleText
|
|
self.bodyText = bodyText
|
|
}
|
|
}
|
|
|
|
public enum Action {
|
|
case dismissButtonTapped
|
|
}
|
|
|
|
@Dependency(\.dismiss) var dismiss
|
|
|
|
public var body: some ReducerOf<Self> {
|
|
Reduce { _, action in
|
|
switch action {
|
|
case .dismissButtonTapped:
|
|
return .run { _ in await self.dismiss() }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public struct InfoView: View {
|
|
let store: StoreOf<InfoViewFeature>
|
|
|
|
public init(store: StoreOf<InfoViewFeature>) {
|
|
self.store = store
|
|
}
|
|
|
|
public var body: some View {
|
|
VStack(spacing: 40) {
|
|
Text(store.bodyText)
|
|
.font(.callout)
|
|
.padding()
|
|
Spacer()
|
|
}
|
|
.navigationTitle(store.titleText)
|
|
.padding(.horizontal)
|
|
.navigationBarBackButtonHidden()
|
|
.toolbar {
|
|
DoneButton { store.send(.dismissButtonTapped) }
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
InfoView(
|
|
store: Store(
|
|
initialState: InfoViewFeature.State(
|
|
title: "Generic Info View",
|
|
body: "Explain what this view does here..."
|
|
),
|
|
reducer: InfoViewFeature.init
|
|
)
|
|
)
|
|
}
|