Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: Frame replacePage by entry #9460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions packages/core/ui/frame/frame-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,14 @@ export class FrameBase extends CustomLayoutView {
if (this.currentPage && viewMatchesModuleContext(this.currentPage, context, ['markup', 'script'])) {
Trace.write(`Change Handled: Replacing page ${context.path}`, Trace.categories.Livesync);

this.replacePage(context.path);
// replace current page with a default fade transition
this.replacePage({
moduleName: context.path,
transition: {
name: 'fade',
duration: 100,
},
});

return true;
}
Expand Down Expand Up @@ -676,13 +683,18 @@ export class FrameBase extends CustomLayoutView {
return true;
}

protected replacePage(pagePath: string): void {
public replacePage(entry: string | NavigationEntry): void {
const currentBackstackEntry = this._currentEntry;
const contextModuleName = sanitizeModuleName(pagePath);

const newPage = <Page>Builder.createViewFromEntry({ moduleName: contextModuleName });
if (typeof entry === 'string') {
const contextModuleName = sanitizeModuleName(entry);
entry = { moduleName: contextModuleName };
}

const newPage = Builder.createViewFromEntry(entry) as Page;

const newBackstackEntry: BackstackEntry = {
entry: currentBackstackEntry.entry,
entry: Object.assign({}, currentBackstackEntry.entry, entry),
resolvedPage: newPage,
navDepth: currentBackstackEntry.navDepth,
fragmentTag: currentBackstackEntry.fragmentTag,
Expand Down
9 changes: 1 addition & 8 deletions packages/core/ui/frame/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const INTENT_EXTRA = 'com.tns.activity';
const ROOT_VIEW_ID_EXTRA = 'com.tns.activity.rootViewId';
const FRAMEID = '_frameId';
const CALLBACKS = '_callbacks';
const HMR_REPLACE_TRANSITION = 'fade';

const ownerSymbol = Symbol('_owner');
const activityRootViewsMap = new Map<number, WeakRef<View>>();
Expand Down Expand Up @@ -413,13 +412,7 @@ export class Frame extends FrameBase {
// layout pass so we will wait forever for transitionCompleted handler...
// https://github.com/NativeScript/NativeScript/issues/4895
let navigationTransition: NavigationTransition;
if (isReplace) {
animated = true;
navigationTransition = {
name: HMR_REPLACE_TRANSITION,
duration: 100,
};
} else if (this._currentEntry) {
if (this._currentEntry) {
navigationTransition = this._getNavigationTransition(newEntry.entry);
} else {
navigationTransition = null;
Expand Down
10 changes: 1 addition & 9 deletions packages/core/ui/frame/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const DELEGATE = '_delegate';
const NAV_DEPTH = '_navDepth';
const TRANSITION = '_transition';
const NON_ANIMATED_TRANSITION = 'non-animated';
const HMR_REPLACE_TRANSITION = 'fade';

let navDepth = -1;

Expand Down Expand Up @@ -84,14 +83,7 @@ export class Frame extends FrameBase {

let navigationTransition: NavigationTransition;
let animated = this.currentPage ? this._getIsAnimatedNavigation(backstackEntry.entry) : false;
if (isReplace) {
animated = true;
navigationTransition = {
name: HMR_REPLACE_TRANSITION,
duration: 100,
};
viewController[TRANSITION] = navigationTransition;
} else if (animated) {
if (animated) {
navigationTransition = this._getNavigationTransition(backstackEntry.entry);
if (navigationTransition) {
viewController[TRANSITION] = navigationTransition;
Expand Down