我正在使用 RN 库
react-native-dropdown-picker
但是当我用 ScrollView 包装这个组件时它返回一个警告
VirtualizedLists 永远不应该嵌套在具有相同方向的普通 ScrollViews 中,因为它会破坏窗口和其他功能 - 请改用另一个支持 VirtualizedList 的容器。
我尝试了几种解决方案,例如
nestedScrollEnabled
、vertical = true
、horizontal= true
,但没有一个对我有用,我也尝试过
LogBox.ignoreLogs(['VirtualizedLists should never be nested']);
此行可以删除警告但是当我尝试滚动 DropDownPicker 它不会滚动,
检查下面的代码,也许我的代码有问题..
<KeyboardAvoidingView
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
style={{flex: 1}}>
<ScrollView nestedScrollEnabled={true}>
<View style={{zIndex: 3, marginBottom: 20}}>
<Text style={{paddingLeft: 5, paddingBottom: 5}}>
Vehicle Type <Text style={{color: 'red'}}>*</Text>
</Text>
<DropDownPicker
open={state.open_vehicle_type}
value={state.vehicle_type}
scrollViewProps={{
decelerationRate: 'fast',
nestedScrollEnabled: true,
style: {
zIndex: 1222,
},
}}
items={[
{label: 'Car', value: 'Car'},
{label: 'Truck', value: 'Truck'},
{label: 'Van', value: 'Van'},
{label: 'Bike', value: 'Bike'},
]}
placeholder="vehicle type"
placeholderStyle={{color: color_theme.black_20}}
onClose={() => setState({open_vehicle_type: false})}
setOpen={() => setState({open_vehicle_type: true})}
closeAfterSelecting={true}
setValue={value => {
setState({
vehicle_type: value(state.vehicle_type),
});
}}
style={{
borderColor: color_theme.black_20,
backgroundColor: color_theme.white,
}}
dropDownContainerStyle={{
borderColor: color_theme.black_20,
backgroundColor: color_theme.white,
}}
multiple={false}
mode="BADGE"
/>
</View>
</ScrollView>
</KeyboardAvoidingView>
我有多个字段,所以可能需要 ScrollView ..