@@ -7,7 +7,6 @@ import { IOSHelper } from '../core/view/view-helper';
77import { profile } from '../../profiling' ;
88import { CORE_ANIMATION_DEFAULTS , ios as iOSUtils , layout } from '../../utils' ;
99import { Trace } from '../../trace' ;
10- import type { PageTransition } from '../transition/page-transition' ;
1110import { SlideTransition } from '../transition/slide-transition' ;
1211import { FadeTransition } from '../transition/fade-transition' ;
1312import { SharedTransition } from '../transition/shared-transition' ;
@@ -22,11 +21,11 @@ const NAV_DEPTH = '_navDepth';
2221const TRANSITION = '_transition' ;
2322const NON_ANIMATED_TRANSITION = 'non-animated' ;
2423
25- let navDepth = - 1 ;
24+ let navDepth : number = - 1 ;
25+ let navControllerDelegate : UINavigationControllerDelegate = null ;
2626
2727export class Frame extends FrameBase {
2828 viewController : UINavigationControllerImpl ;
29- _animatedDelegate : UINavigationControllerDelegate ;
3029 public _ios : iOSFrame ;
3130 iosNavigationBarClass : typeof NSObject ;
3231 iosToolbarClass : typeof NSObject ;
@@ -38,6 +37,11 @@ export class Frame extends FrameBase {
3837 }
3938
4039 createNativeView ( ) {
40+ // Push frame back in frame stack since it was removed in disposeNativeView() method.
41+ if ( this . _currentEntry ) {
42+ this . _pushInFrameStack ( ) ;
43+ }
44+
4145 return this . viewController . view ;
4246 }
4347
@@ -61,7 +65,12 @@ export class Frame extends FrameBase {
6165
6266 this . _removeFromFrameStack ( ) ;
6367 this . viewController = null ;
64- this . _animatedDelegate = null ;
68+
69+ // This was the last frame so we can get rid of the controller delegate reference
70+ if ( this . _isFrameStackEmpty ( ) ) {
71+ navControllerDelegate = null ;
72+ }
73+
6574 if ( this . _ios ) {
6675 this . _ios . controller = null ;
6776 this . _ios = null ;
@@ -120,11 +129,12 @@ export class Frame extends FrameBase {
120129
121130 const nativeTransition = _getNativeTransition ( navigationTransition , true ) ;
122131 if ( ! nativeTransition && navigationTransition ) {
123- if ( ! this . _animatedDelegate ) {
124- this . _animatedDelegate = < UINavigationControllerDelegate > UINavigationControllerAnimatedDelegate . initWithOwner ( new WeakRef ( this ) ) ;
132+ if ( ! navControllerDelegate ) {
133+ navControllerDelegate = < UINavigationControllerDelegate > UINavigationControllerAnimatedDelegate . new ( ) ;
125134 }
126- this . _ios . controller . delegate = this . _animatedDelegate ;
127- viewController [ DELEGATE ] = this . _animatedDelegate ;
135+
136+ this . _ios . controller . delegate = navControllerDelegate ;
137+ viewController [ DELEGATE ] = navControllerDelegate ;
128138 if ( navigationTransition . instance ) {
129139 this . transitionId = navigationTransition . instance . id ;
130140 const transitionState = SharedTransition . getState ( this . transitionId ) ;
@@ -400,14 +410,6 @@ class TransitionDelegate extends NSObject {
400410@NativeClass
401411class UINavigationControllerAnimatedDelegate extends NSObject implements UINavigationControllerDelegate {
402412 public static ObjCProtocols = [ UINavigationControllerDelegate ] ;
403- owner : WeakRef < Frame > ;
404- transition : PageTransition ;
405-
406- static initWithOwner ( owner : WeakRef < Frame > ) {
407- const delegate = < UINavigationControllerAnimatedDelegate > UINavigationControllerAnimatedDelegate . new ( ) ;
408- delegate . owner = owner ;
409- return delegate ;
410- }
411413
412414 navigationControllerAnimationControllerForOperationFromViewControllerToViewController ( navigationController : UINavigationController , operation : number , fromVC : UIViewController , toVC : UIViewController ) : UIViewControllerAnimatedTransitioning {
413415 let viewController : UIViewController ;
@@ -432,29 +434,30 @@ class UINavigationControllerAnimatedDelegate extends NSObject implements UINavig
432434 if ( Trace . isEnabled ( ) ) {
433435 Trace . write ( `UINavigationControllerImpl.navigationControllerAnimationControllerForOperationFromViewControllerToViewController(${ operation } , ${ fromVC } , ${ toVC } ), transition: ${ JSON . stringify ( navigationTransition ) } ` , Trace . categories . NativeLifecycle ) ;
434436 }
435- this . transition = navigationTransition . instance ;
436437
437- if ( ! this . transition ) {
438+ let transition = navigationTransition . instance ;
439+
440+ if ( ! transition ) {
438441 if ( navigationTransition . name ) {
439442 const curve = _getNativeCurve ( navigationTransition ) ;
440443 const name = navigationTransition . name . toLowerCase ( ) ;
441444 if ( name . indexOf ( 'slide' ) === 0 ) {
442- const direction = name . substring ( 'slide' . length ) || 'left' ; //Extract the direction from the string
443- this . transition = new SlideTransition ( direction , navigationTransition . duration , curve ) ;
445+ const direction = name . substring ( 'slide' . length ) || 'left' ; // Extract the direction from the string
446+ transition = new SlideTransition ( direction , navigationTransition . duration , curve ) ;
444447 } else if ( name === 'fade' ) {
445- this . transition = new FadeTransition ( navigationTransition . duration , curve ) ;
448+ transition = new FadeTransition ( navigationTransition . duration , curve ) ;
446449 }
447450 }
448451 }
449452
450- if ( this . transition ?. iosNavigatedController ) {
451- return this . transition . iosNavigatedController ( navigationController , operation , fromVC , toVC ) ;
453+ if ( transition ?. iosNavigatedController ) {
454+ return transition . iosNavigatedController ( navigationController , operation , fromVC , toVC ) ;
452455 }
453456 return null ;
454457 }
455458
456- navigationControllerInteractionControllerForAnimationController ( navigationController : UINavigationController , animationController : UIViewControllerAnimatedTransitioning ) : UIViewControllerInteractiveTransitioning {
457- const owner = this . owner ?. deref ( ) ;
459+ navigationControllerInteractionControllerForAnimationController ( navigationController : UINavigationControllerImpl , animationController : UIViewControllerAnimatedTransitioning ) : UIViewControllerInteractiveTransitioning {
460+ const owner = navigationController . owner ;
458461 if ( owner ) {
459462 const state = SharedTransition . getState ( owner . transitionId ) ;
460463 if ( state ?. instance ?. iosInteractionDismiss ) {
0 commit comments