Fix back-press crash in single-category nav graphs#431
Open
Rimusolamus wants to merge 1 commit into
Open
Conversation
…Screen from NavBackStackEntry instead of querying the unattached NavController inside NavHost.builder (fixes airbnb#420).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #420.
The
onRootScreencheck atShowkaseBrowserApp.kt:459runs insideNavHost(builder = { ... }), which executes once at graph construction time — before the NavController is attached to its graph.currentDestinationis null,startDestinationIdis 0, so the check always returnsfalse. In single-category mode (consumers with only@Preview) that false propagates down to the*GroupsBackHandler, which then tries tonavigate("SHOWKASE_CATEGORIES")— a route that doesn't exist in the single-category graph, hence the crash.Switched to deriving
onRootScreenfrom theNavBackStackEntrythatcomposable(route) { backStackEntry -> ... }already provides per destination. At that scope the graph is attached andbackStackEntry.destination.parent?.startDestinationRouteis the route NavHost was started with. Dropped theonRootScreen: Booleanplumbing param from the 5 private graph builder funcs; screen-level composable signatures are unchanged.Verified on a consumer app with only
@Preview(single-category mode): open browser, drill into a group, press back — no crash, the existingLog.e("BackPressed", "onRootScreen")fires confirming the right branch is taken.