Skip to content

Commit

Permalink
fix 2 issues with replaceAll (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielittner authored Jun 12, 2024
1 parent 55004e3 commit d0cff6e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public fun rememberHostNavigator(
viewModel = viewModel,
startRoot = startRoot,
destinations = destinations,
startRootOverridesSavedRoot = true,
).also {
val handledDeepLinks = viewModel.globalSavedStateHandle.get<Boolean>(SAVED_STATE_HANDLED_DEEP_LINKS)
if (handledDeepLinks != true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ internal class MultiStack(
val snapshot: State<StackSnapshot>
get() = snapshotState

val startRoot = startStack.rootEntry.route as NavRoot
val startRoot
get() = startStack.rootEntry.route as NavRoot

private fun getBackStack(root: NavRoot): Stack? {
return allStacks.find { it.id == root.destinationId }
Expand Down Expand Up @@ -163,14 +164,14 @@ internal class MultiStack(

@Suppress("DEPRECATION")
fun fromState(
root: NavRoot,
root: NavRoot?,
bundle: Bundle,
createEntry: (BaseRoute) -> StackEntry<*>,
createRestoredEntry: (BaseRoute, StackEntry.Id, SavedStateHandle) -> StackEntry<*>,
): MultiStack {
val inputRoot = bundle.getParcelable<NavRoot>(SAVED_INPUT_ROOT)!!

if (inputRoot != root) {
if (root != null && inputRoot != root) {
return createWith(
root = root,
createEntry = createEntry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public fun createHostNavigator(
viewModel: StackEntryStoreViewModel,
startRoot: NavRoot,
destinations: ImmutableSet<NavDestination>,
startRootOverridesSavedRoot: Boolean = false,
): HostNavigator {
val activityDestinations = destinations.filterIsInstance<ActivityDestination>()
val starter = ActivityStarter(context.applicationContext, activityDestinations)
Expand All @@ -31,7 +32,7 @@ public fun createHostNavigator(
)
} else {
MultiStack.fromState(
root = startRoot,
root = startRoot.takeIf { startRootOverridesSavedRoot },
bundle = navState,
createEntry = factory::create,
createRestoredEntry = factory::create,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,12 @@ internal class MultiStackTest {
fun `replaceAll with start root from start hostNavigator`() {
val stack = underTest()
stack.push(SimpleRoute(1))
assertThat(stack.startRoot).isEqualTo(SimpleRoot(1))

stack.replaceAll(SimpleRoot(2))

assertThat(stack.startRoot).isEqualTo(SimpleRoot(2))

assertThat(stack.snapshot.value.visibleEntries)
.containsExactly(
factory.create(StackEntry.Id("102"), SimpleRoot(2)),
Expand Down

0 comments on commit d0cff6e

Please sign in to comment.