javascript - 如何修复 React Native 中的 "Tried to register two views with the same name RNGestureHandlerButton"?

标签 javascript reactjs npm

我想向我的应用添加滑动删除效果,并且我已手动安装了react-native-gesture-handler。从那时起,我收到一条错误消息...我已经尝试卸载手动安装的手势处理程序,但没有成功。有什么建议吗?

这是我尝试测试手势处理程序的组件中的代码。从那时起,我只收到带有上述警告的红屏,并且无法再执行任何操作。 抱歉,我是初学者。

import React, { Component } from "react";
import {Image, StyleSheet, TouchableHighlight, View, Text} from "react-native";
import Swipeable from "react-native-gesture-handler/Swipeable";

renderLeftActions = (progress, dragX) => {
  const trans = dragX.interpolate({
    inputRange: [0, 50, 100, 101],
    outputRange: [-20, 0, 0, 1]
  });
  return (
    <RectButton style={styles.leftAction} onPress={this.close}>
      <Animated.Text
        style={[
          styles.actionText,
          {
            transform: [{ translateX: trans }]
          }
        ]}
      />
    </RectButton>
  );
};

getAllToppings = toppings => {
  return toppings.map(topping => (
    <Swipeable renderLeftActions={this.renderLeftActions}>
      <Text style={styles.toppings}>{topping}</Text>
    </Swipeable>
  ));
};

render() {
  const menuDish = this.props.navigation.getParam('menuDish');
  let toppings = [];
  for (let key in menuDish.toppings) {
    toppings.push(menuDish.toppings[key])
  }
  return(
    <View style={{alignItems: 'center'}}>
        <Image
            source={{url: menuDish.image}}
            style={styles.image}
        />
        <Text style={styles.dishName}>{menuDish.name}</Text>
        {this.getAllToppings(toppings)}
    </View>
  )
}

最佳答案

你能分享一下你的package.json吗?

无论如何,请尝试删除package.json/yarn.lock文件和node_modules文件夹并重新安装它们。

关于javascript - 如何修复 React Native 中的 "Tried to register two views with the same name RNGestureHandlerButton"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54361533/

相关文章:

node.js - 如何在本地执行npm模块?

javascript - 递归 setTimeout() 在后台暂停

JavaScript:需要查找给定字符串中多个子字符串中的哪一个已被选择(突出显示)

javascript - 以 block 的形式运行 HTTP 请求

javascript - 将事件选项卡事件传递给父组件和同级组件

javascript - 如何使用 React.js 中的 Fetch API 将数据发布到数据库

javascript - 如何在 nativescript 中使用 InAppBrowser

javascript - react 多个echarts调整大小不起作用

node.js - 如何在 npm 启动期间在 Project.js 中解析 'npm ERR! code ELIFECYCLE'

node.js - 生成 React 应用程序时使用不同的 NPM 版本