Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct LoadThenNavigateListState: Equatable {

enum LoadThenNavigateListAction: Equatable {
case counter(CounterAction)
case onDisappear
case setNavigation(selection: UUID?)
case setNavigationSelectionDelayCompleted(UUID)
}
Expand Down Expand Up @@ -57,6 +58,9 @@ let loadThenNavigateListReducer =
case .counter:
return .none

case .onDisappear:
return .cancel(id: CancelId())

case let .setNavigation(selection: .some(navigatedId)):
for row in state.rows {
state.rows[id: row.id]?.isActivityIndicatorVisible = row.id == navigatedId
Expand Down Expand Up @@ -119,6 +123,7 @@ struct LoadThenNavigateListView: View {
}
}
.navigationBarTitle("Load then navigate")
.onDisappear { viewStore.send(.onDisappear) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct LoadThenNavigateState: Equatable {
}

enum LoadThenNavigateAction: Equatable {
case onDisappear
case optionalCounter(CounterAction)
case setNavigation(isActive: Bool)
case setNavigationIsActiveDelayCompleted
Expand All @@ -38,12 +39,20 @@ let loadThenNavigateReducer =
with: Reducer<
LoadThenNavigateState, LoadThenNavigateAction, LoadThenNavigateEnvironment
> { state, action, environment in

struct CancelId: Hashable {}

switch action {

case .onDisappear:
return .cancel(id: CancelId())

case .setNavigation(isActive: true):
state.isActivityIndicatorVisible = true
return Effect(value: .setNavigationIsActiveDelayCompleted)
.delay(for: 1, scheduler: environment.mainQueue)
.eraseToEffect()
.cancellable(id: CancelId())

case .setNavigation(isActive: false):
state.optionalCounter = nil
Expand Down Expand Up @@ -90,6 +99,7 @@ struct LoadThenNavigateView: View {
}
}
}
.onDisappear { viewStore.send(.onDisappear) }
}
.navigationBarTitle("Load then navigate")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,19 @@ let navigateAndLoadReducer =
with: Reducer<
NavigateAndLoadState, NavigateAndLoadAction, NavigateAndLoadEnvironment
> { state, action, environment in
struct CancelId: Hashable {}
switch action {
case .setNavigation(isActive: true):
state.isNavigationActive = true
return Effect(value: .setNavigationIsActiveDelayCompleted)
.delay(for: 1, scheduler: environment.mainQueue)
.eraseToEffect()
.cancellable(id: CancelId())

case .setNavigation(isActive: false):
state.isNavigationActive = false
state.optionalCounter = nil
return .none
return .cancel(id: CancelId())

case .setNavigationIsActiveDelayCompleted:
state.optionalCounter = CounterState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct LoadThenPresentState: Equatable {
}

enum LoadThenPresentAction {
case onDisappear
case optionalCounter(CounterAction)
case setSheet(isPresented: Bool)
case setSheetIsPresentedDelayCompleted
Expand All @@ -38,12 +39,20 @@ let loadThenPresentReducer =
with: Reducer<
LoadThenPresentState, LoadThenPresentAction, LoadThenPresentEnvironment
> { state, action, environment in

struct CancelId: Hashable {}

switch action {

case .onDisappear:
return .cancel(id: CancelId())

case .setSheet(isPresented: true):
state.isActivityIndicatorVisible = true
return Effect(value: .setSheetIsPresentedDelayCompleted)
.delay(for: 1, scheduler: environment.mainQueue)
.eraseToEffect()
.cancellable(id: CancelId())

case .setSheet(isPresented: false):
state.optionalCounter = nil
Expand Down Expand Up @@ -93,6 +102,7 @@ struct LoadThenPresentView: View {
)
}
.navigationBarTitle("Load and present")
.onDisappear { viewStore.send(.onDisappear) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ let presentAndLoadReducer =
with: Reducer<
PresentAndLoadState, PresentAndLoadAction, PresentAndLoadEnvironment
> { state, action, environment in
struct CancelId: Hashable {}
switch action {
case .setSheet(isPresented: true):
state.isSheetPresented = true
return Effect(value: .setSheetIsPresentedDelayCompleted)
.delay(for: 1, scheduler: environment.mainQueue)
.eraseToEffect()
.cancellable(id: CancelId())

case .setSheet(isPresented: false):
state.isSheetPresented = false
state.optionalCounter = nil
return .none
return .cancel(id: CancelId())

case .setSheetIsPresentedDelayCompleted:
state.optionalCounter = CounterState()
Expand Down
10 changes: 10 additions & 0 deletions Examples/CaseStudies/UIKitCaseStudies/LoadThenNavigate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct LazyNavigationState: Equatable {
}

enum LazyNavigationAction: Equatable {
case onDisappear
case optionalCounter(CounterAction)
case setNavigation(isActive: Bool)
case setNavigationIsActiveDelayCompleted
Expand All @@ -30,12 +31,16 @@ let lazyNavigationReducer =
with: Reducer<
LazyNavigationState, LazyNavigationAction, LazyNavigationEnvironment
> { state, action, environment in
struct CancelId: Hashable {}
switch action {
case .onDisappear:
return .cancel(id: CancelId())
case .setNavigation(isActive: true):
state.isActivityIndicatorHidden = false
return Effect(value: .setNavigationIsActiveDelayCompleted)
.delay(for: 1, scheduler: environment.mainQueue)
.eraseToEffect()
.cancellable(id: CancelId())
case .setNavigation(isActive: false):
state.optionalCounter = nil
return .none
Expand Down Expand Up @@ -120,6 +125,11 @@ class LazyNavigationViewController: UIViewController {
@objc private func loadOptionalCounterTapped() {
self.viewStore.send(.setNavigation(isActive: true))
}

override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
self.viewStore.send(.onDisappear)
}
}

struct LazyNavigationViewController_Previews: PreviewProvider {
Expand Down
6 changes: 5 additions & 1 deletion Examples/CaseStudies/UIKitCaseStudies/NavigateAndLoad.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ let eagerNavigationReducer =
with: Reducer<
EagerNavigationState, EagerNavigationAction, EagerNavigationEnvironment
> { state, action, environment in

struct CancelId: Hashable {}

switch action {
case .setNavigation(isActive: true):
state.isNavigationActive = true
return Effect(value: .setNavigationIsActiveDelayCompleted)
.delay(for: 1, scheduler: environment.mainQueue)
.eraseToEffect()
.cancellable(id: CancelId())
case .setNavigation(isActive: false):
state.isNavigationActive = false
state.optionalCounter = nil
return .none
return .cancel(id: CancelId())
case .setNavigationIsActiveDelayCompleted:
state.optionalCounter = CounterState()
return .none
Expand Down