我使用 react-native-dropdown-picker 来显示基于按钮单击的多个下拉列表。下拉菜单显示为覆盖在另一个组件上,我无法选择项目。任何人都可以帮助解决问题?
示例代码:
import * as React from 'react';
import {View, Text, ScrollView, StyleSheet} from 'react-native';
import DropDownPicker from 'react-native-dropdown-picker';
import {Button, Card} from 'react-native-paper';
//import Constants from 'expo-constants';
// You can import from local files
//import AssetExample from './components/AssetExample';
// or any pure javascript modules available in npm
//import { Card } from 'react-native-paper';
export default function App() {
const [myArray, setMyArray] = React.useState([]);
const [open, setOpen] = React.useState(false);
const [value, setValue] = React.useState(null);
const [items, setItems] = React.useState([
{label: 'Apple', value: 'apple'},
{label: 'Banana', value: 'banana'},
{label: 'Orange', value: 'orange'},
{label: 'Lemon', value: 'lemon'},
]);
const test = () => {
console.log('Function called');
setMyArray([{name: 'hello'}]);
};
return (
<View style={styles.container}>
<Button mode="contained">
Button 1
</Button>
<Text>Hello world</Text>
<Button mode="contained" >
Button 2
</Button>
<Text>Hello world</Text>
<Button mode="contained" >
Button 3
</Button>
<Text>Hello world</Text>
<Button mode="contained" onPress={() => test()} >
ADD DropDown
</Button>
{myArray.map((item, index) => {
return (
<Card key={index} style={{height: 40}}>
<DropDownPicker
dropDownDirection="TOP"
open={open}
value={value}
items={items}
setOpen={setOpen}
setValue={setValue}
setItems={setItems}
zIndex={3000}
zIndexInverse={1000}
containerStyle={{position: 'relative', width: '70%', left: '15%', paddingTop: 10}}
childrenContainerStyle={{
height: 1030,
}}
style={{
backgroundColor: '#fafafa',
zIndex: 10,
position: 'relative',
}}
itemStyle={{justifyContent: 'flex-start'}}
dropDownStyle={{backgroundColor: '#fafafa', height: 100}}
dropDownContainerStyle={{
backgroundColor: 'white',
zIndex: 1000,
elevation: 5000,
}}
/>
</Card>
);
})}
<Button mode="contained">
Button 4
</Button>
<Text>Hello world</Text>
<Button mode="contained" >
Button 5
</Button>
<Text>Hello world</Text>
<Button mode="contained" >
Button 6
</Button>
<Text>Hello world</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
textAlign: 'center',
},
});
预期:想要显示没有覆盖的下拉菜单,并且项目应该是可选的。