public override Fragment GetItem(int position) { var fragment = FragmentContainer.CreateInstance(_page.Children[position]); _fragments.Add(fragment); return(fragment); }
Fragment GetFragment(Page page, bool removed, bool popToRoot) { // pop if (removed) { return(_fragmentStack[_fragmentStack.Count - 2]); } // pop to root if (popToRoot) { return(_fragmentStack[0]); } // push return(FragmentContainer.CreateInstance(page)); }
void InsertPageBefore(Page page, Page before) { if (!_isAttachedToWindow) { PushCurrentPages(); } UpdateToolbar(); int index = PageController.InternalChildren.IndexOf(before); if (index == -1) { throw new InvalidOperationException("This should never happen, please file a bug"); } Fragment fragment = FragmentContainer.CreateInstance(page); _fragmentStack.Insert(index, fragment); }
protected override 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; } base.AddChildView(childView); } 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; } }