Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed order of start events #58

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion TestInstructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
* 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
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -246,8 +251,6 @@ class ModoScreenAndroidAdapter private constructor(
}
}

emitOnStartEvents()

onDispose {
// Log.d("LifecycleDebug", "ModoScreenAndroidAdapter registerParentLifecycleListener onDispose ${screen.screenKey}")
unregisterLifecycle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ abstract class StackScreen(
dialogModifier: Modifier = Modifier,
content: RendererContent<StackState> = defaultRendererContent
) {
StackBackHandler()

val screensToRender: ScreensToRender by rememberScreensToRender()
screensToRender.screen?.let { screen ->
Content(screen, modifier, content)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -174,14 +188,6 @@ abstract class StackScreen(
modifier: Modifier = Modifier,
content: RendererContent<StackState> = defaultRendererContent
) {
val isBackHandlerEnabled by remember {
derivedStateOf {
defaultBackHandler && navigationState.getChildScreens().size > 1
}
}
BackHandler(enabled = isBackHandlerEnabled) {
back()
}
super.InternalContent(screen, modifier, content)
}

Expand Down