react-native/Libraries/Image
Nick Lockwood e4c53c28ae Improved shadow performance
Summary:
public
React Native currently exposes the iOS layer shadow properties more-or-less directly, however there are a number of problems with this:

1) Performance when using these properties is poor by default. That's because iOS calculates the shadow by getting the exact pixel mask of the view, including any tranlucent content, and all of its subviews, which is very CPU and GPU-intensive.
2) The iOS shadow properties do not match the syntax or semantics of the CSS box-shadow standard, and are unlikely to be possible to implement on Android.
3) We don't expose the `layer.shadowPath` property, which is crucial to getting good performance out of layer shadows.

This diff solves problem number 1) by implementing a default `shadowPath` that matches the view border for views with an opaque background. This improves the performance of shadows by optimizing for the common usage case. I've also reinstated background color propagation for views which have shadow props - this should help ensure that this best-case scenario occurs more often.

For views with an explicit transparent background, the shadow will continue to work as it did before ( `shadowPath` will be left unset, and the shadow will be derived exactly from the pixels of the view and its subviews). This is the worst-case path for performance, however, so you should avoid it unless absolutely necessary. **Support for this may be disabled by default in future, or dropped altogether.**

For translucent images, it is suggested that you bake the shadow into the image itself, or use another mechanism to pre-generate the shadow. For text shadows, you should use the textShadow properties, which work cross-platform and have much better performance.

Problem number 2) will be solved in a future diff, possibly by renaming the iOS shadowXXX properties to boxShadowXXX, and changing the syntax and semantics to match the CSS standards.

Problem number 3) is now mostly moot, since we generate the shadowPath automatically. In future, we may provide an iOS-specific prop to set the path explicitly if there's a demand for more precise control of the shadow.

Reviewed By: weicool

Differential Revision: D2827581

fb-gh-sync-id: 853aa018e1d61d5f88304c6fc1b78f9d7e739804
2016-01-14 14:04:34 -08:00
..
RCTImage.xcodeproj Added RCTDataRequestHandler 2015-10-19 09:07:06 -07:00
__tests__ Load assets from same folder as JSbundle (Android) 2016-01-06 08:46:35 -08:00
AssetRegistry.js [ReactNative] Teach flow how to deal with images 2015-08-26 18:26:09 -08:00
GlobalImageStub.js Removed references to isStatic from the codebase 2015-10-13 06:44:30 -07:00
Image.android.js Make style property available in Image.android.js like Image.ios.js 2015-12-07 10:47:28 -08:00
Image.ios.js Update references to `image!` to use require syntax 2016-01-04 07:41:27 -08:00
ImageEditor.js Added JS wrappers for ImageStore and ImageEditor 2015-12-23 10:08:07 -08:00
ImageResizeMode.js Bugfix - Typos 2015-12-15 09:09:32 -08:00
ImageSource.js Fix flow errors 2015-12-31 07:48:29 -08:00
ImageStore.js Added JS wrappers for ImageStore and ImageEditor 2015-12-23 10:08:07 -08:00
ImageStylePropTypes.js Improved shadow performance 2016-01-14 14:04:34 -08:00
RCTGIFImageDecoder.h Added RCTDataRequestHandler 2015-10-19 09:07:06 -07:00
RCTGIFImageDecoder.m Replaced RCTSparseArray with NSDictionary 2015-11-14 10:28:28 -08:00
RCTImageEditingManager.h [React Native] open source ImageEditingManager native module 2015-07-29 15:57:48 -08:00
RCTImageEditingManager.m Added JS wrappers for ImageStore and ImageEditor 2015-12-23 10:08:07 -08:00
RCTImageLoader.h Added getImageSize method 2015-12-31 18:51:30 -08:00
RCTImageLoader.m Added getImageSize method 2015-12-31 18:51:30 -08:00
RCTImageStoreManager.h RTCImageStoreManager uses NSData instead of UIImage 2015-11-17 09:55:31 -08:00
RCTImageStoreManager.m Added JS wrappers for ImageStore and ImageEditor 2015-12-23 10:08:07 -08:00
RCTImageUtils.h RCTImageUtils Obj-C nullability annotations 2016-01-06 03:55:30 -08:00
RCTImageUtils.m RCTImageUtils Obj-C nullability annotations 2016-01-06 03:55:30 -08:00
RCTImageView.h Added RCTImageSource 2015-12-08 03:32:30 -08:00
RCTImageView.m Fixed image tinting 2015-12-10 09:09:30 -08:00
RCTImageViewManager.h Merged RCTNetworkImageView functionality into RCTStaticImage 2015-07-17 07:43:16 -08:00
RCTImageViewManager.m Added getImageSize method 2015-12-31 18:51:30 -08:00
RCTShadowVirtualImage.h Added RCTImageSource 2015-12-08 03:32:30 -08:00
RCTShadowVirtualImage.m Added RCTImageSource 2015-12-08 03:32:30 -08:00
RCTVirtualImageManager.h Implemented inline image support for <Text> 2015-10-08 11:56:25 -07:00
RCTVirtualImageManager.m Added RCTImageSource 2015-12-08 03:32:30 -08:00
RCTXCAssetImageLoader.h Unify XCAsset handling logic 2015-10-12 04:15:27 -07:00
RCTXCAssetImageLoader.m Improved threading for image loader 2015-10-20 05:02:23 -07:00
RelativeImageStub.js [ReactNative] Teach flow how to deal with images 2015-08-26 18:26:09 -08:00
resolveAssetSource.js Load assets from same folder as JSbundle (Android) 2016-01-06 08:46:35 -08:00