-
Notifications
You must be signed in to change notification settings - Fork 59
6. Transition events and ITransitionAware
Starting from version 2.3 you can listen to transition events (or extend a transition container and use overrides) for start, stop and cancel.
Both SharedNavigationPage
and SharedTransitionShell
expose these events:
Event | Description |
---|---|
TransitionStarted |
Event invoked when a shared transition starts. SharedTransitionEventArgs are provided |
TransitionEnded |
Event invoked when a shared transition ends. SharedTransitionEventArgs are provided |
TransitionCancelled |
Event invoked when a shared transition is cancelled. SharedTransitionEventArgs are provided |
Bindable property | Description |
---|---|
PageFrom |
Xamarin.Forms Page where the transition started |
PageTo |
Xamarin.Forms Page where the transition ended |
NavOperation |
Enum that indicate the navigation operation (Push or Pop ) |
You can create your custom SharedNavigationPage
or SharedTransitionShell
and override these methods:
Method | Description |
---|---|
OnTransitionStarted |
Invoked when a shared transition starts. SharedTransitionEventArgs are provided |
OnTransitionEnded |
Invoked when a shared transition ends. SharedTransitionEventArgs are provided |
OnTransitionCancelled |
Invoked when a shared transition is cancelled. SharedTransitionEventArgs are provided |
Every overrides comes with a SharedTransitionEventArgs
property.
You can also listen to transition events inside a page! Just implement the ITransitionAware
interface like this:
public partial class ImageFromPage : ContentPage, ITransitionAware
{
public ImageFromPage()
{
InitializeComponent();
}
public void OnTransitionStarted(SharedTransitionEventArgs args)
{
if (args.PageFrom == this && args.NavOperation == NavOperation.Push)
DisplayAlert("Message", "Shared Transition started","ok");
}
public void OnTransitionEnded(SharedTransitionEventArgs args)
{
}
public void OnTransitionCancelled(SharedTransitionEventArgs args)
{
}
}
When implementing ITransitionAware you will only be notified of the transition events that the page participates in
ObservableProperty<SharedTransitionEventArgs> CurrentTransition { get; }
The current transition being executed (null
when there is no transition active).
You can read the current value with: CurrentTransition.Get()
or subscribe to the Changed
event:
CurrentTransition.Changed += data =>
{
Debug.WriteLine($"CurrentTransition Changed: {data?.NavOperation} {data?.PageFrom} {data?.PageTo}");
};