Fixed
Status Update
Comments
jb...@google.com <jb...@google.com> #2
Please upload a minimal sample project that reproduces this issue.
ja...@deepl.com <ja...@deepl.com> #3
I've added a sample project to reproduce the Bug:
All the important code is within the MainScreen
Composable/file.
I've noticed the reason to make the app crash is that I emit data to my ViewModel before closing the Dialog. However this works when using composable()
instead of dialog()
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-main
commit 472706e6b170ec44143382f673c8022b944ae731
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Nov 18 12:25:57 2021
Keep dialog back stack entries until the dialog is disposed
When a Dialog is dismissed the content within is recomposed again before
the dialog is disposed. This causes an issue in Navigation where the
dialog content gets a DESTROYED back stack entry.
To get around this we can pop dialogs with transitions and wait until we
get an onDispose callback to move the back stack entry state.
RelNote: "Fixed an issue where attempting to retrieve a viewModel from
a dialogs `NavBackStackEntry` would fail when the dialog was dismissed."
Test: NavHostTest
Bug: 206465487
Change-Id: I6b96d1ce4bcd703340c1d20968d2416c56b9fe46
M navigation/navigation-compose/src/main/java/androidx/navigation/compose/DialogHost.kt
M navigation/navigation-compose/src/androidTest/java/androidx/navigation/compose/NavHostTest.kt
M navigation/navigation-compose/src/main/java/androidx/navigation/compose/DialogNavigator.kt
https://android-review.googlesource.com/1896853
Branch: androidx-main
commit 472706e6b170ec44143382f673c8022b944ae731
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Nov 18 12:25:57 2021
Keep dialog back stack entries until the dialog is disposed
When a Dialog is dismissed the content within is recomposed again before
the dialog is disposed. This causes an issue in Navigation where the
dialog content gets a DESTROYED back stack entry.
To get around this we can pop dialogs with transitions and wait until we
get an onDispose callback to move the back stack entry state.
RelNote: "Fixed an issue where attempting to retrieve a viewModel from
a dialogs `NavBackStackEntry` would fail when the dialog was dismissed."
Test: NavHostTest
Bug: 206465487
Change-Id: I6b96d1ce4bcd703340c1d20968d2416c56b9fe46
M navigation/navigation-compose/src/main/java/androidx/navigation/compose/DialogHost.kt
M navigation/navigation-compose/src/androidTest/java/androidx/navigation/compose/NavHostTest.kt
M navigation/navigation-compose/src/main/java/androidx/navigation/compose/DialogNavigator.kt
ja...@deepl.com <ja...@deepl.com> #6
Wonderful news - thank you for the fast replies!
Description
Component used: Navigation
Version used: 2.4.0-beta02
Devices/Android versions reproduced on: Every device
I'm using Compose with the navigation components. I inject a ViewModel via Hilt.
I navigate with the
NavGraphBuilder.composable()
extension, which works.When I open my composable within a Dialog via the
NavGraphBuilder.dialog()
extension I run into the following problem:Closing the dialog with the system back button works. When I call
navController.popBackstack()
this exception occurs and the app crashes:I observed that my crashing composable is recomposed after
navController.popBackstack()
, which ultimately leads to the crash. Is there a reason for the additional recompositions?