feat: Moves info view feature to it's own module.
This commit is contained in:
72
Sources/InfoViewFeature/InfoView.swift
Normal file
72
Sources/InfoViewFeature/InfoView.swift
Normal file
@@ -0,0 +1,72 @@
|
||||
import ComposableArchitecture
|
||||
import Styleguide
|
||||
import SwiftUI
|
||||
|
||||
@Reducer
|
||||
public struct InfoViewFeature: Sendable {
|
||||
|
||||
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 {
|
||||
TextLabel(store.bodyText)
|
||||
Spacer()
|
||||
}
|
||||
.navigationTitle(store.titleText)
|
||||
.textLabelStyle(.secondary)
|
||||
.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
|
||||
)
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user