@@ -7,7 +7,6 @@ import { IOSHelper } from '../core/view/view-helper';
7
7
import { profile } from '../../profiling' ;
8
8
import { CORE_ANIMATION_DEFAULTS , ios as iOSUtils , layout } from '../../utils' ;
9
9
import { Trace } from '../../trace' ;
10
- import type { PageTransition } from '../transition/page-transition' ;
11
10
import { SlideTransition } from '../transition/slide-transition' ;
12
11
import { FadeTransition } from '../transition/fade-transition' ;
13
12
import { SharedTransition } from '../transition/shared-transition' ;
@@ -22,11 +21,11 @@ const NAV_DEPTH = '_navDepth';
22
21
const TRANSITION = '_transition' ;
23
22
const NON_ANIMATED_TRANSITION = 'non-animated' ;
24
23
25
- let navDepth = - 1 ;
24
+ let navDepth : number = - 1 ;
25
+ let navControllerDelegate : UINavigationControllerDelegate = null ;
26
26
27
27
export class Frame extends FrameBase {
28
28
viewController : UINavigationControllerImpl ;
29
- _animatedDelegate : UINavigationControllerDelegate ;
30
29
public _ios : iOSFrame ;
31
30
iosNavigationBarClass : typeof NSObject ;
32
31
iosToolbarClass : typeof NSObject ;
@@ -38,6 +37,11 @@ export class Frame extends FrameBase {
38
37
}
39
38
40
39
createNativeView ( ) {
40
+ // Push frame back in frame stack since it was removed in disposeNativeView() method.
41
+ if ( this . _currentEntry ) {
42
+ this . _pushInFrameStack ( ) ;
43
+ }
44
+
41
45
return this . viewController . view ;
42
46
}
43
47
@@ -61,7 +65,12 @@ export class Frame extends FrameBase {
61
65
62
66
this . _removeFromFrameStack ( ) ;
63
67
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
+
65
74
if ( this . _ios ) {
66
75
this . _ios . controller = null ;
67
76
this . _ios = null ;
@@ -120,11 +129,12 @@ export class Frame extends FrameBase {
120
129
121
130
const nativeTransition = _getNativeTransition ( navigationTransition , true ) ;
122
131
if ( ! nativeTransition && navigationTransition ) {
123
- if ( ! this . _animatedDelegate ) {
124
- this . _animatedDelegate = < UINavigationControllerDelegate > UINavigationControllerAnimatedDelegate . initWithOwner ( new WeakRef ( this ) ) ;
132
+ if ( ! navControllerDelegate ) {
133
+ navControllerDelegate = < UINavigationControllerDelegate > UINavigationControllerAnimatedDelegate . new ( ) ;
125
134
}
126
- this . _ios . controller . delegate = this . _animatedDelegate ;
127
- viewController [ DELEGATE ] = this . _animatedDelegate ;
135
+
136
+ this . _ios . controller . delegate = navControllerDelegate ;
137
+ viewController [ DELEGATE ] = navControllerDelegate ;
128
138
if ( navigationTransition . instance ) {
129
139
this . transitionId = navigationTransition . instance . id ;
130
140
const transitionState = SharedTransition . getState ( this . transitionId ) ;
@@ -346,19 +356,6 @@ export class Frame extends FrameBase {
346
356
public _setNativeViewFrame ( nativeView : UIView , frame : CGRect ) {
347
357
//
348
358
}
349
-
350
- public _onNavigatingTo ( backstackEntry : BackstackEntry , isBack : boolean ) {
351
- // for now to not break iOS events chain (calling navigation events from controller delegates)
352
- // we dont call super(which would also trigger events) but only notify the frame of the navigation
353
- // though it means events are not triggered at the same time (lifecycle) on iOS / Android
354
- this . notify ( {
355
- eventName : Page . navigatingToEvent ,
356
- object : this ,
357
- isBack,
358
- entry : backstackEntry ,
359
- fromEntry : this . _currentEntry ,
360
- } ) ;
361
- }
362
359
}
363
360
364
361
const transitionDelegates = new Array < TransitionDelegate > ( ) ;
@@ -413,14 +410,6 @@ class TransitionDelegate extends NSObject {
413
410
@NativeClass
414
411
class UINavigationControllerAnimatedDelegate extends NSObject implements UINavigationControllerDelegate {
415
412
public static ObjCProtocols = [ UINavigationControllerDelegate ] ;
416
- owner : WeakRef < Frame > ;
417
- transition : PageTransition ;
418
-
419
- static initWithOwner ( owner : WeakRef < Frame > ) {
420
- const delegate = < UINavigationControllerAnimatedDelegate > UINavigationControllerAnimatedDelegate . new ( ) ;
421
- delegate . owner = owner ;
422
- return delegate ;
423
- }
424
413
425
414
navigationControllerAnimationControllerForOperationFromViewControllerToViewController ( navigationController : UINavigationController , operation : number , fromVC : UIViewController , toVC : UIViewController ) : UIViewControllerAnimatedTransitioning {
426
415
let viewController : UIViewController ;
@@ -445,29 +434,30 @@ class UINavigationControllerAnimatedDelegate extends NSObject implements UINavig
445
434
if ( Trace . isEnabled ( ) ) {
446
435
Trace . write ( `UINavigationControllerImpl.navigationControllerAnimationControllerForOperationFromViewControllerToViewController(${ operation } , ${ fromVC } , ${ toVC } ), transition: ${ JSON . stringify ( navigationTransition ) } ` , Trace . categories . NativeLifecycle ) ;
447
436
}
448
- this . transition = navigationTransition . instance ;
449
437
450
- if ( ! this . transition ) {
438
+ let transition = navigationTransition . instance ;
439
+
440
+ if ( ! transition ) {
451
441
if ( navigationTransition . name ) {
452
442
const curve = _getNativeCurve ( navigationTransition ) ;
453
443
const name = navigationTransition . name . toLowerCase ( ) ;
454
444
if ( name . indexOf ( 'slide' ) === 0 ) {
455
- const direction = name . substring ( 'slide' . length ) || 'left' ; //Extract the direction from the string
456
- 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 ) ;
457
447
} else if ( name === 'fade' ) {
458
- this . transition = new FadeTransition ( navigationTransition . duration , curve ) ;
448
+ transition = new FadeTransition ( navigationTransition . duration , curve ) ;
459
449
}
460
450
}
461
451
}
462
452
463
- if ( this . transition ?. iosNavigatedController ) {
464
- return this . transition . iosNavigatedController ( navigationController , operation , fromVC , toVC ) ;
453
+ if ( transition ?. iosNavigatedController ) {
454
+ return transition . iosNavigatedController ( navigationController , operation , fromVC , toVC ) ;
465
455
}
466
456
return null ;
467
457
}
468
458
469
- navigationControllerInteractionControllerForAnimationController ( navigationController : UINavigationController , animationController : UIViewControllerAnimatedTransitioning ) : UIViewControllerInteractiveTransitioning {
470
- const owner = this . owner ?. deref ( ) ;
459
+ navigationControllerInteractionControllerForAnimationController ( navigationController : UINavigationControllerImpl , animationController : UIViewControllerAnimatedTransitioning ) : UIViewControllerInteractiveTransitioning {
460
+ const owner = navigationController . owner ;
471
461
if ( owner ) {
472
462
const state = SharedTransition . getState ( owner . transitionId ) ;
473
463
if ( state ?. instance ?. iosInteractionDismiss ) {
0 commit comments