Shell navigation bar scroll behavior

限于喜欢 提交于 2021-01-28 14:11:30

问题


I would like to ask if it is possible to animate the Navigation Bar or TabbedPage (TabLayout) in the Xamarin.Forms Shell when scrolling it either hides or the discovery see gif. I tried it in Xamarin native android there it works after adding layout_scrollFlags.

http://lomza.totem-soft.com/appbarlayout-scroll-behavior-with-layout_scrollflags

http://karthikraj.net/2016/12/24/scrolling-behavior-for-appbars-in-android


回答1:


Not sure if you can achieve this behavior with an android style in XF + Shell, but you can achieve it using a custom renderer by overriding CreateToolbarAppearanceTracker().

    public class MyShellRenderer : ShellRenderer
    {
        public MyShellRenderer(Context context) : base(context)
        {
        }

        protected override IShellToolbarAppearanceTracker CreateToolbarAppearanceTracker()
        {
            base.CreateToolbarAppearanceTracker();
            return new MyShellToolbarAppearanceTracker(this);
        }
    }

MyShellToolbarAppearanceTracker (name it whatever you want)

using LP = Android.Views.ViewGroup.LayoutParams;
...
public class MyShellToolbarAppearanceTracker : ShellToolbarAppearanceTracker
{
        public MyShellToolbarAppearanceTracker(IShellContext shellContext) : base(shellContext)
        {
        }

        public override void SetAppearance(AndroidX.AppCompat.Widget.Toolbar toolbar, IShellToolbarTracker toolbarTracker, ShellAppearance appearance)
        {
            base.SetAppearance(toolbar, toolbarTracker, appearance);
            toolbar.LayoutParameters = new AppBarLayout.LayoutParams(LP.MatchParent, LP.WrapContent)
            {
                ScrollFlags = AppBarLayout.LayoutParams.ScrollFlagScroll |
                AppBarLayout.LayoutParams.ScrollFlagEnterAlways
            };
        }
}

Don't forget to properly decorate it with ExportRenderer as explained in the documentation.


(ignore this section if the below linked bug/issue is closed)

Known Side-Effect

This is a trivial undesired side-effect caused by a Xamarin.Forms Bug 13338



来源:https://stackoverflow.com/questions/65544512/shell-navigation-bar-scroll-behavior

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!