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

Provide onDispose callback in the LifecycleEffectOnce api #481

Closed
ibraheemzulfiqar opened this issue Sep 9, 2024 · 3 comments
Closed

Provide onDispose callback in the LifecycleEffectOnce api #481

ibraheemzulfiqar opened this issue Sep 9, 2024 · 3 comments

Comments

@ibraheemzulfiqar
Copy link

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)

@s97712
Copy link

s97712 commented Sep 10, 2024

It would be great if child components could use it with CompositionLocal too.

@DevSrSouza
Copy link
Collaborator

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

@DevSrSouza
Copy link
Collaborator

Should be available in the next release bb2f79c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants