Screen Effects
Here’s the improved version of your documentation text:
Modo provides a set of side effects that are similar to the LaunchedEffect and DisposableEffect from Jetpack Compose, but they are tied to the screen lifecycle:
LaunchedScreenEffect- Executes the givenblock: suspend CoroutineScope.() -> Unitwhen the screen is created and cancels the coroutine scope when the screen is removed.DisposableScreenEffect- Executes the giveneffect: DisposableEffectScope.() -> DisposableEffectResultwhen the screen is created and calls theDisposableEffectResult.dispose()of the returnedDisposableEffectResultwhen the screen is removed.OnScreenRemoved- Executes when the screen is removed from the navigation graph. It is similar to theDisposableScreenEffect.LifecycleScreenEffect- A shortcut for subscribing to a screen's lifecycle, usingDisposableScreenEffectunder the hood.
You can use these effects when you need to perform an action when the screen is created and then dispose of it when the screen is removed. For example, you can use it to create and close a DI scope.
Effects are called once per
Screeninstance, when the given function enters the composition and this block hasn't been called for thisScreeninstance.The effect is disposed of when the
Screenis removed from the navigation graph.
Examples of Usage
Analytics
You can use DisposableScreenEffect to track screen creation and removal events:
DI Scope Integration
You can use OnScreenRemoved with remember to create and close a DI scope. The scope of a Screen can be identified by screenKey. Here is a sample of how you can use it with Toothpick: