Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bring View on top of Modal using zIndex style with React-Native

zIndex has been introduced recently to React-Native to change the position of a View in the stack of layers.

Although, I'm not able to bring a View on top of a Modal component.

My code looks like this:

render() {   return (     <View>       <Modal visible>         {props.children}       </Modal>       <View style={{ zIndex: 1000 }}>         <Text>Loading...</Text>       </View>     </View>   ); } 

I guess I could stop using <Modal> and create a regular animated <View> that would behave like the Modal, but I'd rather find another solution.

Any idea?

like image 785
alexmngn Avatar asked Sep 29 '16 09:09

alexmngn


People also ask

How do you overlap view over view in React Native?

You have have to use position:'absolute' and put the circle element as the last element of the elements list so it comes to top (no need to use zIndex). also the container div must have styles for child elements to be centered.

Does zIndex work in React Native?

To use z-index in React Native, we can use the zIndex style. to add 2 View s that has different zIndex values. The component with the higher zIndex value is laid over the component with the lower zIndex value. So the green square goes on top of the red square.


1 Answers

No amount of zIndex manipulation will bring something above a react-native Modal, unfortunately. The Modal component is a native view that sits on top of the rest of your react-native application. The only way to put something above it is to put something in the modal itself, or alternately to use a js only implementation of a Modal.

Incidentally, the react-native-community version of modal is also built on the react-native modal, so would have the same issue. There's a discussion about different js implementation here: https://github.com/react-native-community/react-native-modal/issues/145

like image 140
Jordan Davis Avatar answered Oct 11 '22 10:10

Jordan Davis