Please sign in to comment.
Implement CSS z-index for iOS
Summary: This diff implement the CSS z-index for React Native iOS views. We've had numerous pull request for this feature, but they've all attempted to use the `layer.zPosition` property, which is problematic for two reasons: 1. zPosition only affects rendering order, not event processing order. Views with a higher zPosition will appear in front of others in the hierarchy, but won't be the first to receive touch events, and may be blocked by views that are visually behind them. 2. when using a perspective transform matrix, views with a nonzero zPosition will be rendered in a different position due to parallax, which probably isn't desirable. See #7825 for further discussion of this problem. So instead of using `layer.zPosition`, I've implemented this by actually adjusting the order of the subviews within their parent based on the zIndex. This can't be done on the JS side because it would affect layout, which is order-dependent, so I'm doing it inside the view itself. It works as follows: 1. The `reactSubviews` array is set, whose order matches the order of the JS components and shadowView components, as specified by the UIManager. 2. `didUpdateReactSubviews` is called, which in turn calls `sortedSubviews` (which lazily generates a sorted array of `reactSubviews` by zIndex) and inserts the result into the view. 3. If a subview is added or removed, or the zIndex of any subview is changed, the previous `sortedSubviews` array is cleared and `didUpdateReactSubviews` is called again. To demonstrate it working, I've modified the UIExplorer example from #7825 Reviewed By: javache Differential Revision: D3365717 fbshipit-source-id: b34aa8bfad577bce023f8af5414f9b974aafd8aa
- Loading branch information
Showing with 173 additions and 10 deletions.
- +66 −1 Examples/UIExplorer/ViewExample.js
- +3 −0 Libraries/StyleSheet/LayoutPropTypes.js
- +0 −4 React/Modules/RCTUIManager.m
- +5 −0 React/Views/RCTShadowView.h
- +24 −0 React/Views/RCTShadowView.m
- +7 −0 React/Views/RCTView.h
- +4 −2 React/Views/RCTView.m
- +4 −0 React/Views/RCTViewManager.m
- +5 −1 React/Views/UIView+Private.h
- +12 −1 React/Views/UIView+React.h
- +43 −1 React/Views/UIView+React.m