reactjs - React Native Dropdown Picker不要点击选项
问题描述
我是反应原生的新手。
我的问题很简单:我使用包 react-native-dropdown 选择器,但是当我打开下拉菜单时,我无法单击该选项,而是单击该选项下的头像。示例我想单击 Housing 并且它从 Yvonee 打开 Avatar 模式,而不是过滤类别。任何建议如何解决?这是我的代码:
<View style={[styles.filterCompany, Platform.OS !== 'android' ? { zIndex: 1 } : null]}>
<DropDownPicker
items={colleguesList}
open={showDropDown}
setOpen={() => setShowDropDown(!showDropDown)}
value={category}
setValue={value => setCategory(value)}
dropDownContainerStyle={{
width: 170,
alignSelf: 'center',
position: 'absolute',
top: 10,
borderColor: Colors.SBLighBlue,
backgroundColor: Colors.SBLighBlue
}}
textStyle={{
fontFamily: customFonts.medium,
color: Colors.SBWhite,
fontSize: 16,
justifyContent: 'center'
}}
labelStyle={{
fontWeight: 'bold',
color: Colors.SBWhite
}}
arrowIconStyle={{
tintColor: Colors.SBWhite
}}
tickIconStyle={{
tintColor: Colors.SBWhite
}}
listMode="SCROLLVIEW"
style={{
width: 170,
height: 40,
alignSelf: 'center',
marginTop: 10,
backgroundColor: Colors.SBLighBlue,
borderColor: Colors.SBLighBlue,
zIndex: 1
}}
/>
</View>
<View style={styles.listAvatar}>
解决方案
问题
您正在尝试以错误的方式更新showDropDown
变量。setShowDropDown
由于该setState
方法是异步操作,因此您将面临此问题。
解决方案
prevState
在方法的回调中使用setState
以正确更新showDropDown
:
<DropDownPicker
setOpen={() => setShowDropDown((prevState) => !prevState)}
// ...
/>
推荐阅读
- vue.js - 在同一个 div vue.js 中显示 2 个元素
- c - 为什么我在 C 中得到这个双重释放或损坏的回溯错误?
- latex - 当我使用 \begin {figure}[H] 时标题消失
- json - 使用python提取JSON数据并遇到keyerror
- javascript - 当模块是`npm link`时,Vue 3组件初始化不正确
- javascript - 将自定义滚动条 CSS 分配给 div 而不是 body
- python - Python Pandas:如何为删除的数据制作标签?
- angular - 如何从 Angular 中的 Route Guards 传递布尔参数
- android - 如何将 Android 设备用作 BLE(低功耗蓝牙)
- apache-flink - 如何在 Flink Web UI 中上传 python 文件?