Status Update
Comments
er...@gmail.com <er...@gmail.com> #2
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ComposeDialogNavigationTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colors.background
) {
MainScreen()
}
}
}
}
}
@Composable
fun MainScreen() {
val navController = rememberNavController()
Scaffold(modifier = Modifier.fillMaxSize()) {
NavHost(navController, "greeting") {
composable(route = "greeting") {
GreetingScreen(navController)
}
dialog(route = "dialog") {
DialogScreen()
}
}
}
}
@Composable
fun DialogScreen() {
val navController = rememberNavController()
Surface(modifier = Modifier.fillMaxSize()
) {
NavHost(navController, "profile") {
composable(route = "profile") {
ProfileScreen()
}
composable(route = "about") {
AboutScreen()
}
composable(route = "troubleshooting") {
TroubleshootingScreen()
}
}
}
}
@Composable
fun GreetingScreen(navController: NavHostController) {
Scaffold(topBar = {
TopAppBar(title = {
Text(text = "Dialog Sample")
},
actions = {
Row {
IconButton(onClick = { navController.navigate("dialog") }) {
Icon(Icons.Rounded.Person, contentDescription = "Profile")
}
}
})
}) {
Text(text = "Compose App - Tap the profile button")
}
}
@Composable
fun ProfileScreen() {
Box(modifier = Modifier.fillMaxSize()) {
Text(modifier = Modifier.align(Alignment.Center),
text = "Dialog - Press hardware back button")
}
}
@Composable
fun AboutScreen() {
Text(text = "About")
}
@Composable
fun TroubleshootingScreen() {
Text(text = "Troubleshooting")
}
@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
ComposeDialogNavigationTheme {
MainScreen()
}
}
buildscript {
ext {
compose_version = '1.1.1'
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
implementation 'androidx.activity:activity-compose:1.4.0'
implementation 'androidx.navigation:navigation-compose:2.4.1'
jb...@google.com <jb...@google.com>
il...@google.com <il...@google.com> #3
So trying this in the latest Navigation
However, that prevention seems to be more that Navigation does not recompose as often, thus avoiding this race condition where the dialog destination is destroyed (which is why the NavBackStackEntry
is DESTROYED
), but the actual Dialog
composable is still on the screen.
This looks like a missed edge case when the fix for popping a dialog destination with navController.popBackStack()
was fixed in Dialog
composable is disposed when dismissing the dialog.
ap...@google.com <ap...@google.com> #4
Branch: androidx-main
commit c2948a752c33d05ca3f10d658458d6eca1a0eb61
Author: Jeremy Woods <jbwoods@google.com>
Date: Tue Apr 12 09:20:23 2022
PopWithTransition on dismiss
DialogNavigator should be using popWithTransition when calling dismiss
on a dialog as well. That way we don't dismiss too early when the dialog
is being destroyed.
RelNote: "Fixed a race condition when using a `ViewModel` within `dialog` destination that would cause an `IllegalStateException` when dismissing the dialog by tapping outside the dialog."
Test: existing tests pass
Bug: 226552301
Change-Id: Id7376c0b8db5be869d8ff53185e15b0603bf8582
M navigation/navigation-compose/src/androidTest/java/androidx/navigation/compose/DialogNavigatorTest.kt
M navigation/navigation-compose/src/main/java/androidx/navigation/compose/DialogNavigator.kt
jb...@google.com <jb...@google.com> #5
This has been fixed internally and will be available in the Navigation 2.5.0-beta01
and 2.4.3
releases.
Description
Component used: Navigation Version used: 2.4.1 Devices/Android versions reproduced on: Pixel 3XL and Pixel C emulator
Repro steps: Use the attached sample