olshevski / compose-navigation-reimagined

🌈 Type-safe navigation library for Jetpack Compose
https://olshevski.github.io/compose-navigation-reimagined/
MIT License
534 stars 18 forks source link

Feature Request: option to prevent navigating to the same destination #36

Open ghost opened 1 month ago

ghost commented 1 month ago

Suppose you have a simple button, when clicked it calls navController.navigate(destination).

Now, if you double-tap it or press it quickly multiple times, multiple navigate() calls will be invoked.

I'd love to prevent this kind of behavior, an option to prevent navigating to the same destination would be great.

Another option would be to expose some kind of property to let apps know navController is currently performing a navigation, so they could disable screen events during the transition.

olshevski commented 4 weeks ago

@bugger15 I don't think the feature should be included into the core navigation library. It seems quite logical to me that multiple navigate calls execute multiple navigation transitions. Maybe you could eliminate the multiple navigate calls in the first place.

Usually, the problem of multiple or simultaneous clicks are resolved with debounce (basically, a reasonable delay between click handling). This way a button cannot be spammed with clicks.

Alternatively, you could always create a wrapper class around NavController and add your own custom logic for accepting/rejecting navigation actions.

As for some inTransition property - that is a great idea, I was thinking to add it myself. Right now it is possible to detect the transition through Lifecycle of a NavHostEntry. During the transition all entries are paused. This follows the behaviour of the official AndroidX Navigation Component library.

ghost commented 2 weeks ago

You are right, I realized that only once posted this. NavController should not handle this, this would be a possible responsibility for AnimatedNavHost. It would be nice to know when its animating, though. Feel free to close this issue.