Skip to content

Commit

Permalink
Ensures binding always has latest state
Browse files Browse the repository at this point in the history
Fixes an issue where navigating back after a state change could reset
 the previous screen to its state before pushing.
  • Loading branch information
johnpatrickmorgan committed Sep 27, 2023
1 parent b12ba12 commit c13f998
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Sources/TCACoordinators/TCARouter/TCARouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public struct TCARouter<
let updateRoutes: ([Route<Screen>]) -> CoordinatorAction
let action: (ID, ScreenAction) -> CoordinatorAction
let identifier: (Screen, Int) -> ID

@ObservedObject private var viewStore: ViewStore<CoordinatorState, CoordinatorAction>
@ViewBuilder var screenContent: (Store<Screen, ScreenAction>) -> ScreenContent

func scopedStore(index: Int, screen: Screen) -> Store<Screen, ScreenAction> {
var screen = screen
return store.scope(
Expand All @@ -34,16 +34,16 @@ public struct TCARouter<
}
)
}

public var body: some View {
Router(
viewStore.binding(get: { _ in store.withState(routes) }, send: updateRoutes),
ViewStore(store, observe: { $0 }).binding(get: routes, send: updateRoutes),
buildView: { screen, index in
screenContent(scopedStore(index: index, screen: screen))
}
)
}

public init(
store: Store<CoordinatorState, CoordinatorAction>,
routes: @escaping (CoordinatorState) -> [Route<Screen>],
Expand Down

0 comments on commit c13f998

Please sign in to comment.