Skip to content

Commit

Permalink
fix(react): 修复编译小程序插件不能触发分享的问题,fix #10105
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen-jj committed Feb 16, 2022
1 parent d3e7f74 commit 7c2ce64
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion packages/taro-plugin-react/src/runtime/connect-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function createNativeComponentConfig (Component, react: typeof React, rea

setReconciler(ReactDOM)

const componentObj = {
const componentObj: Record<string, any> = {
options: componentConfig,
properties: {
props: {
Expand Down Expand Up @@ -200,5 +200,33 @@ export function createNativeComponentConfig (Component, react: typeof React, rea
}
}

// onShareAppMessage 和 onShareTimeline 一样,会影响小程序右上方按钮的选项,因此不能默认注册。
if (
Component.onShareAppMessage ||
Component.prototype?.onShareAppMessage ||
Component.enableShareAppMessage
) {
componentObj.methods.onShareAppMessage = function (options) {
const target = options?.target
if (target) {
const id = target.id
const element = document.getElementById(id)
if (element) {
target!.dataset = element.dataset
}
}
return safeExecute(this.compId, 'onShareAppMessage', options)
}
}
if (
Component.onShareTimeline ||
Component.prototype?.onShareTimeline ||
Component.enableShareTimeline
) {
componentObj.methods.onShareTimeline = function () {
return safeExecute(this.compId, 'onShareTimeline')
}
}

return componentObj
}

0 comments on commit 7c2ce64

Please sign in to comment.