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

Commit

Permalink
fix(wechat): 微信增加 onShareTimeline 生命周期
Browse files Browse the repository at this point in the history
  • Loading branch information
Darmody committed Aug 10, 2020
1 parent 5946163 commit 3e5f3cb
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/remax-cli/src/build/babel/pageEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { pageClassEvents } from '../webpack/plugins/RuntimeOptions';
import { Options } from '@remax/types';
import { slash } from '@remax/shared';

const lifecycleEvents = ['onPageScroll', 'onShareAppMessage'];
const lifecycleEvents = ['onPageScroll', 'onShareAppMessage', 'onShareTimeline'];

export default (options: Options) => {
let skip = false;
Expand Down
1 change: 1 addition & 0 deletions packages/remax-macro/src/macro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type PageEventName =
| 'onReachBottom'
| 'onPageScroll'
| 'onShareAppMessage'
| 'onShareTimeline'
| 'onTitleClick'
| 'onOptionMenuClick'
| 'onPopMenuClick'
Expand Down
1 change: 1 addition & 0 deletions packages/remax-runtime/src/__tests__/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('app', () => {
'onReachBottom',
'onPageScroll',
'onShareAppMessage',
'onShareTimeline',
'onTitleClick',
'onOptionMenuClick',
'onPopMenuClick',
Expand Down
8 changes: 8 additions & 0 deletions packages/remax-runtime/src/__tests__/helpers/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ class Page {
});
}

shareTimeline() {
this.config.onShareTimeline({
from: 'menu',
target: undefined,
webViewUrl: 'https://www.alipay.com',
});
}

titleClick() {
this.config.onTitleClick();
}
Expand Down
19 changes: 19 additions & 0 deletions packages/remax-runtime/src/__tests__/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('page', () => {
'onReachBottom',
'onPageScroll',
'onShareAppMessage',
'onShareTimeline',
'onTitleClick',
'onOptionMenuClick',
'onPopMenuClick',
Expand Down Expand Up @@ -97,6 +98,13 @@ describe('page', () => {
return {};
});

usePageEvent('onShareTimeline', object => {
log.push(object.from);
log.push('useShareTimeline');

return {};
});

usePageEvent('onTitleClick', () => {
log.push('useTitleClick');
});
Expand Down Expand Up @@ -147,6 +155,7 @@ describe('page', () => {
page.reachBottom();
page.pageScroll();
page.shareAppMessage();
page.shareTimeline();
page.titleClick();
page.optionMenuClick();
page.popMenuClick();
Expand All @@ -169,6 +178,8 @@ describe('page', () => {
'usePageScroll',
'menu',
'useShareAppMessage',
'menu',
'useShareTimeline',
'useTitleClick',
'useOptionMenuClick',
'usePopMenuClick',
Expand Down Expand Up @@ -276,6 +287,11 @@ describe('page', () => {
log.push('onShareAppMessage');
}

onShareTimeline(object: any) {
log.push(object.from);
log.push('onShareTimeline');
}

onTitleClick() {
log.push('onTitleClick');
}
Expand Down Expand Up @@ -324,6 +340,7 @@ describe('page', () => {
page.reachBottom();
page.pageScroll();
page.shareAppMessage();
page.shareTimeline();
page.titleClick();
page.optionMenuClick();
page.popMenuClick();
Expand All @@ -346,6 +363,8 @@ describe('page', () => {
'onPageScroll',
'menu',
'onShareAppMessage',
'menu',
'onShareTimeline',
'onTitleClick',
'onOptionMenuClick',
'onPopMenuClick',
Expand Down
4 changes: 4 additions & 0 deletions packages/remax-runtime/src/createPageConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ export default function createPageConfig(Page: React.ComponentType<any>, name: s
onShareAppMessage(options: any) {
return this.callLifecycle(Lifecycle.shareAppMessage, options) || {};
},

onShareTimeline(options: any) {
return this.callLifecycle(Lifecycle.shareTimeline, options) || {};
},
};

pageEvents(name).forEach(eventName => {
Expand Down
1 change: 1 addition & 0 deletions packages/remax-runtime/src/lifecycle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export enum Lifecycle {
reachBottom = 'reachBottom',
pageScroll = 'pageScroll',
shareAppMessage = 'shareAppMessage',
shareTimeline = 'shareTimeline',
titleClick = 'titleClick',
optionMenuClick = 'optionMenuClick',
popMenuClick = 'popMenuClick',
Expand Down

1 comment on commit 3e5f3cb

@vercel
Copy link

@vercel vercel bot commented on 3e5f3cb Aug 10, 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.