fes
fes

Reputation: 2515

React Native - Android - Prevent multiple taps/onclick

Is there anyway to prevent a button from being tapped multiple times?

A TouchableHighlight or a Button can be pressed/tapped multiple times even before a View appears. Therefore instead of showing one screen, you get X amount of screens stacked on top of each other. Is there anyway to delay or disable the button or something to prevent this from happening?

This happens for navigation, all TouchableHighlight and Button options.

You can't really use setState as its async so you can't disable something straight away. Surely others have encountered this issue in RN Android at least, especially when its laggy.

Upvotes: 3

Views: 3389

Answers (1)

Hariks
Hariks

Reputation: 1889

There seems to be a disabled props for Touchable Components for newer versions of RN.

<TouchableHighlight 
ref = {button => this.button = button}
onPress={() => {
  this.button.disabled = {true};
 // What you want to do on button click here
}}/> 

Upvotes: 2

Related Questions