GiampaoloGabba / Xamarin.Plugin.SharedTransitions

Shared Element Transitions between pages in Xamarin.Forms (IOS/Android)
MIT License
414 stars 59 forks source link

[Suggestion] CurrentTransition property #44

Closed Inrego closed 4 years ago

Inrego commented 4 years ago

I finally got around to checking out the update you made on transition events. It's looking great! I had an idea for a simple addition: A property on SharedTransitionNavigationPage where you put the current transition event args. So on transition start, set it. On transition cancel or finished, set it to null.

Basically, I would use it to check if it's null to see if there's a transition in progress right now. So for my need, it could as well be a boolean, but hey, someone else might need the extra info.

It's quite easy to just subclass SharedTransitionNavigationPage and implement it myself. And that's also how I will handle it right now. Just thought it could be a useful addition. I can make a PR if you want.

Inrego commented 4 years ago

This is basically what I mean:

public class TransitionNavigationPage : SharedTransitionNavigationPage
{
    public SharedTransitionEventArgs CurrentTransition { get; private set; }
    public override void OnTransitionStarted(SharedTransitionEventArgs args)
    {
        CurrentTransition = args;
        base.OnTransitionStarted(args);
    }

    public override void OnTransitionCancelled(SharedTransitionEventArgs args)
    {
        base.OnTransitionCancelled(args);
        CurrentTransition = null;
    }

    public override void OnTransitionEnded(SharedTransitionEventArgs args)
    {
        base.OnTransitionEnded(args);
        CurrentTransition = null;
    }
}
GiampaoloGabba commented 4 years ago

the next version implements : public ObservableProperty<SharedTransitionEventArgs> CurrentTransition { get; }

in SharedTransitionNavigationPage and SharedTransitionShell

Basically you can read the property when you want withCurrentTransition.Get() or you can subscribe to changes like this:

CurrentTransition.Changed += data =>
{
    Debug.WriteLine($"CurrentTransition Changed: {data?.NavOperation} {data?.PageFrom} {data?.PageTo}");
};

Just remember that the property is null when there is not active transition