Skip to content

Commit

Permalink
Merge pull request #27 from holixfactory/fix-replay-bug
Browse files Browse the repository at this point in the history
Cache the latest screen and use it on scopedStore not to replay initial screen
  • Loading branch information
johnpatrickmorgan committed Jun 27, 2022
2 parents 2461e38 + 48ff3ec commit 02a3349
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
8 changes: 6 additions & 2 deletions Sources/TCACoordinators/TCARouter/TCARouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ public struct TCARouter<

func scopedStore(index: Int, screen: Screen) -> Store<Screen, ScreenAction> {
let id = identifier(screen, index)
var screen = screen
return store.scope(
state: { routes($0)[safe: index]?.screen ?? screen },
action: { action(id, $0) }
state: {
screen = routes($0)[safe: index]?.screen ?? screen
return screen
},
action: { action(id, $0) }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,25 @@ struct MainTabCoordinatorView: View {
let store: Store<MainTabCoordinatorState, MainTabCoordinatorAction>

var body: some View {
WithViewStore(store) { _ in
TabView {
IndexedCoordinatorView(
store: store.scope(
state: \MainTabCoordinatorState.indexed,
action: MainTabCoordinatorAction.indexed
)
).tabItem { Text("Indexed") }
IdentifiedCoordinatorView(
store: store.scope(
state: \MainTabCoordinatorState.identified,
action: MainTabCoordinatorAction.identified
)
).tabItem { Text("Identified") }
AppCoordinatorView(
store: store.scope(
state: \MainTabCoordinatorState.app,
action: MainTabCoordinatorAction.app
)
).tabItem { Text("App") }
}
TabView {
IndexedCoordinatorView(
store: store.scope(
state: \MainTabCoordinatorState.indexed,
action: MainTabCoordinatorAction.indexed
)
).tabItem { Text("Indexed") }
IdentifiedCoordinatorView(
store: store.scope(
state: \MainTabCoordinatorState.identified,
action: MainTabCoordinatorAction.identified
)
).tabItem { Text("Identified") }
AppCoordinatorView(
store: store.scope(
state: \MainTabCoordinatorState.app,
action: MainTabCoordinatorAction.app
)
).tabItem { Text("App") }
}
}
}
Expand Down

0 comments on commit 02a3349

Please sign in to comment.