Lifecycle
Inside a Screen
, you can call LifecycleEffect
to listen for some events:
onStarted
: called when the screen enters the compositiononDisposed
: called when the screen is disposed
ScreenLifecycleOwner
With ScreenLifecycleProvider
interface you can provide a special ScreenLifecycleOwner
that can react when the Screen leaves the Stack
Extending the Lifecycle lazily
You can access directly the ScreenLifecycleStore
to add a ScreenDisposable
implementation lazily in a lifecycle aware custom API.
If you for example have a custom dependency that should be notified when the Screen is disposed you can use the ScreenLifecycleStore
directly. For example, the Screen Model and ScreenModelStore APIs rely on this API to Store the ScreenModel instance and the Screen owns the ScreenModel instance, when the Screen leaves the Stack, the ScreenModelStore, that implements ScreenDisposable
is notified and can dispose the ScreenModel.
Let's imagine a dependency called MyDependency
that holds and provides a State for a Screen while it is on the Navigator stack and we want to notify MyDependency
when the Screen leaves the Stack.
ScreenDisposable for all Screens
You can also provide a ScreenLifecycleOwner
for all Screen in the stack of a Navigator easily by in the Navigator composable start to listen to lastItem
for registering at ScreenLifecycleStore.
Let's reuse the MyScreenLifecycleOwner
from the example above and provide it to all screens in the navigator.
Last updated