From a9115bcbb34dd851b46317043576f1601fe2416d Mon Sep 17 00:00:00 2001 From: Andy Street Date: Wed, 26 Aug 2015 15:59:25 -0700 Subject: [PATCH] [ReactNative][SyncDiff] Add parameter to allow turning on/off off screen rendering for alpha compositing --- Libraries/Components/View/View.js | 23 +++++++++++++++++++ .../ReactNative/ReactNativeViewAttributes.js | 1 + 2 files changed, 24 insertions(+) diff --git a/Libraries/Components/View/View.js b/Libraries/Components/View/View.js index 8594cfe8b..fdb2ff6ed 100644 --- a/Libraries/Components/View/View.js +++ b/Libraries/Components/View/View.js @@ -274,6 +274,29 @@ var View = React.createClass({ * @platform android */ collapsable: PropTypes.bool, + + /** + * Whether this view needs to rendered offscreen and composited with an alpha + * in order to preserve 100% correct colors and blending behavior. The default + * (false) falls back to drawing the component and its children with an alpha + * applied to the paint used to draw each element instead of rendering the full + * component offscreen and compositing it back with an alpha value. This default + * may be noticeable and undesired in the case where the View you are setting + * an opacity on has multiple overlapping elements (e.g. multiple overlapping + * Views, or text and a background). + * + * Rendering offscreen to preserve correct alpha behavior is extremely + * expensive and hard to debug for non-native developers, which is why it is + * not turned on by default. If you do need to enable this property for an + * animation, consider combining it with renderToHardwareTextureAndroid if the + * view **contents** are static (i.e. it doesn't need to be redrawn each frame). + * If that property is enabled, this View will be rendered off-screen once, + * saved in a hardware texture, and then composited onto the screen with an alpha + * each frame without having to switch rendering targets on the GPU. + * + * @platform android + */ + needsOffscreenAlphaCompositing: PropTypes.bool, }, render: function() { diff --git a/Libraries/ReactNative/ReactNativeViewAttributes.js b/Libraries/ReactNative/ReactNativeViewAttributes.js index 028284db5..0447c78ab 100644 --- a/Libraries/ReactNative/ReactNativeViewAttributes.js +++ b/Libraries/ReactNative/ReactNativeViewAttributes.js @@ -30,6 +30,7 @@ ReactNativeViewAttributes.UIView = { onAccessibilityTap: true, onMagicTap: true, collapsable: true, + needsOffscreenAlphaCompositing: true, }; ReactNativeViewAttributes.RCTView = merge(