Skip to content

Commit

Permalink
feat:兼容harmony PanResponder事件戳
Browse files Browse the repository at this point in the history
  • Loading branch information
jumiao authored and zhiqingchen committed Apr 2, 2024
1 parent 5898e1a commit 0bafa3c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/taro-components-rn/src/components/hooks/useClickable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from 'react'

import {
GestureResponderEvent,
GestureResponderHandlers, PanResponder
GestureResponderHandlers, PanResponder, Platform
} from 'react-native'
import { omit } from '../../utils'

Expand Down Expand Up @@ -152,10 +152,19 @@ const useClickable = (props: any) => {
const { onClick, onLongPress, onTouchEnd } = ref.current.props
onTouchEnd && onTouchEnd(getWxAppEvent(evt))
const endTimestamp = evt.nativeEvent.timestamp
const gapTime = endTimestamp - ref.current.startTimestamp
let gapTime = endTimestamp - ref.current.startTimestamp
// 1 =>3, 修复部分android机型(三星折叠屏尤为明显),单击时dx,dy为>1,而被误判为move的情况。
const hasMove = Math.abs(gestureState.dx) >= 3 || Math.abs(gestureState.dy) >= 3
if (!hasMove) {
if (Platform.OS === 'harmony') {
let ms = Math.floor(gapTime / 1000);
if (ms > 0) { // 这种情况是 1000毫秒以上 || 单位小于毫秒的情况
let us = Math.floor(ms / 1000);
if (us > 0 || ms > 10) { // 防止以后系统升级改成毫秒后的容错处理
gapTime = ms;
}
}
}
if (gapTime <= 350) {
onClick && onClick(getWxAppEvent(evt))
} else {
Expand Down

0 comments on commit 0bafa3c

Please sign in to comment.