react-native-gesture-handler: RectButton onPress does not work

Hi,

RectButton’s onPress doesn’t work. I’m using React Native 0.60.4 inside of a Styled Component:

export const Hour = styled(RectButton)`
  background: #fff;
  padding: 20px;
  flex: 1;
  opacity: ${props => (props.enabled ? 1 : 0.7)};
  align-items: center;
  margin: 0 10px 20px;
`

I’ve tried running jestify, a manual React Native link despite the recommendations, cleaning cache but nothing works. It decided not to work for NOTHING.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 7
  • Comments: 20 (1 by maintainers)

Most upvoted comments

Screen Shot 2019-08-08 at 12 35 48 PM Make sure you followed this insctructions

image Resolved for me. In my case, I forgot to pass spreading props… Diego`s code! Rocketseat…rs I also copied them

UPDATE 2022-08-17

Documentation changed and the installation is now more easier the ever. Take a look at the docs:

https://docs.swmansion.com/react-native-gesture-handler/docs/next/installation/#js

Resume:

install the lib yarn add react-native-gesture-handler

After installation, wrap your entry point with <GestureHandlerRootView> or gestureHandlerRootHOC

export default function App() { return <GestureHandlerRootView style={{ flex: 1 }}>{/* content */}</GestureHandlerRootView>; }

image

you need adjust of this way, involving with GestureHandlerRootView

Screen Shot 2019-08-08 at 12 35 48 PM Make sure you followed this insctructions

just add in your MainActivity.java

at the imports

import com.facebook.react.ReactActivityDelegate;
import com.facebook. react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;

and at the final

  @Override
  protected ReactActivityDelegate createReactActivityDelegate() {
    return new ReactActivityDelegate(this, getMainComponentName ()) {
    @Override
    protected ReactRootView createRootView() {
    return new RNGestureHandlerEnabledRootView (MainActivity. this);
      }
    };
  }

it’ll look like this

import android.os.Bundle;
import com.facebook.react.ReactActivity;

import com.facebook.react.ReactActivityDelegate;
import com.facebook. react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;

public class MainActivity extends ReactActivity {
  @Override
  protected String getMainComponentName() {
    return "applicationName";
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(null);
  }

  @Override
  protected ReactActivityDelegate createReactActivityDelegate() {
    return new ReactActivityDelegate(this, getMainComponentName ()) {
    @Override
    protected ReactRootView createRootView() {
    return new RNGestureHandlerEnabledRootView (MainActivity. this);
      }
    };
  }
}

Be sure to follow complete setup steps for react-native-gesture-handler, including wrapping your root component in <GestureHandlerRootView>

Screen Shot 2019-08-08 at 12 35 48 PM Make sure you followed this insctructions

Thank you, its working now!! That’s what we got when do not read the docs rsrsrs