首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >反应-本机-液体-旋转木马不工作(不变的违规)

反应-本机-液体-旋转木马不工作(不变的违规)
EN

Stack Overflow用户
提问于 2022-09-07 14:25:21
回答 1查看 370关注 0票数 1

我不知道为什么不起作用

每当我向返回部分添加旋转木马时,它都会显示一个错误,即删除了ViewProptypes。

我得到了以下错误:

代码语言:javascript
复制
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.

以下是代码:

代码语言:javascript
复制
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:

代码语言:javascript
复制
  "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"
  }

谁来帮帮我!!另外,我没有发现任何其他原因造成这一错误

EN

回答 1

Stack Overflow用户

发布于 2022-09-07 22:16:54

react-native-snap-carousel是非常不受欢迎的,并且有很多问题。你应该试试反应-原生-再生-旋转木马,这是当今的发展方向。它解决了react-native-snap-carousel所存在的所有问题,并使用反应本土化来提高性能(通过在UI线程上运行动画,而不是在JS线程上运行动画)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73637193

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档