6. Transition events and ITransitionAware - GiampaoloGabba/Xamarin.Plugin.SharedTransitions GitHub Wiki

Starting from version 2.3 you can listen to transition events (or extend a transition container and use overrides) for start, stop and cancel.

Events

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

SharedTransitionEventArgs properties

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)

Overrides

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.

ITransitionAware

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)
    {

    }
}

Note

When implementing ITransitionAware you will only be notified of the transition events that the page participates in

CurrentTransition observable property

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}");
};