react-native-dropdown-picker: Problem with the zIndex where my picker goes under below Views
Hi everyone. Sorry if this has already been asked but I couldn’t find a working solution. So My code is this:
<View style={styles.oddsSelectorContainer}> <Text style={styles.oddsShownLabel}>ODDS SHOWN</Text> <View style={{ ...(Platform.OS !== 'android' && { zIndex: 10, }), }} > <DropDownPicker items={[ { label: 'UK', value: 'uk', icon: () => <Icon name="flag" size={18} color="#900" /> }, { label: 'France', value: 'france', icon: () => <Icon name="flag" size={18} color="#900" /> }, ]} defaultValue={this.state.country} style={{ backgroundColor: '#fafafa', width: 174 }} itemStyle={{ justifyContent: 'flex-start', }} dropDownStyle={{ backgroundColor: '#fafafa' }} onChangeItem={(item) => this.setState({ country: item.value, })} /> </View> </View>
And the picker still goes under the views which are under it. Tried to increase the wrapping View zIndex also added zIndex to teh Dropdown picker but nothing seems to work for me. Thanks in advance. 😃. If more information is needed I will add it.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 19
worked for me 👍
Hi everyone. Thanks all for the help. Let me share what I found out and how I managed to fix my problem. So I managed to rework my component. Initially I had a component with Flatlist which Flatlist had ListHeaderComponent and all of the content that had to be rendered above the items, so basically the whole screen was a flatlist 😄. And I managed to make it work on iOS with the zIndex in ListHeaderComponentStyle of the Flatlist, but the only way to show the dropdown above the items on Android was to use elevation, which elevation was simply making the dropdown not touchable. The solution was to remove the ListHeaderComponent from the Flatlist and to put the header in separate function which I called above the Flatlist (of course you can put the content of the ListHeaderComponent in separate component, function or just in a View or Fragment above the Flatlist). That way it just worked as it should on Android with no workarounds and hacks, the only thing I needed to add was:
SO the dropdown goes above the items of the Flatlist in iOS also. Only the check is needed because otherwise on Android the dropdown becomes untouchable again. I added the View that way ->
I will close the issue, if anyone had same problems feel free to reopen it and I will try to help 😃
This works fine for iOS but not for Android yet
For anyone still facing this issue here is the best solution that works for both IOS and Android : https://github.com/hoaphantn7604/react-native-element-dropdown
I tried so many package but this is by far the best one and it’s so customizable and easy to use. i wish i found this early when i started working on my project. Thank me later.
This issue should not be closed. The solutions provided are all hack that does not always work. It only work if the first opens down and the second opens up. Not reliable.
So what I managed to achieve is to fix the problem on iOS. Since my dropdown picker is used in Flatlist’s ListHeaderComponent I added to the flatlist also ListHeaderComponentStyle={{zIndex: 10}} and from then it seemed to work fine but only on iOS. Today I faced the same issue (the dropdown goes under the below Views on Android ) and the best I managed to do so far is to make the dropdown to go over everything as it should be, but unfortunately it is not clickable. The only way worked for me was to add these lines of code to the flatlist
So now the dropdown is on the top of the world but not clickable 😄 … Is there any way for the dropdown to remain where it is and to appear on the top but to be clickable. I know that the elevation makes the dropdown untouchable but just could seem to find another way. Thanks in advance guys.
Thank you! I had issue with Dropdown options not appearing in FlatList. Adding
ListHeaderComponentStyle={{zIndex: 10}}
fixed the issue.This was my solution. Considerations :
zIndex
property is for IOS andelevate
for Android.elevate
property - only for Android. In my case, the problem was that on a few screens the next element had theelevate
propertyFor IOS
For Android
Solution 1 - Use
elevate
property on parent’s dropdownSolution 2 - Use
minHeight
property on parent’s dropdown with positionabsolute
and your own needs (top,margin…)