software-mansion / react-native-gesture-handler

Declarative API exposing platform native touch and gesture system to React Native.
https://docs.swmansion.com/react-native-gesture-handler/
MIT License
5.85k stars 954 forks source link

Swipeable is not working on android #725

Closed JohnGkouziotis closed 3 years ago

JohnGkouziotis commented 4 years ago

So i'm trying to use the Swipeable component from react-native-gesture-handler. The thing is that it does nothing. Below is my code

App.js

import Swipeable from 'react-native-gesture-handler/Swipeable';

const RightActions = () => {
  return (
    <TouchableOpacity onPress={() => console.warn('works'))}>
      <Icon name="md-trash" size={18} color={Colors.red} />
    </TouchableOpacity>
  );
};

const App = () => {
  return (
    <ScrollView>
    ...
      {Object.keys(data).map(key => {
        return (
          <Swipeable key={key} renderRightActions={RightActions}>
            <View>
              <Text>Swipe left</Text>
            </View>
          </Swipeable>
        );
      });
    </ScrollView>
  );
};

export default App;

And here is my MainActivity.java as it is suggested.

package com.assosfood;

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

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

This is all done with react-native not with expo. What am i doing wrong?

alz10 commented 4 years ago

react-navigation uses this library for their drawer navigation. We have the same similar problem. The problem happens in v0.60.4. What's your RN version by the way?

JohnGkouziotis commented 4 years ago

My version is v0. 60.4 as well. I thought I was doing something wrong.

Vijay-mRoads commented 4 years ago

Facing the same issue. My version is v0.60.4 as well

voxspox commented 4 years ago

+1

leabaertschi commented 4 years ago

Works for me with v0.60.5

josephmbeveridge commented 4 years ago

We are still having this issue on 0.61.0-rc2. Is this still one the radar for being fixed?

netgfx commented 4 years ago

Yes same issue here, local code doesn't work with react navigation drawer, but here with Expo it does https://snack.expo.io/@netgfx/auth-flow-v3 any ideas?

rkstar commented 4 years ago

apparently this was fixed in RN 0.61.1

juniorstreichan commented 4 years ago

I´m using inside the Flatlist component, it's ok

https://stackoverflow.com/questions/57428224/react-native-gesture-handler-swipeable-is-not-working-on-android

mnemanja commented 4 years ago

I can say that in RN 0.61.1 it still exists. The drawer opens, but it cannot be clicked away or swiped.

By the way, I'm not using Swipeable, but a regular createDrawerNavigator.

juniorstreichan commented 4 years ago

In version 4 of react-navigation, separate navigations

https://reactnavigation.org/docs/en/drawer-navigator.html#api

shhhiiiii commented 4 years ago

This helps me to make swipeable working. https://aboutreact.com/swipe-gestures-not-working-in-android/

lyair1 commented 4 years ago

You'll have to modify MainActivity.java:

Add:

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); } }; }

Yandamuri commented 4 years ago

@MariShielaFurio Worked this solution for me.......Thank You

EricLewe commented 3 years ago

For the ones using react-native-navigation (RNN). You should instead follow this part of the doc: https://software-mansion.github.io/react-native-gesture-handler/docs/getting-started.html#with-wix-react-native-navigation-https-githubcom-wix-react-native-navigation

jakub-gonet commented 3 years ago

Should be resolved.

being-yash-t commented 3 years ago

For the ones using react-native-navigation (RNN). You should instead follow this part of the doc: https://software-mansion.github.io/react-native-gesture-handler/docs/getting-started.html#with-wix-react-native-navigation-https-githubcom-wix-react-native-navigation

Amm, I am having the same issue. the gesture isn't working. Also, I am using react-navigation - native. New to react native, using Flat List. Need help

jakub-gonet commented 3 years ago

Try following installation instructions at updated link https://docs.swmansion.com/react-native-gesture-handler/docs

kalideir commented 3 years ago

This helps me to make swipeable working. https://aboutreact.com/swipe-gestures-not-working-in-android/

That was the solution in my case w/ Navigation 5. I noticed it worked after gradlew clean and then rebuild

zikyfranky commented 1 year ago

So I made use of RN FlatList

To get it working on Android, I just had to wrap FlatList with <GestureHandlerRootView>

Kotpes commented 1 year ago

So I made use of RN FlatList

To get it working on Android, I just had to wrap FlatList with <GestureHandlerRootView>

I've had a separate issue where Swipeable won't properly work. when inside of the renderItem of a FlatList, due to scroll kicking in and swipeable gesture is dropped. But this solution totally solved it! Thanks!