Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How to wait for transition animation to finish when calling Navigation.PushAsync in Xamarin.forms

$
0
0

We're developing an app using xamarin.forms and using the MVVM pattern. We're using the built in navigation system to push and pop pages. Now we're running into an issue when navigating pages using commands.

Say we have a view with a button that navigates to another page. This navigation is done by binding a viewmodel command to the button. The command has a canExecute check, which checks the "IsBusy" property, to prevent the button from being clicked twice, and initiating two page navigations.

Example code:

view:

<Button Command={Binding NavigateCommand} />

viewmodel (i've left out the notifypropertychanged and ChangeCanExecute calls, which do exist):

Public bool IsBusy {get => _isBusy set => {_isBusy = value;}}
Public ICommand NavigateCommand = New Command(Navigate, () => !IsBusy);

async private Task Navigate()
{
    IsBusy = true;
    await Navigation.PushAsync(new OtherPage());
    IsBusy = false;
}

Now you would say that this works, which is kind of does. However, we've implemented custom transition animations in Android that slides the new page into view from the right, and removes the old one by sliding it out of view to the left. The problem is, that the PushAsync method is awaited, but it completes as soon as the page is loaded, but before the animation to move it into view has completed. So during the transition animation, the command can execute again, and it is still possible to execute the command twice.

TLDR: Is there any way to wait for page transition animations to finish when using PushAsync?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>