@@ -226,26 +226,18 @@ class UINavigationControllerImpl extends UINavigationController implements UINav
226226 }
227227
228228 public navigationControllerWillShowViewControllerAnimated ( navigationController : UINavigationController , viewController : UIViewController , animated : boolean ) : void {
229- // This method is needed otherwise it will be too late and transition will completed before page is layouted .
229+ // In this method we need to layout the new page otherwise page will be shown empty and update after that which is bad UX .
230230 var frame = this . _owner ;
231- var backStack = frame . backStack ;
232- var currentEntry = backStack . length > 0 ? backStack [ backStack . length - 1 ] : null ;
233231 var newEntry : definition . BackstackEntry = viewController [ ENTRY ] ;
234-
235- var isBack = currentEntry && newEntry === currentEntry ;
236- if ( ! isBack ) {
237- var newPage = newEntry . resolvedPage ;
238-
239- if ( ! frame . _currentEntry ) {
240- frame . _currentEntry = newEntry ;
241- }
242- else {
243- frame . _navigateToEntry = newEntry ;
244- }
245-
232+ var newPage = newEntry . resolvedPage ;
233+ if ( ! newPage . parent ) {
234+ frame . _navigateToEntry = newEntry ;
246235 frame . _addView ( newPage ) ;
247236 frame . populateMenuItems ( newPage ) ;
248237 }
238+ else if ( newPage . parent !== frame ) {
239+ throw new Error ( "Page is already shown on another frame." ) ;
240+ }
249241 }
250242
251243 public navigationControllerDidShowViewControllerAnimated ( navigationController : UINavigationController , viewController : UIViewController , animated : boolean ) : void {
@@ -255,6 +247,8 @@ class UINavigationControllerImpl extends UINavigationController implements UINav
255247 var currentEntry = backStack . length > 0 ? backStack [ backStack . length - 1 ] : null ;
256248 var newEntry : definition . BackstackEntry = viewController [ ENTRY ] ;
257249
250+ // This code check if navigation happened through UI (e.g. back button or swipe gesture).
251+ // When calling goBack on frame isBack will be false.
258252 var isBack : boolean = currentEntry && newEntry === currentEntry ;
259253 if ( isBack ) {
260254 try {
@@ -267,16 +261,16 @@ class UINavigationControllerImpl extends UINavigationController implements UINav
267261 }
268262
269263 var page = frame . currentPage ;
270- if ( page && isBack ) {
264+ if ( page && ! navigationController . viewControllers . containsObject ( page . ios ) ) {
271265 frame . _removeView ( page ) ;
272266 }
273267
274- var newPage = newEntry . resolvedPage ;
275-
276268 frame . _navigateToEntry = null ;
277269 frame . _currentEntry = newEntry ;
278270 frame . updateNavigationBar ( ) ;
279-
271+
272+ var newPage = newEntry . resolvedPage ;
273+
280274 // notify the page
281275 newPage . onNavigatedTo ( newEntry . entry . context ) ;
282276 frame . _processNavigationQueue ( newPage ) ;
0 commit comments