@@ -17,6 +17,8 @@ import { NavigationData } from '.';
1717export { NavigationType } from './frame-interfaces' ;
1818export type { AndroidActivityCallbacks , AndroidFragmentCallbacks , AndroidFrame , BackstackEntry , NavigationContext , NavigationEntry , NavigationTransition , TransitionState , ViewEntry , iOSFrame } from './frame-interfaces' ;
1919
20+ const FRAME_ENTRY_LOADED_EVENT = '_frameEntryLoaded' ;
21+
2022function buildEntryFromArgs ( arg : any ) : NavigationEntry {
2123 let entry : NavigationEntry ;
2224 if ( typeof arg === 'string' ) {
@@ -76,13 +78,13 @@ export class FrameBase extends CustomLayoutView {
7678 return true ;
7779 } else if ( top ) {
7880 let parentFrameCanGoBack = false ;
79- let parentFrame = < FrameBase > getAncestor ( top , 'Frame' ) ;
81+ let parentFrame = getAncestor ( top , 'Frame' ) ;
8082
8183 while ( parentFrame && ! parentFrameCanGoBack ) {
8284 if ( parentFrame && parentFrame . canGoBack ( ) ) {
8385 parentFrameCanGoBack = true ;
8486 } else {
85- parentFrame = < FrameBase > getAncestor ( parentFrame , 'Frame' ) ;
87+ parentFrame = getAncestor ( parentFrame , 'Frame' ) ;
8688 }
8789 }
8890
@@ -127,14 +129,29 @@ export class FrameBase extends CustomLayoutView {
127129 super . onLoaded ( ) ;
128130
129131 if ( parentFrame ?. isLoadingSubviews ) {
130- parentFrame . once ( 'frameEntryLoaded' , ( ) => {
131- this . onFrameLoaded ( ) ;
132+ const frameRef = new WeakRef ( this ) ;
133+
134+ parentFrame . once ( FRAME_ENTRY_LOADED_EVENT , ( ) => {
135+ const frame = frameRef . deref ( ) ;
136+ if ( frame ) {
137+ frame . onFrameLoaded ( ) ;
138+ }
132139 } ) ;
133140 } else {
134141 this . onFrameLoaded ( ) ;
135142 }
136143 }
137144
145+ @profile
146+ public onUnloaded ( ) {
147+ super . onUnloaded ( ) ;
148+
149+ // This is a precaution in case the method is called asynchronously during the loading procedure
150+ if ( this . hasListeners ( FRAME_ENTRY_LOADED_EVENT ) ) {
151+ this . off ( FRAME_ENTRY_LOADED_EVENT ) ;
152+ }
153+ }
154+
138155 public onFrameLoaded ( ) : void {
139156 this . _processNextNavigationEntry ( ) ;
140157 this . _notifyFrameEntryLoaded ( ) ;
@@ -338,15 +355,16 @@ export class FrameBase extends CustomLayoutView {
338355
339356 protected _notifyFrameEntryLoaded ( ) : void {
340357 this . notify ( {
341- eventName : 'frameEntryLoaded' ,
358+ eventName : FRAME_ENTRY_LOADED_EVENT ,
342359 object : this ,
343360 } ) ;
344361 }
345362
346363 private isNestedWithin ( parentFrameCandidate : FrameBase ) : boolean {
347- let frameAncestor : FrameBase = this ;
364+ let frameAncestor = this as FrameBase ;
365+
348366 while ( frameAncestor ) {
349- frameAncestor = < FrameBase > getAncestor ( frameAncestor , FrameBase ) ;
367+ frameAncestor = getAncestor ( frameAncestor , FrameBase ) ;
350368 if ( frameAncestor === parentFrameCandidate ) {
351369 return true ;
352370 }
0 commit comments