leonard-palm / compose-state-events

A new way to implement One-Time-UI-Events (former SingleLiveEvent) in a Compose world.
Apache License 2.0
177 stars 13 forks source link

Introduced NavigationEventEffect for prioritised onConsume execution #3

Closed YanneckReiss closed 1 year ago

YanneckReiss commented 1 year ago

While working with the Compose State Events library is a great development experience when it comes to handling one-time events, I stumbled upon a drawback.

When implementing navigation in your Android app and navigating to another screen, triggered by an action block from the regular EventEffect, the onCosume function often has no chance to be executed.

This has the effect that when you navigate back from ScreenB to ScreenA, the event that caused the navigation is not consumed correctly and triggers the navigation to ScreenB again.

My suggestion is the NavigationEventEffect, which is useful in such situations. The only difference to the regular EventEffect is the order of the functions.

Contrary to the EventEffect, here the onConsume() is triggered first and then the action() block is called. This way you can overcome the timing problem.