Closed TommyVisic closed 9 months ago
Hi @TommyVisic, unfortunately I was not able reproduce the described behaviour. Could you please send an example project where the bug happens? I would be really interested looking into that behaviour.
Setting the onConsumed as a reference or as a lambda definately makes a difference in terms of recomposition. But the library needs to be save to use even with a lambda I think.
Btw: Was the code snippet above just a random example? I think you dont need to trigger this close event via the views state if it is just a direct reaction to a users button click.
Here's a sample that reproduces the double event. It looks like the key is 1) observe a MutableStateFlow and 2) call navController.popBackstack in the StateEvent action.
Yes, this is pretty much a random example. But in our case, we do indeed involve the view model in the close event because we have to do some work before we want to actually close the screen. Basically it's a "save and close" kind of action.
Thanks for your response!
@TommyVisic Thank your for your example project. I was able to reproduce your described behaviour. Looking into it.
Fixed in release 2.2.0
Hi. Thank you for this library! Noticed a possible bug where the action for an EventEffect or NavigationEventEffect is called twice when triggered. This happens when the onConsumed parameter is set with a lambda. I think this is a valid way to use the effects, but I'm not sure. Can you let me know your thoughts? Thanks again
A possible fix for this is to remove the onConsumed parameter from the keys on the LaunchedEffect within NavigationEventEffect and EventEffect.