我想通过PanResponder处理React Native中的长按操作。经过一次体面的搜索后,我无法找到如何做到“正确的方式”,所以我在这里问。这个想法是在检测到屏幕上长按(点击)时执行代码。 我已经长到了这样的事情:如何处理PanResponder长按事件?
handlePanResponderGrant(e, gestureState){
// On the press of the button set a timeout
myVar = setTimeout(this.MyExecutableFunction(), LONG_PRESS_MIN_DURATION);
}
handlePanResponderRelease(e, gestureState) {
// Clear the timeout if the press is released earlier than the set duration
clearTimeout(myVar);
}
这是处理长按正确的方式还是有更好的办法?
'this.MyExecutableFunction()未测试'必须是'this.MyExecutableFunction'和'clearTimeout(myVar的)'具有在'handlePanResponderTerminate'以及执行,确保在按下终止后,应用程序不会将其计为长按。 –