Exemple #1
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);
        }
Exemple #2
0
        public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var shellSection = ShellSection;

            if (shellSection == null)
            {
                return(null);
            }

            if (shellSection.CurrentItem == null)
            {
                throw new InvalidOperationException($"Content not found for active {shellSection}. Title: {shellSection.Title}. Route: {shellSection.Route}.");
            }

            var context         = Context;
            var root            = PlatformInterop.CreateShellCoordinatorLayout(context);
            var appbar          = PlatformInterop.CreateShellAppBar(context, Resource.Attribute.appBarLayoutStyle, root);
            int actionBarHeight = context.GetActionBarHeight();

            var shellToolbar = new Toolbar(shellSection);

            ShellToolbarTracker.ApplyToolbarChanges(_shellContext.Shell.Toolbar, shellToolbar);
            _toolbar = (AToolbar)shellToolbar.ToPlatform(_shellContext.Shell.FindMauiContext());
            appbar.AddView(_toolbar);
            _tablayout = PlatformInterop.CreateShellTabLayout(context, appbar, actionBarHeight);

            var pagerContext        = MauiContext.MakeScoped(layoutInflater: inflater, fragmentManager: ChildFragmentManager);
            var adapter             = new ShellFragmentStateAdapter(shellSection, ChildFragmentManager, pagerContext);
            var pageChangedCallback = new ViewPagerPageChanged(this);

            _viewPager = PlatformInterop.CreateShellViewPager(context, root, _tablayout, this, adapter, pageChangedCallback);

            Page currentPage  = null;
            int  currentIndex = -1;
            var  currentItem  = shellSection.CurrentItem;
            var  items        = SectionController.GetItems();

            while (currentIndex < 0 && items.Count > 0 && shellSection.CurrentItem != null)
            {
                currentItem = shellSection.CurrentItem;
                currentPage = ((IShellContentController)shellSection.CurrentItem).GetOrCreateContent();

                // current item hasn't changed
                if (currentItem == shellSection.CurrentItem)
                {
                    currentIndex = items.IndexOf(currentItem);
                }
            }

            _toolbarTracker = _shellContext.CreateTrackerForToolbar(_toolbar);
            _toolbarTracker.SetToolbar(shellToolbar);
            _toolbarTracker.Page = currentPage;

            _viewPager.CurrentItem = currentIndex;

            if (items.Count == 1)
            {
                UpdateTablayoutVisibility();
            }

            _tablayout.LayoutChange += OnTabLayoutChange;

            _tabLayoutAppearanceTracker = _shellContext.CreateTabLayoutAppearanceTracker(ShellSection);
            _toolbarAppearanceTracker   = _shellContext.CreateToolbarAppearanceTracker();

            HookEvents();

            return(_rootView = root);
        }