xamarin-forms-page-transitions
xamarin-forms-page-transitions copied to clipboard
Build Errors on Xamrin 4.6.0.726
Does not build when updated to lastest Xamrin
Do need working version with shell?
For shell i took some principle from Xamarin.Plugin.SharedTransitions I needed just page transitions so didnt wanted to take all packege. Basically you dont need to do anothing in forms. You need to create ShellRenrerer and just pass animation like in this library
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using Android.Content;
using Android.OS;
using Xamarin.Forms;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Platform.Android;
using View = Android.Views.View;
#if __ANDROID_29__
using AndroidX.Fragment.App;
using FragmentManager = AndroidX.Fragment.App.FragmentManager;
using SupportTransitions = AndroidX.Transitions;
#else
using Android.Support.V4.App;
using FragmentManager = Android.Support.V4.App.FragmentManager;
using SupportTransitions = Android.Support.Transitions;
#endif
[assembly: ExportRenderer(typeof(AppShell), typeof(TransitionNavigationPageRenderer))]
namespace CatCatty.Droid.Services.Renderers
{
/// <summary>
/// https://github.com/jsuarezruiz/xamarin-forms-page-transitions
/// Took core for shell from
/// https://github.com/GiampaoloGabba/Xamarin.Plugin.SharedTransitions
/// </summary>
public class TransitionNavigationPageRenderer : ShellRenderer
{
public TransitionNavigationPageRenderer(Context context) : base(context)
{
}
protected override IShellToolbarAppearanceTracker CreateToolbarAppearanceTracker()
{
return new MyShellToolbarAppearanceTracker(this);
}
protected override IShellItemRenderer CreateShellItemRenderer(ShellItem shellItem)
{
return new SharedTransitionShellItemRenderer(this);
}
}
public class MyShellToolbarAppearanceTracker : ShellToolbarAppearanceTracker
{
public MyShellToolbarAppearanceTracker(IShellContext context) : base(context)
{
}
}
public class SharedTransitionShellItemRenderer : ShellItemRenderer
{
public SharedTransitionShellItemRenderer(IShellContext shellContext) : base(shellContext)
{
}
protected override void SetupAnimation(ShellNavigationSource navSource, FragmentTransaction t, Page page)
{
if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
{
base.SetupAnimation(navSource, t, page);
}
else
{
var isPush = navSource == ShellNavigationSource.Push;
if (isPush)
{
t.SetCustomAnimations(Resource.Animation.enter_left, Resource.Animation.exit_right,
Resource.Animation.enter_right, Resource.Animation.exit_left);
}
else
{
t.SetCustomAnimations(Resource.Animation.enter_right, Resource.Animation.exit_left,
Resource.Animation.enter_left, Resource.Animation.exit_right);
}
}
}
protected override void OnNavigationRequested(object sender, NavigationRequestedEventArgs e)
{
base.OnNavigationRequested(sender, e);
}
}
}
For shell i took some principle from Xamarin.Plugin.SharedTransitions I needed just page transitions so didnt wanted to take all packege. Basically you dont need to do anothing in forms. You need to create ShellRenrerer and just pass animation like in this library
using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using Android.Content; using Android.OS; using Xamarin.Forms; using Xamarin.Forms.Internals; using Xamarin.Forms.Platform.Android; using View = Android.Views.View; #if __ANDROID_29__ using AndroidX.Fragment.App; using FragmentManager = AndroidX.Fragment.App.FragmentManager; using SupportTransitions = AndroidX.Transitions; #else using Android.Support.V4.App; using FragmentManager = Android.Support.V4.App.FragmentManager; using SupportTransitions = Android.Support.Transitions; #endif [assembly: ExportRenderer(typeof(AppShell), typeof(TransitionNavigationPageRenderer))] namespace CatCatty.Droid.Services.Renderers { /// <summary> /// https://github.com/jsuarezruiz/xamarin-forms-page-transitions /// Took core for shell from /// https://github.com/GiampaoloGabba/Xamarin.Plugin.SharedTransitions /// </summary> public class TransitionNavigationPageRenderer : ShellRenderer { public TransitionNavigationPageRenderer(Context context) : base(context) { } protected override IShellToolbarAppearanceTracker CreateToolbarAppearanceTracker() { return new MyShellToolbarAppearanceTracker(this); } protected override IShellItemRenderer CreateShellItemRenderer(ShellItem shellItem) { return new SharedTransitionShellItemRenderer(this); } } public class MyShellToolbarAppearanceTracker : ShellToolbarAppearanceTracker { public MyShellToolbarAppearanceTracker(IShellContext context) : base(context) { } } public class SharedTransitionShellItemRenderer : ShellItemRenderer { public SharedTransitionShellItemRenderer(IShellContext shellContext) : base(shellContext) { } protected override void SetupAnimation(ShellNavigationSource navSource, FragmentTransaction t, Page page) { if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop) { base.SetupAnimation(navSource, t, page); } else { var isPush = navSource == ShellNavigationSource.Push; if (isPush) { t.SetCustomAnimations(Resource.Animation.enter_left, Resource.Animation.exit_right, Resource.Animation.enter_right, Resource.Animation.exit_left); } else { t.SetCustomAnimations(Resource.Animation.enter_right, Resource.Animation.exit_left, Resource.Animation.enter_left, Resource.Animation.exit_right); } } } protected override void OnNavigationRequested(object sender, NavigationRequestedEventArgs e) { base.OnNavigationRequested(sender, e); } } }
can you post your source code of a project with this example @valentasm1
Sorry no, but here is updated version for shell renderer which i think should help. If not let my know where you stuck
public enum PagePushDirection
{
FromRightToLeft,
FromBottomToTop
}
public abstract class ApplicationContentPage : ContentPage, IView
{
public virtual PagePushDirection PagePushDirection { get; } = PagePushDirection.FromRightToLeft;
}
And shell renderer
public class AndroidAppShellRenderer : ShellRenderer
{
public AndroidAppShellRenderer(Context context) : base(context)
{
}
protected override IShellToolbarAppearanceTracker CreateToolbarAppearanceTracker()
{
return new MyShellToolbarAppearanceTracker(this);
}
protected override IShellItemRenderer CreateShellItemRenderer(ShellItem shellItem)
{
return new SharedTransitionShellItemRenderer(this);
}
}
public class MyShellToolbarAppearanceTracker : ShellToolbarAppearanceTracker
{
public MyShellToolbarAppearanceTracker(IShellContext context) : base(context)
{
}
public override void ResetAppearance(Toolbar toolbar, IShellToolbarTracker toolbarTracker)
{
if (toolbarTracker.CanNavigateBack)
{
toolbar.SetNavigationIcon(Resource.Drawable.ic_back);
}
}
public override void SetAppearance(Toolbar toolbar, IShellToolbarTracker toolbarTracker, ShellAppearance appearance)
{
toolbar.SetElevation(0);
toolbar.SetPadding(0, 0, 0, 0);
toolbar.SetContentInsetsAbsolute(0, 0);
if (toolbarTracker.CanNavigateBack)
{
toolbar.NavigationIcon = null;
}
}
}
public class SharedTransitionShellItemRenderer : ShellItemRenderer
{
public SharedTransitionShellItemRenderer(IShellContext shellContext) : base(shellContext)
{
}
protected override void SetupAnimation(ShellNavigationSource navSource, FragmentTransaction t, Page page)
{
if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
{
base.SetupAnimation(navSource, t, page);
}
else
{
var isPush = navSource == ShellNavigationSource.Push;
if (page is ApplicationContentPage applicationContentPage)
{
var pushDirection = applicationContentPage.PagePushDirection;
if (pushDirection == PagePushDirection.FromRightToLeft)
{
if (isPush)
{
t.SetCustomAnimations(Resource.Animation.enter_right, Resource.Animation.exit_left, Resource.Animation.enter_left, Resource.Animation.exit_right);
}
else
{
t.SetCustomAnimations(Resource.Animation.enter_left, Resource.Animation.exit_right, Resource.Animation.enter_right, Resource.Animation.exit_left);
}
}
if (pushDirection == PagePushDirection.FromBottomToTop)
{
if (isPush)
{
t.SetCustomAnimations(Resource.Animation.enter_bottom, Resource.Animation.exit_top, Resource.Animation.enter_top, Resource.Animation.exit_bottom);
}
else
{
t.SetCustomAnimations(Resource.Animation.enter_top, Resource.Animation.exit_bottom, Resource.Animation.enter_bottom, Resource.Animation.exit_top);
}
}
}
else
{
if (isPush)
{
t.SetCustomAnimations(Resource.Animation.enter_right, Resource.Animation.exit_left, Resource.Animation.enter_left, Resource.Animation.exit_right);
}
else
{
t.SetCustomAnimations(Resource.Animation.enter_left, Resource.Animation.exit_right, Resource.Animation.enter_right, Resource.Animation.exit_left);
}
}
}
}
}
@valentasm1 so all I do is create the app shell render? How do I call a specific transition from page to page? Is it no different then the way we you do it without shell? I’m trying to use the scale transition you wouldn’t happen to have an iOS version too? Thank you for any help.
I dont have iOs version. Just describe animation in ApplicationContentPage in PagePushDirection as example and inherit from it in your content page. If you looking for more type animation you could modify existing animations https://github.com/jsuarezruiz/xamarin-forms-page-transitions/tree/master/src/TransitionNavigationPage/TransitionNavigationPage/TransitionNavigationPage.Android/Resources/anim