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

Commit

Permalink
fix(web): 修复 web 下即使离开页面 onPageScroll 事件也会触发的问题 (#1232)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darmody authored Aug 19, 2020
1 parent 4623220 commit 7ae649e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/remax-runtime/src/createPageConfig.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,23 @@ export default function createPageConfig(Page: React.ComponentType<any>, name: s
page.callLifecycle(Lifecycle.show);
page.callLifecycle(Lifecycle.ready);

this.handlePageScroll();
this.registerPageScroll();
}

componentWillUnmount() {
window.removeEventListener('scroll', this.scrollEvent);
this.unregisterPageScroll();
}

componentDidCache = () => {
this.title = document.title;
page.callLifecycle(Lifecycle.hide);
this.unregisterPageScroll();
};

componentDidRecover = () => {
this.setTitle();
page.callLifecycle(Lifecycle.show);
this.registerPageScroll();
};

setTitle = () => {
Expand Down Expand Up @@ -110,10 +112,14 @@ export default function createPageConfig(Page: React.ComponentType<any>, name: s
page.callLifecycle(Lifecycle.pageScroll, event);
};

handlePageScroll = () => {
registerPageScroll = () => {
window.addEventListener('scroll', this.scrollEvent);
};

unregisterPageScroll = () => {
window.removeEventListener('scroll', this.scrollEvent);
};

handleRefresh = async () => {
this.setState({
refreshing: true,
Expand Down

1 comment on commit 7ae649e

@vercel
Copy link

@vercel vercel bot commented on 7ae649e Aug 19, 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.