Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not open / close drawer with swipe gesture #7536

Closed
muraterd opened this issue Sep 17, 2019 · 31 comments
Closed

Can not open / close drawer with swipe gesture #7536

muraterd opened this issue Sep 17, 2019 · 31 comments

Comments

@muraterd
Copy link

I can open drawer with this.props.navigation.openDrawer() but can not open or close with swipe gesture. What am i doing wrong here?

App.js

import React from 'react';
import {Button} from 'react-native';

import {createDrawerNavigator} from 'react-navigation-drawer';
import {createAppContainer} from 'react-navigation';

class MyHomeScreen extends React.Component {
  render() {
    return (
      <>
        <Button
          onPress={() => this.props.navigation.navigate('Notifications')}
          title="Go to notifications"
        />

        <Button
          onPress={() => this.props.navigation.openDrawer()}
          title="Drawer"
        />
      </>
    );
  }
}

class MyNotificationsScreen extends React.Component {
  render() {
    return (
      <Button
        onPress={() => this.props.navigation.goBack()}
        title="Go back home"
      />
    );
  }
}

const MyDrawerNavigator = createDrawerNavigator(
  {
    Home: {
      screen: MyHomeScreen,
    },
    Notifications: {
      screen: MyNotificationsScreen,
    },
  },
  {
    drawerLockMode: 'unlocked',
  },
);

export default createAppContainer(MyDrawerNavigator);

dependencies

"dependencies": {
    "react": "16.8.1",
    "react-native": "0.61.0-rc.3",
    "react-native-gesture-handler": "^1.4.1",
    "react-native-reanimated": "^1.2.0",
    "react-native-screens": "^2.0.0-alpha.3",
    "react-navigation": "^4.0.5",
    "react-navigation-drawer": "^2.2.1",
    "react-navigation-stack": "^1.7.3"
  },

And i did the MainActivity setup

import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
...
...
...
@Override
  protected ReactActivityDelegate createReactActivityDelegate() {
    return new ReactActivityDelegate(this, getMainComponentName()) {
      @Override
      protected ReactRootView createRootView() {
      return new RNGestureHandlerEnabledRootView(MainActivity.this);
      }
    };
  }
@satya164
Copy link
Member

Can you downgrade to React Navigation 0.60 and try? I think there's some issue with 0.61 and gesture handler.

@MBach
Copy link

MBach commented Sep 24, 2019

@satya164 : same with react-Native: 0.60.5

@cayasso
Copy link

cayasso commented Sep 25, 2019

Same issue here, cant close drawer in Android! I am on 0.61

@satya164
Copy link
Member

It's fixed in facebook/react-native@9f0dede and will be released in a patch release of react-native 0.61

@netgfx
Copy link

netgfx commented Sep 27, 2019

still seeing the issue with react-native 0.61.1 and react-navigation 4.0.10

@devashishsethia
Copy link

Same issue here.
"react-navigation": "^4.0.10",
"react-native-gesture-handler": "^1.4.1",
"react-native": "0.61.2",

@davidcort
Copy link

Why this is closed? This error still seeing in "react-native": "0.61.2" and "react-native-gesture-handler": "^1.4.1".

Please, help us :(

@devashishsethia
Copy link

@davidcort I resolved the issue by following this : https://github.com/react-navigation/drawer/issues/105#issuecomment-534937151
You need to make changes to your MainActivity.java listed in the documentation for set up for RN version < 0.60. This has worked for me. Also, please test on a real device.

@davidcort
Copy link

@devashishsethia that patch exists in react-native 0.61.2. But the swipe on the drawer not works. :(

@davidcort
Copy link

davidcort commented Oct 10, 2019

I resolved !!!

in the index.js of your project:

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import { gestureHandlerRootHOC } from 'react-native-gesture-handler'

AppRegistry.registerComponent(appName, () => gestureHandlerRootHOC(App));

Works in debug, not testing in release mode.

@davidcort
Copy link

Confirm. In realease mode, works like a charm. 👍

@sjonchhe
Copy link

Problem still exists on 0.61.2..

@Zeeshan666
Copy link

Zeeshan666 commented Nov 11, 2019

try this one its worked in 0.61.4 or higher...
import {gestureHandlerRootHOC} from 'react-native-gesture-handler';
AppRegistry.registerComponent(appName, () => gestureHandlerRootHOC(App));

@du-hernandez
Copy link

I had the same problem and solved it by importing react-native-gesture-handler in the root of the project:

import 'react-native-gesture-handler';

@ghost
Copy link

ghost commented Nov 20, 2019

In Android, you can fix it by updating the MainActivity.java file.

package com.example;

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 {

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "Example";
    }
     @Override
  protected ReactActivityDelegate createReactActivityDelegate() {
    return new ReactActivityDelegate(this, getMainComponentName()) {
     @Override
      protected ReactRootView createRootView() {
      return new RNGestureHandlerEnabledRootView(MainActivity.this);
     }
   };
 }
}

@jordaofs
Copy link

jordaofs commented Dec 6, 2019

In Android, you can fix it by updating the MainActivity.java file.

package com.example;

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 {

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "Example";
    }
     @Override
  protected ReactActivityDelegate createReactActivityDelegate() {
    return new ReactActivityDelegate(this, getMainComponentName()) {
     @Override
      protected ReactRootView createRootView() {
      return new RNGestureHandlerEnabledRootView(MainActivity.this);
     }
   };
 }
}

This solve the problem on android, but sometimes it is also necessary to do react-native link to make it work!

@zenandre
Copy link

@davidcort TKS .. :)

@phanvankhaicd
Copy link

I resolved !!!

in the index.js of your project:

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import { gestureHandlerRootHOC } from 'react-native-gesture-handler'

AppRegistry.registerComponent(appName, () => gestureHandlerRootHOC(App));

Works in debug, not testing in release mode.

Thanks

@zeeshanaligold
Copy link

zeeshanaligold commented Dec 26, 2019

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import { gestureHandlerRootHOC } from 'react-native-gesture-handler'

AppRegistry.registerComponent(appName, () => gestureHandlerRootHOC(App));

Working. Thanks

@waqaramjad
Copy link

I resolved !!!

in the index.js of your project:

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import { gestureHandlerRootHOC } from 'react-native-gesture-handler'

AppRegistry.registerComponent(appName, () => gestureHandlerRootHOC(App));

Works in debug, not testing in release mode.

my application after applying that , when i touch any thing app crash

@davidcort
Copy link

I resolved !!!
in the index.js of your project:

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import { gestureHandlerRootHOC } from 'react-native-gesture-handler'

AppRegistry.registerComponent(appName, () => gestureHandlerRootHOC(App));

Works in debug, not testing in release mode.

my application after applying that , when i touch any thing app crash

What version of RN and React Navigation are you using?

@shubhamkakkar
Copy link

I resolved !!!
in the index.js of your project:

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import { gestureHandlerRootHOC } from 'react-native-gesture-handler'

AppRegistry.registerComponent(appName, () => gestureHandlerRootHOC(App));

Works in debug, not testing in release mode.

my application after applying that , when i touch any thing app crash

What version of RN and React Navigation are you using?
"react-native": "0.61.5", "react-native-gesture-handler": "^1.5.2", "react-navigation": "^4.0.10", "react-navigation-drawer": "^2.3.3",

@davidcort
Copy link

I resolved !!!
in the index.js of your project:

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import { gestureHandlerRootHOC } from 'react-native-gesture-handler'

AppRegistry.registerComponent(appName, () => gestureHandlerRootHOC(App));

Works in debug, not testing in release mode.

my application after applying that , when i touch any thing app crash

What version of RN and React Navigation are you using?
"react-native": "0.61.5", "react-native-gesture-handler": "^1.5.2", "react-navigation": "^4.0.10", "react-navigation-drawer": "^2.3.3",

Is very extrange, in Android works very well for me, in iOS you should change the next:
import { gestureHandlerRootHOC } from 'react-native-gesture-handler' in the first line in the index.js file.

@s3f4
Copy link

s3f4 commented Jan 15, 2020

I resolved !!!
in the index.js of your project:

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import { gestureHandlerRootHOC } from 'react-native-gesture-handler'

AppRegistry.registerComponent(appName, () => gestureHandlerRootHOC(App));

Works in debug, not testing in release mode.

my application after applying that , when i touch any thing app crash

same.

Solution:
"react-native-reanimated": "1.4.0"
I was using 1.5.0, Downgrading worked on me. And to add gestureHandlerRootHOC is not necessary.

index.js

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';

AppRegistry.registerComponent(appName, () => App);

@satya164 satya164 transferred this issue from react-navigation/drawer Feb 25, 2020
@Maskedman99
Copy link

react native: 0.62.2
react-native-gesture-handler: 1.6.1
This Issue is still present. #7536 (comment) workaround works.
This should be mentioned in the docs of RNGesturehandler's Drawer Layout https://docs.swmansion.com/react-native-gesture-handler/docs/component-drawer-layout.html

@sleez007
Copy link

I am also having this issue on rn 0.63.3. Gesture doesn't work on Android

@sandipbiswasbehala
Copy link

I am also having this issue on react-native: 0.63.4. Gesture doesn't work on Android.

@sandipbiswasbehala
Copy link

sandipbiswasbehala commented Feb 10, 2021

@sleez007

Solution Found and Working in Android (by following https://docs.swmansion.com/react-native-gesture-handler/docs/#android)

Update your MainActivity.java file

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 "Example";
    }

  • @OverRide

  • protected ReactActivityDelegate createReactActivityDelegate() {

  • return new ReactActivityDelegate(this, getMainComponentName()) {

  •  @Override
    
  •  protected ReactRootView createRootView() {
    
  •   return new RNGestureHandlerEnabledRootView(MainActivity.this);
    
  •  }
    
  • };

  • }
    }

  • ---> need to add

For React Native 0.61 or greater, add the library as the first import in your index.js file:

import 'react-native-gesture-handler';

Before running apps--- clean using gradlew clean command .

then npx react-native run-android.

Just tested.

@parnekov
Copy link

parnekov commented Jun 27, 2021

I had the same problem and solved it by importing react-native-gesture-handler in the root of the project:

import 'react-native-gesture-handler';

Works fine on iOS and Android. Thank you.

@github-actions
Copy link

Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro.

@MihirSvr
Copy link

I resolved !!!

in the index.js of your project:

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import { gestureHandlerRootHOC } from 'react-native-gesture-handler'

AppRegistry.registerComponent(appName, () => gestureHandlerRootHOC(App));

Works in debug, not testing in release mode.

not worked for me 🙃.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests