Home > Enterprise >  Why my gestureDetector not working if I press?
Why my gestureDetector not working if I press?

Time:03-22

I want to use GestureDetector but I dont get a console.log statement if I press the button.

Button.tsx

const Button = ({ children }: IButton) => {
  const gestureHandler = Gesture.Tap()
    .onStart(() => console.log('HI'))
  return (
    <GestureDetector gesture={gestureHandler}>
      <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
      { children }
      </View>
    </GestureDetector>
  )
};

App.tsx

export default function App() {
  return (
    <GestureHandlerRootView style={s.container}>
      <Button>
        <Text>Button</Text>
      </Button>
    </GestureHandlerRootView>
  );
}

What I am doing wrong ?

CodePudding user response:

For most use cases, and especially for beginners, it is probably best to use the Pressable react-native API. It's a native solution that doesn't require additional libraries and it is more than sufficient for most button use cases. It is also probably faster than an external library.

For more information - reactnative.dev/docs/pressable

  • Related