I'm struggling to prevent double click on a button using ReactiveUI with Xamarin Forms. Let's say we have a command like this:
NextCommand = ReactiveCommand.CreateFromTask(async () => await HostScreen.Router.NavigateAndReset.Execute(new NewViewModel()));
It's bound to a button in a normal Xamarin Forms way. Unfortunately, very fast click causes two command calls.
Is it possible to fix it using ReactiveUI?
I updated the question to summarise what I've tried:
var obs = Observable.FromAsync(async () => await HostScreen.Router.NavigateAndReset.Execute(new CitizensIndexViewModel()))
.Throttle(TimeSpan.FromSeconds(2));
LoginCommand = ReactiveCommand.CreateFromObservable(() => obs);
Unfortunately, it didn't help. When you double-click very fast on a button, two executions of a command will take place.
I've also tried to add lock statement or semaphore to 'execute' method but it also failed to work because executions aren't done in parallel. That's also a reason why using CanExecute method won't work.
What can potentially work is an ugly bool flag. The only problem with this solution is that I'd have to reset it on back navigation which is obviously doable but I don't consider it as the best solution.