11// Definitions.
22import {
33 AndroidFrame as AndroidFrameDefinition , AndroidActivityCallbacks ,
4- AndroidFragmentCallbacks , BackstackEntry , NavigationTransition
4+ AndroidFragmentCallbacks , BackstackEntry , NavigationTransition , NavigationEntry
55} from "." ;
66import { Page } from "../page" ;
77
88// Types.
99import * as application from "../../application" ;
1010import {
11- FrameBase , goBack , stack , NavigationContext , NavigationType ,
11+ FrameBase , goBack , stack , NavigationType ,
1212 Observable , View , traceCategories , traceEnabled , traceError , traceWrite
1313} from "./frame-common" ;
1414
@@ -21,7 +21,6 @@ import { profile } from "../../profiling";
2121
2222// TODO: Remove this and get it from global to decouple builder for angular
2323import { createViewFromEntry } from "../builder" ;
24- import { getModuleName } from "../../utils/utils" ;
2524
2625export * from "./frame-common" ;
2726
@@ -37,6 +36,7 @@ const INTENT_EXTRA = "com.tns.activity";
3736const ROOT_VIEW_ID_EXTRA = "com.tns.activity.rootViewId" ;
3837const FRAMEID = "_frameId" ;
3938const CALLBACKS = "_callbacks" ;
39+ const HMR_REPLACE_TRANSITION = "fade" ;
4040
4141const ownerSymbol = Symbol ( "_owner" ) ;
4242const activityRootViewsMap = new Map < number , WeakRef < View > > ( ) ;
@@ -319,6 +319,18 @@ export class Frame extends FrameBase {
319319 restoreAnimatorState ( this . _currentEntry , this . _cachedAnimatorState ) ;
320320 this . _cachedAnimatorState = null ;
321321 }
322+
323+ // restore original fragment transitions if we just completed replace navigation (hmr)
324+ if ( navigationType === NavigationType . replace ) {
325+ _clearEntry ( entry ) ;
326+
327+ const animated = entry . entry . animated ;
328+ const navigationTransition = this . _getNavigationTransition ( entry . entry ) ;
329+ const currentEntry = null ;
330+ const newEntry = entry ;
331+ const transaction = null ;
332+ _setAndroidFragmentTransitions ( animated , navigationTransition , currentEntry , newEntry , transaction , this . _android . frameId ) ;
333+ }
322334 }
323335
324336 public onBackPressed ( ) : boolean {
@@ -381,12 +393,20 @@ export class Frame extends FrameBase {
381393 const newFragmentTag = `fragment${ fragmentId } [${ navDepth } ]` ;
382394 const newFragment = this . createFragment ( newEntry , newFragmentTag ) ;
383395 const transaction = manager . beginTransaction ( ) ;
384- const animated = currentEntry ? this . _getIsAnimatedNavigation ( newEntry . entry ) : false ;
396+ let animated = currentEntry ? this . _getIsAnimatedNavigation ( newEntry . entry ) : false ;
385397 // NOTE: Don't use transition for the initial navigation (same as on iOS)
386398 // On API 21+ transition won't be triggered unless there was at least one
387399 // layout pass so we will wait forever for transitionCompleted handler...
388400 // https://github.com/NativeScript/NativeScript/issues/4895
389- const navigationTransition = this . _currentEntry ? this . _getNavigationTransition ( newEntry . entry ) : null ;
401+ let navigationTransition : NavigationTransition ;
402+ if ( isReplace ) {
403+ animated = true ;
404+ navigationTransition = { name : HMR_REPLACE_TRANSITION , duration : 100 } ;
405+ } else if ( this . _currentEntry ) {
406+ navigationTransition = this . _getNavigationTransition ( newEntry . entry ) ;
407+ } else {
408+ navigationTransition = null ;
409+ }
390410
391411 _setAndroidFragmentTransitions ( animated , navigationTransition , currentEntry , newEntry , transaction , this . _android . frameId ) ;
392412
0 commit comments