import { Component } from 'react' ; import { GestureResponderEvent , TouchableWithoutFeedbackProperties } from 'react-native' ; const kOnPressDelayMS = 200 ; export abstract class TouchableDelay < P extends TouchableWithoutFeedbackProperties > extends Component < P > { private onPressDelayTimer : ReturnType < typeof setTimeout > | null = null ; componentWillUnmount ( ) { window . removeEventListener ( 'scroll' , this . handleScroll ) ; } handleScroll = ( event ) => { if ( this . onPressDelayTimer ) { clearTimeout ( this . onPressDelayTimer ) ; this . onPressDelayTimer = null ; window . removeEventListener ( 'scroll' , this . handleScroll ) ; } } ; handleOnPress = ( event ) : void => { const { onPress } = this . props ; if ( onPress ) { if ( ! this . onPressDelayTimer ) { window . addEventListener ( 'scroll' , this . handleScroll ) ; this . onPressDelayTimer = setTimeout ( ( ) => { this . onPressDelayTimer = null ; window . removeEventListener ( 'scroll' , this . handleScroll ) ; return onPress ( event ) ; } , kOnPressDelayMS ) ; } event . preventDefault ( ) ; } } ; }