安装组件
yarn add react-native-wheel-picker-android
我这里的版本为"react-native-wheel-picker-android": "^2.0.6",
示例代码
import { useState } from 'react'
import { View } from 'react-native'
import { WheelPicker } from 'react-native-wheel-picker-android'const MyPicker = () => {const [selectedMinute, setSelectedMinute] = useState(0) // 这个是默认显示的数据的索引号const wheelPickerData = ['2组', '3组', '4组', '5组', '6组', '7组', '8组', '9组', '10组'] // 这个是滚动的数据const onItemSelected = aa => {console.log('selectedItem', aa) // 这个是选择的元素的索引号}return (<View style={{ height: '100%', flexDirection: 'row', justifyContent: 'center', alignItems: 'center' }}><WheelPickerselectedItem={selectedMinute}data={wheelPickerData}onItemSelected={onItemSelected}initPosition={1}itemTextSize={16}selectedItemTextSize={18}indicatorColor="#EEEEEE"indicatorWidth={0.5}/></View>)
}export default MyPicker
效果图