question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with the zIndex where my picker goes under below Views

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14

github_iconTop GitHub Comments

21reactions
crackerjackjay21commented, Feb 2, 2021
  <View style={{zIndex: 2000}}>
    <DropDownPicker />
  </View>
  <View style={{zIndex: 1000}}>
    <DropDownPicker />
  </View>
 </>

worked for me 👍

13reactions
petkovvcommented, Oct 23, 2020

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:

 <View style={{
                ...(Platform.OS !== 'android' && {
                    zIndex: 10,
                }),
            }}
            >

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 ->

...
 <View style={{
                ...(Platform.OS !== 'android' && {
                    zIndex: 10,
                }),
            }}
            >
   <BookmakerSelectionDropdown /> // That is my component which contains the dropdown
</View
....

I will close the issue, if anyone had same problems feel free to reopen it and I will try to help 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

React native - z-index in dropdown doesnt work - Stack Overflow
I think zIndex only applies to siblings... so the nested menu won't pop "out" over its parent's siblings using it. You could probably...
Read more >
4 reasons your z-index isn't working (and how to fix it)
It seems simple at first- a higher z-index number means the element will be on top of elements with lower z-index numbers.
Read more >
z-index - CSS: Cascading Style Sheets - MDN Web Docs
The z-index CSS property sets the z-order of a positioned element and its descendants or flex items. Overlapping elements with a larger ...
Read more >
Stacking overlapping views with zIndex in Expo and React ...
While a position: 'absolute' component may seem like it operates independently, it must still respect the zIndex of its parent.
Read more >
Diagnosis: z-index (submenu hidden behind content)
z-index values are relative to their element's siblings only; outside of that parent container, they have no effect. So if Element B is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found