我希望当屏幕上有两次触摸时 panResponder 继续前进并且不停止但大约半秒后 panResponder 停止并开始滚动这是我的代码
import {View} from 'native-base';
import React, {Children, useMemo, useState} from 'react';
import {Animated, NativeTouchEvent, PanResponder} from 'react-native';
import {getDistance} from '../utils/functions';
interface Props {
opacity: Animated.Value;
}
const PinchZoom: React.FC<Props> = (props) => {
let initialXs: Array<number> = [];
let initialYs: Array<number> = [];
let currentXs: Array<number> = [];
let currentYs: Array<number> = [];
const resetAnimation = () => {
Animated.spring(props.opacity, {
toValue: props.opacity,
useNativeDriver: false,
}).start();
};
const panResponder = useMemo(
() =>
PanResponder.create({
onStartShouldSetPanResponder: (event) => {
let touches = event.nativeEvent.touches;
if (touches.length == 2) {
return true;
} else {
return false;
}
},
onPanResponderStart: (initial_event, initial_gesture) => {
let touches = initial_event.nativeEvent.touches;
if (touches.length == 2) {
initialXs = [];
initialYs = [];
initialXs.push(touches[0].locationX);
initialXs.push(touches[1].locationX);
initialYs.push(touches[0].locationY);
initialYs.push(touches[1].locationY);
}
},
onMoveShouldSetPanResponder: () => true,
onPanResponderMove: (event, gesture) => {
let touches = event.nativeEvent.touches;
if (touches.length == 2) {
currentXs = [];
currentYs = [];
currentXs.push(touches[0].locationX);
currentXs.push(touches[1].locationX);
currentYs.push(touches[0].locationY);
currentYs.push(touches[1].locationY);
}
console.log('Xs', initialXs, currentXs);
console.log('Ys', initialYs, currentYs);
},
onPanResponderRelease: (event, gesture) => {
let touches = event.nativeEvent.touches;
console.log('Xs', initialXs, currentXs);
console.log('Ys', initialYs, currentYs);
if (touches.length == 2) {
console.log('Xs', initialXs, currentXs);
console.log('Ys', initialYs, currentYs);
}
},
}),
[],
);
return (
<Animated.View {...panResponder.panHandlers}>
{props.children}
</Animated.View>
);
};
export default PinchZoom;
我想当屏幕上有两次触摸时 panResponder 开始,直到有两次触摸它继续,当有一次触摸它停止