我不知道为什么不起作用
每当我向返回部分添加旋转木马时,它都会显示一个错误,即删除了ViewProptypes。
我得到了以下错误:
ERROR Invariant Violation: ViewPropTypes has been removed from React Native. Migrate to ViewPropTypes exported from 'deprecated-react-native-prop-types'.
ERROR Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.以下是代码:
import React, { useContext, useState } from "react";
import {
Dimensions,
Text,
View,
StyleSheet,
TouchableOpacity,
} from "react-native";
import { NewsContext } from '../API/context'
import SingleNews from "../components/SingleNews";
import Carousel from "react-native-snap-carousel";
const NewsScreen = () => {
const {
news: { articles }
} = useContext(NewsContext);
const [activeIndex, setActiveIndex] = useState();
const windowHeight = Dimensions.get("window").height;
return (
<View style={styles.carousel}>
{articles && (
<Carousel
layout={"stack"}
data={articles.slice(0, 10)}
sliderHeight={300}
itemHeight={windowHeight}
vertical={true}
renderItem={({ item, index }) => (
<SingleNews item={item} index={index} />
)}
onSnapToItem={(index) => setActiveIndex(index)}
/>
)}
</View>
);
};
export default NewsScreen;
const styles = StyleSheet.create({
carousel: {
flex: 1,
backgroundColor: "black",
},
text:{
color: "white",
fontSize: 20,
}
});package.json devDependencies:
"dependencies": {
"@expo/vector-icons": "^13.0.0",
"@types/react-native-snap-carousel": "^3.8.5",
"axios": "^0.27.2",
"expo": "~46.0.9",
"expo-status-bar": "~1.4.0",
"react": "18.0.0",
"react-native": "0.69.5",
"react-native-pager-view": "5.4.24",
"react-native-snap-carousel": "^3.9.1",
"react-native-tab-view": "^3.1.1"
}谁来帮帮我!!另外,我没有发现任何其他原因造成这一错误
发布于 2022-09-07 22:16:54
react-native-snap-carousel是非常不受欢迎的,并且有很多问题。你应该试试反应-原生-再生-旋转木马,这是当今的发展方向。它解决了react-native-snap-carousel所存在的所有问题,并使用反应本土化来提高性能(通过在UI线程上运行动画,而不是在JS线程上运行动画)
https://stackoverflow.com/questions/73637193
复制相似问题