3

I use bottom menu and disable flyout. For IOS I needed to add swipe gesture to shell. I used custom render.

How to add swipe animation? On Android for tabbed page it works out of box. I need something similar for Xamarin Shell tabbar menu. I thought Xamarin Forms is pretty easy to use without any problems. It’s basic thing it should be implemented

[assembly: ExportRenderer(typeof(AppShell), typeof(CustomShellRenderer))]
namespace ShellDemo.iOS
{
    public class CustomShellRenderer : ShellRenderer
    {
        protected override IShellTabBarAppearanceTracker CreateTabBarAppearanceTracker()
        {
            return new CustomTabbarAppearance();
        }
    }

    public class CustomTabbarAppearance : IShellTabBarAppearanceTracker
    {
        public void Dispose()
        {

        }

        public void ResetAppearance(UITabBarController controller)
        {

        }

        public void SetAppearance(UITabBarController controller, ShellAppearance appearance)
        {
            UISwipeGestureRecognizer swipeRight = new UISwipeGestureRecognizer((gesture) =>
            {
                if (controller.SelectedIndex > 0)
                {
                    controller.SelectedIndex--;
                }
            });
            swipeRight.Direction = UISwipeGestureRecognizerDirection.Right;
            controller.View.AddGestureRecognizer(swipeRight);

            UISwipeGestureRecognizer swipeLeft = new UISwipeGestureRecognizer((gesture) =>
            {
                if (controller.SelectedIndex < controller.ViewControllers.Count() - 1)
                {
                    controller.SelectedIndex++;
                }
            });
            swipeLeft.Direction = UISwipeGestureRecognizerDirection.Left;
            controller.View.AddGestureRecognizer(swipeLeft);
        }

        public void UpdateLayout(UITabBarController controller)
        {

        }
    }
}```
![enter image description here](https://i.stack.imgur.com/dXNMJ.gif)
Cfun
  • 8,442
  • 4
  • 30
  • 62

0 Answers0