Example #1
0
        void DisposeChildRenderers()
        {
            IVisualElementRenderer childRenderer = APlatform.GetRenderer(_childView);

            childRenderer?.Dispose();
            _childView?.ClearValue(APlatform.RendererProperty);
        }
Example #2
0
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            if (_childView == null)
            {
                return;
            }

            Rectangle bounds = GetBounds(_isFlyout, l, t, r, b);

            if (_isFlyout)
            {
                FlyoutPageController.FlyoutBounds = bounds;
            }
            else
            {
                FlyoutPageController.DetailBounds = bounds;
            }

            IVisualElementRenderer renderer = APlatform.GetRenderer(_childView);

            renderer?.UpdateLayout();

            // If we're using a PageContainer (i.e., we've wrapped our contents in a Fragment),
            // Make sure that it gets laid out
            if (_pageContainer != null)
            {
                if (_isFlyout)
                {
                    var controller = (IFlyoutPageController)_parent;
                    var width      = (int)Context.ToPixels(controller.FlyoutBounds.Width);
                    // When the base class computes the size of the Flyout container, it starts at the top of the
                    // screen and adds padding (_parent.FlyoutBounds.Top) to leave room for the status bar
                    // When this container is laid out, it's already starting from the adjusted y value of the parent,
                    // so we subtract _parent.FlyoutBounds.Top from our starting point (to get 0) and add it to the
                    // bottom (so the flyout page stretches to the bottom of the screen)
                    var height = (int)Context.ToPixels(controller.FlyoutBounds.Height + controller.FlyoutBounds.Top);
                    _pageContainer.Layout(0, 0, width, height);
                }
                else
                {
                    _pageContainer.Layout(l, t, r, b);
                }

                _pageContainer.Child.UpdateLayout();
            }
        }
Example #3
0
        void RegisterToolbar()
        {
            Context  context = Context;
            AToolbar bar     = _toolbar;
            Element  page    = Element.RealParent;

            _flyoutPage = null;
            while (page != null)
            {
                if (page is FlyoutPage)
                {
                    _flyoutPage = page as FlyoutPage;
                    break;
                }
                page = page.RealParent;
            }

            if (_flyoutPage == null)
            {
                if (PageController.InternalChildren.Count > 0)
                {
                    _flyoutPage = PageController.InternalChildren[0] as FlyoutPage;
                }

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

            if (((IFlyoutPageController)_flyoutPage).ShouldShowSplitMode)
            {
                return;
            }

            var renderer = APlatform.GetRenderer(_flyoutPage) as FlyoutPageRenderer;

            if (renderer == null)
            {
                return;
            }

            _drawerLayout = renderer;

            Controls.Platform.AutomationPropertiesProvider.GetDrawerAccessibilityResources(context, _flyoutPage, out int resourceIdOpen, out int resourceIdClose);

            if (_drawerToggle != null)
            {
                _drawerToggle.ToolbarNavigationClickListener = null;
                _drawerToggle.Dispose();
            }

            _drawerToggle = new ActionBarDrawerToggle(context.GetActivity(), _drawerLayout, bar,
                                                      resourceIdOpen == 0 ? global::Android.Resource.String.Ok : resourceIdOpen,
                                                      resourceIdClose == 0 ? global::Android.Resource.String.Ok : resourceIdClose)
            {
                ToolbarNavigationClickListener = new ClickListener(Element)
            };

            if (_drawerListener != null)
            {
                _drawerLayout.RemoveDrawerListener(_drawerListener);
                _drawerListener.Dispose();
            }

            _drawerListener = new DrawerMultiplexedListener {
                Listeners = { _drawerToggle, renderer }
            };
            _drawerLayout.AddDrawerListener(_drawerListener);
        }
Example #4
0
        protected virtual void AddChildView(VisualElement childView)
        {
            _pageContainer = null;

            Page page = childView as NavigationPage ?? (Page)(childView as TabbedPage);

            if (page == null)
            {
                // The thing we're adding is not a NavigationPage or TabbedPage, so we can just use the old AddChildView

                if (_currentFragment != null)
                {
                    if (!_parent.IsAttachedToRoot())
                    {
                        return;
                    }

                    // But first, if the previous occupant of this container was a fragment, we need to remove it properly
                    FragmentTransaction transaction = FragmentManager.BeginTransactionEx();
                    transaction.RemoveEx(_currentFragment);
                    transaction.SetTransitionEx((int)FragmentTransit.None);

                    if (IsAttachedToWindow)
                    {
                        ExecuteTransaction(transaction);
                    }
                    else
                    {
                        _transaction = transaction;
                    }

                    _currentFragment = null;
                }

                IVisualElementRenderer renderer = APlatform.GetRenderer(childView);
                if (renderer == null)
                {
                    APlatform.SetRenderer(childView, renderer = APlatform.CreateRenderer(childView, Context));
                }

                if (renderer.View.Parent != this)
                {
                    if (renderer.View.Parent != null)
                    {
                        renderer.View.RemoveFromParent();
                    }
                    SetDefaultBackgroundColor(renderer);
                    AddView(renderer.View);
                    renderer.UpdateLayout();
                }
            }
            else
            {
                if (!_parent.IsAttachedToRoot())
                {
                    return;
                }

                // The renderers for NavigationPage and TabbedPage both host fragments, so they need to be wrapped in a
                // FragmentContainer in order to get isolated fragment management
                Fragment fragment = FragmentContainer.CreateInstance(page);

                var fc = fragment as FragmentContainer;

                fc?.SetOnCreateCallback(pc =>
                {
                    _pageContainer = pc;
                    UpdateFlowDirection();
                    SetDefaultBackgroundColor(pc.Child);
                });

                FragmentTransaction transaction = FragmentManager.BeginTransactionEx();

                if (_currentFragment != null)
                {
                    transaction.RemoveEx(_currentFragment);
                }

                transaction.AddEx(Id, fragment);
                transaction.SetTransitionEx((int)FragmentTransit.None);

                if (IsAttachedToWindow)
                {
                    ExecuteTransaction(transaction);
                }
                else
                {
                    _transaction = transaction;
                }

                _currentFragment = fragment;
            }
        }