React native image slider box无法正常运行

4bbkushb  于 2023-10-22  发布在  React
关注(0)|答案(1)|浏览(122)
import { SliderBox } from "react-native-image-slider-box";

Uncaught TypeError: Cannot read properties of undefined (reading 'style')
at ./node_modules/react-native-snap-carousel/src/carousel/Carousel.js

我试图在react本机应用程序中使用图像滑块框,我不明白错误是什么意思。我已经安装了软件包,但无法正常工作。

yacmzcpb

yacmzcpb1#

你需要更新插件在这里,但不要担心,我会指导你如何

第一步
**1)**按照说明将patch package安装到项目中。
**2)**通过运行npm install deprecated-react-native-prop-types或yarn add deprecated-react-native-prop-types安装deprecated-react-native-prop-types。
第二步

更新Carousel.js,从react-native中删除ViewPropTypes,并更新样式
./node_modules/react-native-snap-carousel/src/carousel/Carousel.js

+ import { ViewPropTypes } from 'deprecated-react-native-prop-types' 
- import { ViewPropTypes } from 'react-native'; 


-   slideStyle: ViewPropTypes ? ViewPropTypes.style : View.propTypes.style,
-   containerCustomStyle: ViewPropTypes ? ViewPropTypes.style : View.propTypes.style,
-   contentContainerCustomStyle: ViewPropTypes ? ViewPropTypes.style : View.propTypes.style,
    
    
+   containerCustomStyle:  ViewPropTypes?.style ?? View.propTypes?.style,
+   slideStyle: ViewPropTypes?.style ?? View.propTypes?.style ,
+   contentContainerCustomStyle:  ViewPropTypes?.style ?? View.propTypes?.style,


Step 3

In package.json

 "scripts": {
   + "patch": "npx patch-package",
   + "postinstall": "patch-package"
  }

运行below命令

npx patch-package react-native-snap-carousel

相关问题