Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continuously increasing counter with long press React Native

I have a button next to a TextInput that increases its counter when pressed.

   <TouchableWithoutFeedback onPress={() => {this.increaseAmount(step, rowID)}}>
      <View style={styles.amountPlusButtonContainer}>
        <Text style={styles.amountButtonText}>+</Text>
      </View>
    </TouchableWithoutFeedback>

It currently increases by 1 each time I tap the button. What I want to achieve is to keep increasing the counter for as long as the user is pressing it.

I have tried to use setInterval() but I don't know exactly when to stop it nor if it's the right approach to this problem.

like image 435
rikesan Avatar asked Jul 12 '16 16:07

rikesan


1 Answers

I think to use setInterval is a good solution. Call setInterval on onPressIn and clearInterval on onPressOut.

like image 101
Headless Avatar answered Oct 13 '22 02:10

Headless