@@ -13,6 +13,7 @@ import { getModuleName } from "../../utils/utils";
1313export * from "../core/view" ;
1414
1515export enum NavigationType {
16+ unset ,
1617 back ,
1718 forward ,
1819 replace
@@ -37,7 +38,9 @@ function buildEntryFromArgs(arg: any): NavigationEntry {
3738
3839export interface NavigationContext {
3940 entry : BackstackEntry ;
41+ // TODO: remove isBackNavigation for NativeScript 6.0
4042 isBackNavigation : boolean ;
43+ navigationType : NavigationType
4144}
4245
4346@CSSType ( "Frame" )
@@ -51,11 +54,10 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition {
5154
5255 public actionBarVisibility : "auto" | "never" | "always" ;
5356 public _currentEntry : BackstackEntry ;
54- public _executingEntry : BackstackEntry ;
57+ public _executingContext : NavigationContext ;
5558 public _isInFrameStack = false ;
5659 public static defaultAnimatedNavigation = true ;
5760 public static defaultTransition : NavigationTransition ;
58- public navigationType : NavigationType ;
5961
6062 // TODO: Currently our navigation will not be synchronized in case users directly call native navigation methods like Activity.startActivity.
6163
@@ -75,7 +77,8 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition {
7577 let previousForwardNotInBackstack = false ;
7678 this . _navigationQueue . forEach ( item => {
7779 const entry = item . entry ;
78- if ( item . isBackNavigation ) {
80+ const isBackNavigation = item . navigationType === NavigationType . back ;
81+ if ( isBackNavigation ) {
7982 previousForwardNotInBackstack = false ;
8083 if ( ! entry ) {
8184 backstack -- ;
@@ -135,7 +138,8 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition {
135138
136139 const navigationContext : NavigationContext = {
137140 entry : backstackEntry ,
138- isBackNavigation : true
141+ isBackNavigation : true ,
142+ navigationType : NavigationType . back
139143 }
140144
141145 this . _navigationQueue . push ( navigationContext ) ;
@@ -203,7 +207,8 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition {
203207
204208 const navigationContext : NavigationContext = {
205209 entry : backstackEntry ,
206- isBackNavigation : false
210+ isBackNavigation : false ,
211+ navigationType : NavigationType . forward
207212 }
208213
209214 this . _navigationQueue . push ( navigationContext ) ;
@@ -214,7 +219,7 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition {
214219 return this . _currentEntry === entry ;
215220 }
216221
217- public setCurrent ( entry : BackstackEntry , navigationType : NavigationType ) : void {
222+ public setCurrent ( entry : BackstackEntry ) : void {
218223 const newPage = entry . resolvedPage ;
219224 // In case we navigated forward to a page that was in the backstack
220225 // with clearHistory: true
@@ -225,17 +230,19 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition {
225230
226231 this . _currentEntry = entry ;
227232
233+ const navigationContext = this . _executingContext || { navigationType : NavigationType . unset } ;
234+ const navigationType = navigationContext . navigationType ;
228235 const isBack = navigationType === NavigationType . back ;
229236 if ( isBack ) {
230237 this . _pushInFrameStack ( ) ;
231238 }
232239
233240 newPage . onNavigatedTo ( isBack ) ;
234241
235- // Reset executing entry after NavigatedTo is raised;
242+ // Reset executing context after NavigatedTo is raised;
236243 // we do not want to execute two navigations in parallel in case
237244 // additional navigation is triggered from the NavigatedTo handler.
238- this . _executingEntry = null ;
245+ this . _executingContext = null ;
239246 }
240247
241248 public _updateBackstack ( entry : BackstackEntry , navigationType : NavigationType ) : void {
@@ -342,13 +349,14 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition {
342349 }
343350
344351 protected _processNextNavigationEntry ( ) {
345- if ( ! this . isLoaded || this . _executingEntry ) {
352+ if ( ! this . isLoaded || this . _executingContext ) {
346353 return ;
347354 }
348355
349356 if ( this . _navigationQueue . length > 0 ) {
350357 const navigationContext = this . _navigationQueue [ 0 ] ;
351- if ( navigationContext . isBackNavigation ) {
358+ const isBackNavigation = navigationContext . navigationType === NavigationType . back ;
359+ if ( isBackNavigation ) {
352360 this . performGoBack ( navigationContext ) ;
353361 } else {
354362 this . performNavigation ( navigationContext ) ;
@@ -358,10 +366,12 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition {
358366
359367 @profile
360368 public performNavigation ( navigationContext : NavigationContext ) {
361- const navContext = navigationContext . entry ;
362- this . _executingEntry = navContext ;
363- this . _onNavigatingTo ( navContext , navigationContext . isBackNavigation ) ;
364- this . _navigateCore ( navContext ) ;
369+ this . _executingContext = navigationContext ;
370+
371+ const backstackEntry = navigationContext . entry ;
372+ const isBackNavigation = navigationContext . navigationType === NavigationType . back ;
373+ this . _onNavigatingTo ( backstackEntry , isBackNavigation ) ;
374+ this . _navigateCore ( backstackEntry ) ;
365375 }
366376
367377 @profile
@@ -373,7 +383,7 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition {
373383 navigationContext . entry = backstackEntry ;
374384 }
375385
376- this . _executingEntry = backstackEntry ;
386+ this . _executingContext = navigationContext ;
377387 this . _onNavigatingTo ( backstackEntry , true ) ;
378388 this . _goBackCore ( backstackEntry ) ;
379389 }
@@ -643,9 +653,6 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition {
643653 }
644654
645655 protected replacePage ( context : ModuleContext ) : void {
646- // Set NavigationType.replace for HMR.
647- // In IOS on `viewDidAppear()` this will be set to NavigationType.forward.
648- this . navigationType = NavigationType . replace ;
649656 const currentBackstackEntry = this . _currentEntry ;
650657 const contextModuleName = getModuleName ( context . path ) ;
651658
@@ -658,10 +665,15 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition {
658665 frameId : currentBackstackEntry . frameId
659666 } ;
660667
661- const navContext : NavigationContext = { entry : newBackstackEntry , isBackNavigation : false } ;
662- this . performNavigation ( navContext ) ;
663- }
668+ const navigationContext : NavigationContext = {
669+ entry : newBackstackEntry ,
670+ isBackNavigation : false ,
671+ navigationType : NavigationType . replace
672+ } ;
664673
674+ this . _navigationQueue . push ( navigationContext ) ;
675+ this . _processNextNavigationEntry ( ) ;
676+ }
665677}
666678
667679export function getFrameById ( id : string ) : FrameBase {
0 commit comments