我想通過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'以及執行,確保在按下終止後,應用程序不會將其計爲長按。 –