예제 #1
0
        void Destroy()
        {
            ((IShellController)_shellContext.Shell).RemoveAppearanceObserver(this);

            if (_shellContent != null)
            {
                ((IShellContentController)_shellContent).RecyclePage(_page);
                _page.Handler = null;
            }

            if (_shellPageContainer != null)
            {
                _shellPageContainer.RemoveAllViews();

                if (_root is ViewGroup vg)
                {
                    vg.RemoveView(_shellPageContainer);
                }

                _shellPageContainer.Dispose();
            }

            _root?.Dispose();
            _toolbarTracker?.Dispose();
            _appearanceTracker?.Dispose();


            _appearanceTracker = null;
            _toolbarTracker    = null;
            _toolbar           = null;
            _root               = null;
            _viewhandler        = null;
            _shellContent       = null;
            _shellPageContainer = null;
        }
예제 #2
0
        public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            if (_shellContent != null)
            {
                _page = ((IShellContentController)_shellContent).GetOrCreateContent();
            }

            _root = inflater.Inflate(Controls.Resource.Layout.shellcontent, null).JavaCast <CoordinatorLayout>();

            var shellContentMauiContext = MauiContext.MakeScoped(layoutInflater: inflater, fragmentManager: ChildFragmentManager);

            Maui.IElement parentElement = (_shellContent as Maui.IElement) ?? _page;
            var           shellToolbar  = new Toolbar(parentElement);

            ShellToolbarTracker.ApplyToolbarChanges(_shellContext.Shell.Toolbar, shellToolbar);
            _toolbar = (AToolbar)shellToolbar.ToPlatform(shellContentMauiContext);

            var appBar = _root.FindViewById <AppBarLayout>(Resource.Id.shellcontent_appbar);

            appBar.AddView(_toolbar);
            _viewhandler = _page.ToHandler(shellContentMauiContext);

            _shellPageContainer = new ShellPageContainer(Context, _viewhandler);

            if (_root is ViewGroup vg)
            {
                vg.AddView(_shellPageContainer);
            }

            _toolbarTracker = _shellContext.CreateTrackerForToolbar(_toolbar);
            _toolbarTracker.SetToolbar(shellToolbar);
            _toolbarTracker.Page = _page;
            // this is probably not the most ideal way to do that
            _toolbarTracker.CanNavigateBack = _shellContent == null;

            _appearanceTracker = _shellContext.CreateToolbarAppearanceTracker();

            ((IShellController)_shellContext.Shell).AddAppearanceObserver(this, _page);

            if (_shellPageContainer.LayoutParameters is CoordinatorLayout.LayoutParams layoutParams)
            {
                layoutParams.Behavior = new AppBarLayout.ScrollingViewBehavior();
            }

            return(_root);
        }