schylake
schylake

Reputation: 444

Reduce the duration for long press on TouchableHighlight in 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

Upvotes: 11

Views: 9482

Answers (1)

Andrew
Andrew

Reputation: 28539

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

Upvotes: 22

Related Questions