예제 #1
0
        public override Object InstantiateItem(ViewGroup container, int position)
        {
            ContentPage child = _page.Children.ElementAt(position);

            if (AppCompat.Platform.GetRenderer(child) == null)
            {
                AppCompat.Platform.SetRenderer(child, AppCompat.Platform.CreateRenderer(child, _context));
            }

            IVisualElementRenderer renderer = AppCompat.Platform.GetRenderer(child);

            renderer.View.RemoveFromParent();

            ViewGroup frame = new PageContainer(_context, renderer);

            container.AddView(frame);

            return(new ObjectJavaBox <Tuple <ViewGroup, Page, int> >(new Tuple <ViewGroup, Page, int>(frame, child, position)));
        }
예제 #2
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;
            }
        }