react-native/Libraries/StyleSheet
Nick Lockwood d64368b9e2 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 https://github.com/facebook/react-native/pull/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 https://github.com/facebook/react-native/pull/7825

Reviewed By: javache

Differential Revision: D3365717

fbshipit-source-id: b34aa8bfad577bce023f8af5414f9b974aafd8aa
2016-06-07 07:43:49 -07:00
..
__tests__ Update Jest APIs on fbsource 2016-04-27 19:16:32 -07:00
ColorPropType.js Add support for number as colors 2016-02-08 04:04:38 -08:00
EdgeInsetsPropType.js [ReactNative] clean lint in all of Libraries/ 2015-05-19 13:47:04 -08:00
LayoutPropTypes.js Implement CSS z-index for iOS 2016-06-07 07:43:49 -07:00
PointPropType.js [ReactNative] clean lint in all of Libraries/ 2015-05-19 13:47:04 -08:00
StyleSheet.js add StyleSheet.absoluteFill convenience constant 2016-06-06 16:13:42 -07:00
StyleSheetPropType.js Flowify Libraries/StyleSheet and Libraries/Text 2015-03-24 16:22:59 -08:00
StyleSheetTypes.js [Flow] Clean up react-native for Flow v0.15.0 2015-09-04 16:51:18 -08:00
StyleSheetValidation.js Remove knowledge of fbjs from the packager 2016-03-02 04:28:38 -08:00
TransformPropTypes.js Deprecate transformMatrix and decomposedMatrix 2016-04-29 14:19:25 -07:00
flattenStyle.js Caches array length in flattenStyles methods for loop 2016-03-26 06:54:18 -07:00
normalizeColor.js Add support for number as colors 2016-02-08 04:04:38 -08:00
processColor.js Change internal format from 0xaarrggbb to 0xrrggbbaa 2016-02-07 10:14:29 -08:00
processTransform.js Remove knowledge of fbjs from the packager 2016-03-02 04:28:38 -08:00
setNormalizedColorAlpha.js Replace usages of hexToRgb with setNormalizedColorAlpha 2016-02-09 14:58:34 -08:00