Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
fix: 修复同一页面的生命周期会重复触发的问题 (#1289)
Browse files Browse the repository at this point in the history
fix #1288
  • Loading branch information
Darmody committed Sep 16, 2020
1 parent 7d10e81 commit 4e8fef1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
10 changes: 5 additions & 5 deletions packages/remax-runtime/src/__tests__/helpers/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,21 @@ class Page {
}

back() {
this.config.events.onBack();
this.config.events.onBack.apply(this.config);
}

keyboardHeight() {
this.config.events.onKeyboardHeight();
this.config.events.onKeyboardHeight.apply(this.config);
}
tabItemTap() {
this.config.events.onTabItemTap();
this.config.events.onTabItemTap.apply(this.config);
this.config.onTabItemTap();
}
beforeTabItemTap() {
this.config.events.beforeTabItemTap();
this.config.events.beforeTabItemTap.apply(this.config);
}
resize() {
this.config.events.onResize();
this.config.events.onResize.apply(this.config);
this.config.onResize();
}
}
Expand Down
43 changes: 23 additions & 20 deletions packages/remax-runtime/src/createPageConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,36 @@ export function resetPageId() {
idCounter = 0;
}

const defaultData = {
root: {
children: [],
},
modalRoot: {
children: [],
},
};

const defaultLifecycleCallback: any = {};

export default function createPageConfig(Page: React.ComponentType<any>, name: string) {
const app = getApp() as any;

const config: any = {
data: defaultData,
data: {
root: {
children: [],
},
modalRoot: {
children: [],
},
},

wrapperRef: React.createRef<any>(),

lifecycleCallback: defaultLifecycleCallback,
lifecycleCallback: {},

onLoad(this: any, query: any) {
const PageWrapper = createPageWrapper(Page, name);
this.pageId = generatePageId();

this.lifecycleCallback = defaultLifecycleCallback;
this.data = defaultData;
this.lifecycleCallback = {};
this.data = {
root: {
children: [],
},
modalRoot: {
children: [],
},
};

this.query = query;
this.container = new Container(this, 'root');
Expand Down Expand Up @@ -114,25 +117,25 @@ export default function createPageConfig(Page: React.ComponentType<any>, name: s
events: {
// 页面返回时触发
onBack(this: any, e: any) {
return config.callLifecycle(Lifecycle.back, e);
return this.callLifecycle(Lifecycle.back, e);
},

// 键盘高度变化时触发
onKeyboardHeight(this: any, e: any) {
return config.callLifecycle(Lifecycle.keyboardHeight, e);
return this.callLifecycle(Lifecycle.keyboardHeight, e);
},

onTabItemTap(this: any, e: any) {
return config.callLifecycle(Lifecycle.tabItemTap, e);
return this.callLifecycle(Lifecycle.tabItemTap, e);
},

// 点击但切换tabItem前触发
beforeTabItemTap(this: any) {
return config.callLifecycle(Lifecycle.beforeTabItemTap);
return this.callLifecycle(Lifecycle.beforeTabItemTap);
},

onResize(this: any, e: any) {
return config.callLifecycle(Lifecycle.resize, e);
return this.callLifecycle(Lifecycle.resize, e);
},
},

Expand Down

1 comment on commit 4e8fef1

@vercel
Copy link

@vercel vercel bot commented on 4e8fef1 Sep 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.