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.
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 regularEventEffect
, theonCosume
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 regularEventEffect
is the order of the functions.Contrary to the
EventEffect
, here theonConsume()
is triggered first and then theaction()
block is called. This way you can overcome the timing problem.