React Native的ViewPager给出错误:: :: ViewPagerAndroid已从React Native移除

时间:2020-03-30 09:44:15

标签: react-native android-viewpager2

我正在尝试在React Native上使用View Pager,并且正在使用参考链接寻求帮助 https://reactnativecode.com/create-viewpager-with-tab-title-dot-indicators/?unapproved=42387&moderation-hash=570c68d8ea5535b832994536ba239b28#comment-42387

按原样使用代码并运行时,它会显示错误-

ViewPagerAndroid has been removed from React Native. It can now be installed and imported from 'react-native-viewpager' instead of 'react-native'. 

我想念什么?

1 个答案:

答案 0 :(得分:0)

yarn add @react-native-community/viewpager

npm -i @react-native-community/viewpager --save

要进行链接,请使用以下命令

react-native link @react-native-community/viewpager

在较新版本的React Native ViewPager中不可用,因此您必须手动添加

然后,您可以像这样导入它

import ViewPager from '@react-native-community/viewpager';