Skip to content

Commit e73fd0a

Browse files
committed
Merge branch 'navigation-beta' into prerelease/1.0
2 parents c9289cd + 3f0cdf9 commit e73fd0a

File tree

67 files changed

+4481
-392
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+4481
-392
lines changed

Examples/CaseStudies/SwiftUICaseStudies/03-Navigation-Sheet-LoadThenPresent.swift

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,50 +13,39 @@ private let readMe = """
1313

1414
struct LoadThenPresent: Reducer {
1515
struct State: Equatable {
16-
var optionalCounter: Counter.State?
16+
@PresentationState var counter: Counter.State?
1717
var isActivityIndicatorVisible = false
18-
19-
var isSheetPresented: Bool { self.optionalCounter != nil }
2018
}
2119

2220
enum Action {
23-
case onDisappear
24-
case optionalCounter(Counter.Action)
25-
case setSheet(isPresented: Bool)
26-
case setSheetIsPresentedDelayCompleted
21+
case counter(PresentationAction<Counter.Action>)
22+
case counterButtonTapped
23+
case counterPresentationDelayCompleted
2724
}
2825

2926
@Dependency(\.continuousClock) var clock
30-
private enum CancelID {}
3127

3228
var body: some Reducer<State, Action> {
3329
Reduce { state, action in
3430
switch action {
35-
case .onDisappear:
36-
return .cancel(id: CancelID.self)
31+
case .counter:
32+
return .none
3733

38-
case .setSheet(isPresented: true):
34+
case .counterButtonTapped:
3935
state.isActivityIndicatorVisible = true
4036
return .task {
4137
try await self.clock.sleep(for: .seconds(1))
42-
return .setSheetIsPresentedDelayCompleted
38+
return .counterPresentationDelayCompleted
4339
}
44-
.cancellable(id: CancelID.self)
4540

46-
case .setSheet(isPresented: false):
47-
state.optionalCounter = nil
48-
return .none
49-
50-
case .setSheetIsPresentedDelayCompleted:
41+
case .counterPresentationDelayCompleted:
5142
state.isActivityIndicatorVisible = false
52-
state.optionalCounter = Counter.State()
43+
state.counter = Counter.State()
5344
return .none
5445

55-
case .optionalCounter:
56-
return .none
5746
}
5847
}
59-
.ifLet(\.optionalCounter, action: /Action.optionalCounter) {
48+
.ifLet(\.$counter, action: /Action.counter) {
6049
Counter()
6150
}
6251
}
@@ -73,7 +62,7 @@ struct LoadThenPresentView: View {
7362
Section {
7463
AboutView(readMe: readMe)
7564
}
76-
Button(action: { viewStore.send(.setSheet(isPresented: true)) }) {
65+
Button(action: { viewStore.send(.counterButtonTapped) }) {
7766
HStack {
7867
Text("Load optional counter")
7968
if viewStore.isActivityIndicatorVisible {
@@ -84,22 +73,10 @@ struct LoadThenPresentView: View {
8473
}
8574
}
8675
.sheet(
87-
isPresented: viewStore.binding(
88-
get: \.isSheetPresented,
89-
send: LoadThenPresent.Action.setSheet(isPresented:)
90-
)
91-
) {
92-
IfLetStore(
93-
self.store.scope(
94-
state: \.optionalCounter,
95-
action: LoadThenPresent.Action.optionalCounter
96-
)
97-
) {
98-
CounterView(store: $0)
99-
}
100-
}
76+
store: store.scope(state: \.$counter, action: LoadThenPresent.Action.counter),
77+
content: CounterView.init(store:)
78+
)
10179
.navigationTitle("Load and present")
102-
.onDisappear { viewStore.send(.onDisappear) }
10380
}
10481
}
10582
}

0 commit comments

Comments
 (0)