void DisposeChildRenderers()
        {
            IVisualElementRenderer childRenderer = APlatform.GetRenderer(_childView);

            childRenderer?.Dispose();
            _childView?.ClearValue(APlatform.RendererProperty);
        }
        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();
            }
        }
        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;
            }
        }
 public FlyoutPageContainer(FlyoutPage parent, bool isFlyout, Context context) : base(context)
 {
     Id        = APlatform.GenerateViewId();
     _parent   = parent;
     _isFlyout = isFlyout;
 }
Пример #5
0
 public EmbeddedFragment(ViewGroup content, AppCompat.Platform platform)
 {
     _content  = content;
     _platform = platform;
 }