MCPcopy Index your code
hub / github.com/ionic-team/ionic-framework / postViewInit

Method postViewInit

core/src/components/nav/nav.tsx:789–865  ·  view source on GitHub ↗

* Adds and Removes the views from the navigation stack. * * @param enteringView The view being entered. * @param leavingView The view being left. * @param ti The instructions.

(
    enteringView: ViewController | undefined,
    leavingView: ViewController | undefined,
    ti: TransitionInstruction
  )

Source from the content-addressed store, hash-verified

787 * @param ti The instructions.
788 */
789 private postViewInit(
790 enteringView: ViewController | undefined,
791 leavingView: ViewController | undefined,
792 ti: TransitionInstruction
793 ): void {
794 assert(leavingView || enteringView, 'Both leavingView and enteringView are null');
795 assert(ti.resolve, 'resolve must be valid');
796 assert(ti.reject, 'reject must be valid');
797
798 // Compute the views to remove.
799 const opts = ti.opts!;
800 const { insertViews, removeStart, removeCount } = ti;
801 /** Records the view to destroy */
802 let destroyQueue: ViewController[] | undefined;
803
804 // there are views to remove
805 if (removeStart !== undefined && removeCount !== undefined) {
806 assert(removeStart >= 0, 'removeStart can not be negative');
807 assert(removeCount >= 0, 'removeCount can not be negative');
808
809 destroyQueue = [];
810 for (let i = removeStart; i < removeStart + removeCount; i++) {
811 const view = this.views[i];
812 if (view !== undefined && view !== enteringView && view !== leavingView) {
813 destroyQueue.push(view);
814 }
815 }
816 // default the direction to "back"
817 opts.direction ??= 'back';
818 }
819
820 const finalNumViews = this.views.length + (insertViews?.length ?? 0) - (removeCount ?? 0);
821 assert(finalNumViews >= 0, 'final balance can not be negative');
822 if (finalNumViews === 0) {
823 printIonWarning(
824 `[ion-nav] - You can't remove all the pages in the navigation stack. nav.pop() is probably called too many times.`,
825 this,
826 this.el
827 );
828
829 throw new Error('navigation stack needs at least one root page');
830 }
831
832 // At this point the transition can not be rejected, any throw should be an error
833 // Insert the new views in the stack.
834 if (insertViews) {
835 // add the views to the
836 let insertIndex = ti.insertStart!;
837 for (const view of insertViews) {
838 this.insertViewAt(view, insertIndex);
839 insertIndex++;
840 }
841
842 if (ti.enteringRequiresTransition) {
843 // default to forward if not already set
844 opts.direction ??= 'forward';
845 }
846 }

Callers 1

runTransitionMethod · 0.95

Calls 6

insertViewAtMethod · 0.95
destroyViewMethod · 0.95
assertFunction · 0.90
printIonWarningFunction · 0.90
lifecycleFunction · 0.90
pushMethod · 0.45

Tested by

no test coverage detected