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

[BUG-60] added preDispose after state update #62

Merged
merged 2 commits into from
Oct 10, 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
11 changes: 10 additions & 1 deletion TestInstructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ certain cases:
* 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
* Parent screens events ON_PAUSE, ON_STOP, ON_DESTROY should be called after child screens events

## Test cases

### Removing previous screen

1. Use `LifecycleScreenEffect` to subscribe to lifecycle updates in `ButtonsScreenContent` (remove comments from code).
2. Launch app and navigate to "Stack Actions".
3. Click "Remove previous".
4. "LifecycleScreenEffect ON_DESTROY" in logcat for previous screen.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ internal class ComposeRenderer<State : NavigationState>(
}
lastState = this.state
this.state = state
// Handling a case when updating state doesn't cause UI to update. But if some screens was removed, we need to move them to destroy state.
// F.e. removing previous screen causes this case.
onPreDispose()
}

@Suppress("UnusedPrivateProperty", "SpreadOperator")
Expand Down Expand Up @@ -198,7 +201,7 @@ internal class ComposeRenderer<State : NavigationState>(
}

/**
* Called onPreDispose for removed screens
* Called onPreDispose for removed screens, that are not presented in [displayingScreensAfterScreenContent] (not displayed on screen).
* @param clearAll - forces to call onPreDispose on all children screen states that renderer holds (removed and "displayed")
*/
private fun onPreDispose(clearAll: Boolean = false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.lifecycle.compose.LocalLifecycleOwner
import com.github.terrakok.modo.ExperimentalModoApi
import com.github.terrakok.modo.Screen
import com.github.terrakok.modo.ScreenKey
import com.github.terrakok.modo.lifecycle.LifecycleScreenEffect
import com.github.terrakok.modo.sample.SampleAppConfig
import com.github.terrakok.modo.sample.randomBackground
import com.github.terrakok.modo.sample.screens.ButtonsState
Expand Down Expand Up @@ -119,11 +120,11 @@ fun Screen.LogLifecycle() {
lifecycleOwner.lifecycle.removeObserver(observer)
}
}
// LifecycleScreenEffect {
// LifecycleEventObserver { source, event ->
// logcat(tag = "LifecycleDebug") { "$screenKey LifecycleScreenEffect $event" }
// }
// }
LifecycleScreenEffect {
LifecycleEventObserver { source, event ->
logcat(tag = "LifecycleDebug") { "$screenKey LifecycleScreenEffect $event" }
}
}
}

@Composable
Expand Down