Provide onDispose callback in the LifecycleEffectOnce api
Closed this issue · 3 comments
It would be useful to have an onDispose callback in LifecycleEffectOnce. Also, the API should be similar to DisposableEffect, except it binds to the screen's lifecycle. Something like this:
LifecycleEffectOnce {
val observer = LifecycleEventObserver { _, _->}
lifecycle.addObserver(observer)
onDispose {
lifecycle.removeObserver(observer)
}
}
Currently, I've duplicated the LifecycleEffectStore logic for my use case, but it would be nice to have this feature in the library.
Originally posted by @shpasha in #425 (comment)
It would be great if child components could use it with CompositionLocal too.
This is a nice addition, I will implement it.
@s97712 you have two choses when you want to use a Voyager API that depends on Screen
, you can make your child components extension of Screen or you can use LocalNavigator.currentOrThrow.lastItem
Should be available in the next release bb2f79c