はじめに
TCA勉強記録第二弾です。
今回はSheetを実装してみました。
実装
ContentView
import SwiftUI
import ComposableArchitecture
struct ContentView: View {
let store: StoreOf<Feature>
var body: some View {
WithViewStore(store) { viewStore in
Button {
viewStore.send(.sheetPresented)
} label: {
Text("表示")
}
.sheet(isPresented: viewStore.binding(
get: \.sheet,
send: .sheetDismissed
)) {
Text("Sheet")
}
}
}
}
Feature
import Foundation
import ComposableArchitecture
struct Feature: ReducerProtocol {
struct State: Equatable {
var sheet: Bool = false
}
enum Action: Equatable {
case sheetPresented
case sheetDismissed
}
func reduce(into state: inout State, action: Action) -> EffectPublisher<Action, Never> {
switch action {
case .sheetPresented:
state.sheet = true
return .none
case .sheetDismissed:
state.sheet = false
return .none
}
}
}
完成
おわり
Sheetを実装することができました。