Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reduce the duration for long press on TouchableHighlight in react native

Tags:

react-native

I have my touchable highlight with an onPress and an onLongPress. They both work as expected the problem is I want to reduce the duration the user has to hold the button before long press activates. Is there a way reduce how long the user has to hold the button for longpress?. Maybe some kind of overide?

<TouchableHighlight style={styles.square} onPress={this._onPressButton.bind(this,item)} onLongPress={this._onLongPressButton.bind(this,item)}>
   <View style={styles.button}>

   </View>
</TouchableHighlight>

Thanks in advance

like image 954
schylake Avatar asked Mar 15 '19 23:03

schylake


1 Answers

There is a prop that you can pass to TouchableHighlight1 called delayLongPress. You can read about it here.

Basically what it allows you to do is set, in milliseconds, how long until onLongPress is called.

From the documentation:

Delay in ms, from onPressIn, before onLongPress is called.

In the example below the duration has been set to 500ms.

<TouchableHighlight
  style={styles.square}
  onPress={this._onPressButton.bind(this, item)}
  onLongPress={this._onLongPressButton.bind(this, item)}
  delayLongPress={500}
>
  <View style={styles.button}>

  </View>
</TouchableHighlight>

1 Note that all Touchables have the props from TouchableWithoutFeedback. You can see the props for TouchableHightlighthere

like image 156
Andrew Avatar answered Jan 03 '23 00:01

Andrew