Skip to content

Fix back-press crash in single-category nav graphs#431

Open
Rimusolamus wants to merge 1 commit into
airbnb:masterfrom
Rimusolamus:fix/back-handler-nav-issue-420
Open

Fix back-press crash in single-category nav graphs#431
Rimusolamus wants to merge 1 commit into
airbnb:masterfrom
Rimusolamus:fix/back-handler-nav-issue-420

Conversation

@Rimusolamus
Copy link
Copy Markdown

Fixes #420.

The onRootScreen check at ShowkaseBrowserApp.kt:459 runs inside NavHost(builder = { ... }), which executes once at graph construction time — before the NavController is attached to its graph. currentDestination is null, startDestinationId is 0, so the check always returns false. In single-category mode (consumers with only @Preview) that false propagates down to the *Groups BackHandler, which then tries to navigate("SHOWKASE_CATEGORIES") — a route that doesn't exist in the single-category graph, hence the crash.

Switched to deriving onRootScreen from the NavBackStackEntry that composable(route) { backStackEntry -> ... } already provides per destination. At that scope the graph is attached and backStackEntry.destination.parent?.startDestinationRoute is the route NavHost was started with. Dropped the onRootScreen: Boolean plumbing 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 existing Log.e("BackPressed", "onRootScreen") fires confirming the right branch is taken.

…Screen from NavBackStackEntry instead of querying the unattached NavController inside NavHost.builder (fixes airbnb#420).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Back handler navigation crash

1 participant