PopToRoot while retap active tab in TabbedPage in MAUI Android

250 views Asked by At

How can I setup a PopToRoot action while tapping active tab on Android devices. On iOS it works fine but on android nothing happened if i clicked active tab again.

In Xamarin using shell i use a code :

[assembly: ExportRenderer(typeof(Shell), typeof(JknShellRenderer))]
namespace MyApp.Droid.Renderers
{
    /// <summary>
    /// The JknShellRenderer is necessary in order to replace the ShellItemRenderer with your own.
    /// </summary>
    class JknShellRenderer : ShellRenderer
    {
        public JknShellRenderer(Context context) : base(context)
        {
        }

        protected override IShellItemRenderer CreateShellItemRenderer(ShellItem shellItem)
        {
            return new JknShellItemRenderer(this);
        }
    }

    /// <summary>
    /// This renderer is necessary to allow us to handle the TabReselected (current tab clicked) event as it is not implemented by default on Android
    /// and the only way is to go through a renderer. 
    /// </summary>
    public class JknShellItemRenderer : ShellItemRenderer
    {
        public JknShellItemRenderer(IShellContext shellContext) : base(shellContext)
        {
        }

        /// <summary>
        /// Pops to root when the selected tab is pressed.
        /// </summary>
        /// <param name="shellSection"></param>
        protected override void OnTabReselected(ShellSection shellSection)
        {
            Xamarin.Forms.Device.BeginInvokeOnMainThread(async () =>
            {
                await shellSection?.Navigation.PopToRootAsync();
            });
        }
    }
}

but on MAUI I'm not using a Shell...

What the way to make it in MAUI TabbedPage ?

0

There are 0 answers