showing results for - "prevent double tap in react native"
Constance
10 Jan 2017
1import debounce from 'lodash.debounce'; // 4.0.8
2
3const withPreventDoubleClick = (WrappedComponent) => {
4
5  class PreventDoubleClick extends React.PureComponent {
6
7    debouncedOnPress = () => {
8      this.props.onPress && this.props.onPress();
9    }
10
11    onPress = debounce(this.debouncedOnPress, 300, { leading: true, trailing: false });
12
13    render() {
14      return <WrappedComponent {...this.props} onPress={this.onPress} />;
15    }
16  }
17
18  PreventDoubleClick.displayName = `withPreventDoubleClick(${WrappedComponent.displayName ||WrappedComponent.name})`
19  return PreventDoubleClick;
20}