compose-navigation-reimagined icon indicating copy to clipboard operation
compose-navigation-reimagined copied to clipboard

Feature Request: option to prevent navigating to the same destination

Open ghost opened this issue 1 year ago • 2 comments

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.

ghost avatar May 28 '24 13:05 ghost

@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.

olshevski avatar Jun 05 '24 14:06 olshevski

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.

ghost avatar Jun 17 '24 17:06 ghost