Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Potential Proposal: Animation of MainPage Transition

$
0
0

I wanted to discuss this here before submitting a proposal because its a feature I would really like, page transitions, similar to those on a navigation page. But its far from simple to implement and I don't have a solid plan for an API as yet.

I can animate the transition of a MainPage with the following code changes in the Xamarin Forms source code.

iOS

In FormsAppDelegate.cs change this function

  void UpdateMainPage()
  {
       if (_application.MainPage == null)
            return;

        var platformRenderer = (PlatformRenderer)_window.RootViewController;

        if (platformRenderer != null)
            ((IDisposable)platformRenderer.Platform).Dispose();
        if (_window.RootViewController == null)
            _window.RootViewController = _application.MainPage.CreateViewController();
        else
            UIView.Transition(_window.RootViewController.View, 1, UIViewAnimationOptions.TransitionFlipFromBottom, () => { _window.RootViewController = _application.MainPage.CreateViewController(); }, () => { });

    }

Android
Android proves the hardest because I can only seem to transition in, once the previous page is removed. In Platform.cs I replace the following function:

  void AddChild(Page page, bool layout = false)
  {
       if (Android.Platform.GetRenderer(page) != null)
            return;

        Android.Platform.SetPageContext(page, _context);
        IVisualElementRenderer renderView = Android.Platform.CreateRenderer(page);
        Android.Platform.SetRenderer(page, renderView);

        if (layout)
            LayoutRootPage((FormsAppCompatActivity)_context, page, _renderer.Width, _renderer.Height);

        renderView.ViewGroup.StartAnimation(global::Android.Views.Animations.AnimationUtils.LoadAnimation(_context, global::Android.Resource.Animation.SlideInLeft));

        _renderer.AddView(renderView.ViewGroup);
      }

UWP
In UWP we add in this to the SetCurrent method in Platform.cs, just before the Children.Add line.

    if (_container.ChildrenTransitions == null)
    {
        _container.ChildrenTransitions = new TransitionCollection();
        _container.ChildrenTransitions.Add(new EntranceThemeTransition());
    }

The problem is, what API would be good to change the MainPage with an animation, we would need different platform specific code, but it would need to be called through a PCL, hence it would have to be an abstraction of some kind.

Next if anyone is up for the challenge, that Android page transition code needs a looking at.


Viewing all articles
Browse latest Browse all 91519

Trending Articles



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