Skip to content

Commit c456bd7

Browse files
authored
Merge pull request #1970 from didi/refactor-rn-event-part
fix: 事件对象复用
2 parents 256c1f1 + cf84d48 commit c456bd7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/webpack-plugin/lib/runtime/components/react/getInnerListeners.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function handleEmitEvent (
114114
const { propsRef } = eventConfig
115115
const eventCfg = eventConfig[name]
116116
if (eventCfg) {
117-
if (eventCfg.hasCatch) {
117+
if (eventCfg.hasCatch && name !== 'tap' && name !== 'longpress') {
118118
e.stopPropagation()
119119
}
120120
eventCfg[type].forEach((event) => {
@@ -138,6 +138,8 @@ function checkIsNeedPress (e: ExtendedNativeTouchEvent, type: 'bubble' | 'captur
138138
}
139139

140140
function handleTouchstart (e: ExtendedNativeTouchEvent, type: EventType, eventConfig: EventConfig) {
141+
// 阻止事件被释放放回对象池,导致对象复用 _stoppedEventTypes 状态被保留
142+
e.persist()
141143
const { innerRef } = eventConfig
142144
globalEventState.needPress = true
143145
innerRef.current.mpxPressInfo.detail = {
@@ -155,7 +157,6 @@ function handleTouchstart (e: ExtendedNativeTouchEvent, type: EventType, eventCo
155157
e._stoppedEventTypes = e._stoppedEventTypes || new Set()
156158
e._stoppedEventTypes.add('longpress')
157159
}
158-
e.persist()
159160
innerRef.current.startTimer[type] && clearTimeout(innerRef.current.startTimer[type] as unknown as number)
160161
innerRef.current.startTimer[type] = setTimeout(() => {
161162
// 只要触发过longpress, 全局就不再触发tap

0 commit comments

Comments
 (0)