我正在使用React-native- dropdown -picker,但是我无法从下拉列表中选择任何项目,这些项目正被下面的视图覆盖。我尝试添加position:'absolute,zIndex:2,但项目列表仍然重叠,如下所示:

我已经编写了dropdown组件的代码,如下所示
return (
<View>
<View style={styles.container}>
{console.log('new array', dateArr)}
{console.log('arr', arr)}
<Icon
name="arrow-left"
size={20}
color="#fff"
style={{marginTop: 12}}
/>
{console.log('----------date', dateArr)}
{dateArr != null && (
<DropDownPicker
onValueChange={(value) => onValSelect(value)}
items={dateArr}
itemStyle={{
// justifyContent: 'flex-start',
flexDirection:'row'
}}
containerStyle={{height: 40,width:'80%',zIndex:2}}
/>
)}
</View>
<DaysInAWeek daysInAWeek={daysInAWeek} />
</View>
);
}
const styles = StyleSheet.create({
container: {
backgroundColor: '#FE017E',
// height: 56,
width: '100%',
flexDirection: 'row',
padding: 10,
},
});onValSelect()方法如下:
function onValSelect(val) {
if (val.length > 1) {
let arr = [];
for (let i = val[0]; i <= val[1]; i += 86400000) {
let date = getMonthDate(new Date(i));
arr.push(date);
}
console.log('final arr', arr);
setDaysInAWeek(arr);
} else {
console.log('single date', new Date(val));
setDaysInAWeek(new Date(val));
}
}请让我知道问题,任何帮助将不胜感激。
发布于 2021-02-06 21:28:04
如果有人仍然没有得到这个,这里我发现了一些东西这都是与父元素相关的,所以如果DropDownPicker组件没有一个具有一定高度的父元素,那么即使你看到了选项,这也不会让你选择。
只需给父元素minHeight:300px或任何你想要的高度示例-
<View style={{minHeight: 300}}>
<DropDownPicker
items={timeslots}
defaultValue={this.state.selected2}
containerStyle={{height: 40}}
style={{backgroundColor: '#fafafa'}}
itemStyle={{
justifyContent: 'flex-start',
}}
dropDownStyle={{backgroundColor: '#fafafa'}}
onChangeItem={(item) =>
this.setState({
selected2: item.value,
});
}
/>
</View>发布于 2021-09-01 06:01:23
我用这种方式解决了这个问题:
const [open, setOpen] = useState(false);
...
<View style={[style.viewContainer, Platform.OS === 'android' && open && style.androidContainer]}>
<DropDownPicker
open={open}
setOpen={setOpen}
...样式:
viewContainer: { marginHorizontal: 16, zIndex: 1 },
androidContainer: {
minHeight: 500,
marginBottom: -428,
},发布于 2020-11-25 15:21:27
cost dataArr=[
{label: 'USA', value: 'usa'},
{label: 'UK', value: 'uk' },
{label: 'France', value: 'france'},
];
<DropDownPicker
items={dataArr}
defaultValue="Select Country"
containerStyle={{height: 40}}
style={{backgroundColor: '#fafafa'}}
itemStyle={{
justifyContent: 'flex-start'
}}
dropDownStyle={{backgroundColor: '#fafafa'}}
onChangeItem={item => this.setState({
country: item.value
})}
/>我想问题出在你的商品风格上。您可以将伸缩方向更改为列吗?
https://stackoverflow.com/questions/64999714
复制相似问题