-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zIndex, is it possible #1076
Comments
The order that you place the elements in determines its layout order, so if you put something at the end it will appear on top if you use |
Maybe I didn't explain myself correctly, I have a sequence of items placed using position:'absolute' and then inside each one of them I have another position:'absolute' item (these items are children of the parent absolutely positioned items), which is supposed to appear on the corner of each of these items, but instead appears behind them. |
You should post some code. I have the same setup and things are working fine for me. |
@JohnyDays - are the icons the last child of the posts? |
They are the first child, but the following elements are not absolutely positioned. |
@JohnyDays - yup, make them the last child, that will fix it |
It did fix it, thanks for the help. I don't know how relevant it is for the project to maintain similar behaviour to regular css/html, but here's a js fiddle demonstrating this differs from what would happen on the web, where an absolutely positioned child is always on top of it's siblings. |
cc @vjeux re: consistent behaviour with web |
On React Native we have Thanks a lot for the jsfiddle, we really want to be compatible with the web! |
Not sure how relevant it is, but I did make a little module to help with this type of thing. It allows you to define a key to order it's children by
So that when you do something like this, 2 would be on bottom. Although I would imagine this breaks down when not having an index for every item, could be updated easily to be more powerful I am sure. |
+1 to re-open this issue. There are situations where one cannot rely on rendering order to enforce Z-index: the two are orthogonal principles, which is why CSS implements z-index. For example, a card or a button console may need to be rendered above some descriptive text (in flex-order), but still sit in front of it (e.g. to capture touch first, to provide layout overlap, etc). Also see https://productpains.com/post/react-native/zindex-support/ |
The approach I would take is to reorder the native views so that from the perspective of React and css-layout there has been no reordering. |
I should chime in that there seems to be a very old iOS bug that causes the view drawing hierarchy to break when modifying the m34 value of the CATransform3D of a given UIView's backing layer. I'm guessing that this is how RCTViewManager is achieving mimicking CSS's perspective value? This has been an issue since iOS 5 as far as I know. My workaround has always been to modify the layer.zPosition of affected views to manually override the broken UIView hierarchy. I don't know of any other work around myself. |
Hi there! This issue is being closed because it has been inactive for a while. But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/zindex-is-it-possible ProductPains helps the community prioritize the most important issues thanks to its voting feature. Also, if this issue is a bug, please consider sending a PR with a fix. |
Product pain duplicate of https://productpains.com/post/react-native/zindex-support |
For everyone else, |
Amazing job! |
zIndex has some issues on Android - #8968 (comment) It is working fine in iOS and UWP (windows) |
For me re-ordering JSX is the only solution right now, if components I want to position are not siblings Sometimes, Even though I want component <Container>
<B />
<A />
</Container> and I give container |
we all know "re-ordering JSX is the solution right now" but when we can't re-order elements---- what should we do ???? |
if you have any elevation style prop put in the style, remove it. Solved my zIndex problem. |
I was using the following to simulate zIndex:
as a style property
It worked for a while, but now an error has appeared saying it is invalid(even though it worked for the last day)
Is there another way to do zIndex, I have a position:'absolute' element inside another position:'absolute' element, and the inner element is appearing behind the parent element, the above style corrected this, but it no longer works.
The text was updated successfully, but these errors were encountered: