Skip to content

Commit

Permalink
fix(shared/react/runtime): 修复 map 组件
Browse files Browse the repository at this point in the history
* 在微信中 Map 组件 setting 属性还是要用 [] 做默认值,用 {} 会报错
* 可以绑定 onRegionChange
  • Loading branch information
Chen-jj committed Oct 21, 2020
1 parent e411159 commit 0537c9d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
11 changes: 9 additions & 2 deletions packages/shared/src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,22 @@ const Map = {
'enable-rotate': 'false',
'enable-satellite': 'false',
'enable-traffic': 'false',
setting: '{}',
bindMarkerTap: '',
bindLabelTap: '',
bindControlTap: '',
bindCalloutTap: '',
bindUpdated: '',
bindRegionChange: '',
bindPoiTap: '',
...touchEvents
...touchEvents,
...selectEnv({
alipay: {
setting: '{}'
},
default: {
setting: '[]'
}
})
}

const Progress = {
Expand Down
7 changes: 6 additions & 1 deletion packages/taro-react/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ function setEvent (dom: TaroElement, name: string, value: unknown, oldValue?: un
if (!oldValue) {
dom.addEventListener(eventName, eventProxy, isCapture)
}
dom.__handlers[eventName][0] = value
if (eventName === 'regionchange') {
dom.__handlers.begin[0] = value
dom.__handlers.end[0] = value
} else {
dom.__handlers[eventName][0] = value
}
} else {
dom.removeEventListener(eventName, eventProxy)
}
Expand Down
7 changes: 6 additions & 1 deletion packages/taro-runtime/src/dom/event_target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ export class TaroEventTarget {
public __handlers: Record<string, EventHandler[]> = {}

public addEventListener (type: string, handler: EventHandler, options?: boolean | AddEventListenerOptions) {
warn(type === 'regionchange', 'map 组件的 regionchange 事件非常特殊,请使用 begin/end 事件替代。详情:https://github.com/NervJS/taro/issues/5766')
if (type === 'regionchange') {
// map 组件的 regionchange 事件非常特殊,详情:https://github.com/NervJS/taro/issues/5766
this.addEventListener('begin', handler, options)
this.addEventListener('end', handler, options)
return
}
type = type.toLowerCase()
const handlers = this.__handlers[type]
let isCapture = Boolean(options)
Expand Down

0 comments on commit 0537c9d

Please sign in to comment.