React-native-gesture-handler swipeable 在 Android 上不起作用

i*_*sis 6 android gesture react-native

这是我的代码。

应用程序.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;
Run Code Online (Sandbox Code Playgroud)

这是我的 MainActivity.java,如包所示。

package com.project;

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

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

我不明白发生了什么事,但这有点令人沮丧。有谁知道该怎么做吗?我的代码是我找到的教程的精确副本,所以我希望它能够工作。唯一的区别是我的项目使用react-native,而教程使用expo。

小智 2

使用 FlatList 而不是 map,因为react-native-gesture-handler 支持列表组件。