Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-Native - call a function on swipe left/right

I am trying to use left/right swipe to call a function on my page - I cant see an obvious way to do this?

I assume there is built in functionality to detect these kinds of gestures and then call a predefined function?

I am trying to use this as a navigation gesture - and a left and right swipe will load a component passing in a date and loading data based on that date.

Please let know if anyone can help with this. Thanks

like image 680
Gotts Avatar asked Aug 11 '26 11:08

Gotts


1 Answers

I'll recommend this library as I don't know of any inbuilt function to achieve your need so easy. Swipe gestures

  <GestureRecognizer
    onSwipe={(direction, state) => this.onSwipe(direction, state)}
    onSwipeUp={(state) => this.onSwipeUp(state)}
    onSwipeDown={(state) => this.onSwipeDown(state)}
    onSwipeLeft={(state) => this.onSwipeLeft(state)}
    onSwipeRight={(state) => this.onSwipeRight(state)}
    config={config}
    style={{
      flex: 1,
      backgroundColor: this.state.backgroundColor
    }}
    >
    <Text>{this.state.myText}</Text>
    <Text>onSwipe callback received gesture: {this.state.gestureName}</Text>
  </GestureRecognizer>
like image 193
Chukwuemeka Maduekwe Avatar answered Aug 13 '26 01:08

Chukwuemeka Maduekwe