1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【SwiftUI】TCAでSheetを実装する

Posted at

はじめに

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
        }
    }
}

完成

Simulator Screen Recording - iPhone 14 Pro - 2023-04-07 at 21.37.03.gif

おわり

Sheetを実装することができました。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?