我想向我的应用添加滑动删除效果,并且我已手动安装了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/