From 1f01046bdb489d3660fb6848f58e5fd974ad0682 Mon Sep 17 00:00:00 2001 From: ikarenkov Date: Tue, 23 Jul 2024 15:30:40 +0200 Subject: [PATCH] Fixed order of start events, now parent start and resume happens before child. Also, it fixed back handling after activity recreation. --- TestInstructions.md | 5 ++++- gradle/libs.versions.toml | 2 +- .../modo/android/ModoScreenAndroidAdapter.kt | 7 ++++-- .../github/terrakok/modo/stack/StackScreen.kt | 22 ++++++++++++------- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/TestInstructions.md b/TestInstructions.md index 22ae5c8..13a50f5 100644 --- a/TestInstructions.md +++ b/TestInstructions.md @@ -11,4 +11,7 @@ certain cases: * Check correctness, with animation interruption. F.e. 2 fast back clicks * Check pause, stop. dispose - 2 fast back or replace * Check create, start, resume - 2 fast forward or replace -* Movable content test \ No newline at end of file +* Movable content test +* Check lifecycle order in nested screens when activity/fragment recreated, by rotating the screen. Following rules should be applied: + * Parent screens events ON_CREATE, ON_START, ON_RESUME should be called before child screens events + * Parent screens events ON_PAUSE, ON_STOP, ON_DESTROY should be called after child screens events \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index bbd2622..5644681 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] leakcanaryAndroid = "2.14" -modo = "0.10.0-alpha1" +modo = "0.10.0-alpha2" androidGradlePlugin = "8.4.0" detektComposeVersion = "0.3.20" detektVersion = "1.23.6" diff --git a/modo-compose/src/main/java/com/github/terrakok/modo/android/ModoScreenAndroidAdapter.kt b/modo-compose/src/main/java/com/github/terrakok/modo/android/ModoScreenAndroidAdapter.kt index d92f3d7..4168fc8 100644 --- a/modo-compose/src/main/java/com/github/terrakok/modo/android/ModoScreenAndroidAdapter.kt +++ b/modo-compose/src/main/java/com/github/terrakok/modo/android/ModoScreenAndroidAdapter.kt @@ -219,6 +219,11 @@ class ModoScreenAndroidAdapter private constructor( onCreate(savedState) // do this in the UI thread to force it to be called before anything else } + DisposableEffect(this) { + emitOnStartEvents() + onDispose { } + } + content() DisposableEffect(this) { @@ -246,8 +251,6 @@ class ModoScreenAndroidAdapter private constructor( } } - emitOnStartEvents() - onDispose { // Log.d("LifecycleDebug", "ModoScreenAndroidAdapter registerParentLifecycleListener onDispose ${screen.screenKey}") unregisterLifecycle() diff --git a/modo-compose/src/main/java/com/github/terrakok/modo/stack/StackScreen.kt b/modo-compose/src/main/java/com/github/terrakok/modo/stack/StackScreen.kt index 4f80111..e14192e 100644 --- a/modo-compose/src/main/java/com/github/terrakok/modo/stack/StackScreen.kt +++ b/modo-compose/src/main/java/com/github/terrakok/modo/stack/StackScreen.kt @@ -72,6 +72,8 @@ abstract class StackScreen( dialogModifier: Modifier = Modifier, content: RendererContent = defaultRendererContent ) { + StackBackHandler() + val screensToRender: ScreensToRender by rememberScreensToRender() screensToRender.screen?.let { screen -> Content(screen, modifier, content) @@ -131,6 +133,18 @@ abstract class StackScreen( } } + @Composable + private fun StackBackHandler() { + val isBackHandlerEnabled by remember { + derivedStateOf { + defaultBackHandler && navigationState.getChildScreens().size > 1 + } + } + BackHandler(enabled = isBackHandlerEnabled) { + back() + } + } + @Composable @OptIn(ExperimentalModoApi::class) private fun StackScreen.RenderDialog( @@ -174,14 +188,6 @@ abstract class StackScreen( modifier: Modifier = Modifier, content: RendererContent = defaultRendererContent ) { - val isBackHandlerEnabled by remember { - derivedStateOf { - defaultBackHandler && navigationState.getChildScreens().size > 1 - } - } - BackHandler(enabled = isBackHandlerEnabled) { - back() - } super.InternalContent(screen, modifier, content) }