Skip to content

Commit d4eac3d

Browse files
committed
[RFC][Rendering] Add shouldRasterizeIOS to View components
Summary: Exposes the `shouldRasterize` property. Fixes #1986. Closes facebook/react-native#2226 Github Author: James Ide <ide@jameside.com>
1 parent d8f4310 commit d4eac3d

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

Libraries/Components/View/View.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,28 @@ var View = React.createClass({
225225
* different parameters. The downside is that this can use up limited video
226226
* memory, so this prop should be set back to false at the end of the
227227
* interaction/animation.
228+
* @platform android
228229
*/
229230
renderToHardwareTextureAndroid: PropTypes.bool,
231+
232+
/**
233+
* Whether this view should be rendered as a bitmap before compositing.
234+
*
235+
* On iOS, this is useful for animations and interactions that do not
236+
* modify this component's dimensions nor its children; for example, when
237+
* translating the position of a static view, rasterization allows the
238+
* renderer to reuse a cached bitmap of a static view and quickly composite
239+
* it during each frame.
240+
*
241+
* Rasterization incurs an off-screen drawing pass and the bitmap consumes
242+
* memory. Test and measure when using this property.
243+
* @platform ios
244+
*/
245+
shouldRasterizeIOS: PropTypes.bool,
246+
247+
/**
248+
* @platform android
249+
*/
230250
collapsable: PropTypes.bool,
231251
},
232252

Libraries/ReactNative/ReactNativeViewAttributes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ReactNativeViewAttributes.UIView = {
2323
accessibilityLiveRegion: true,
2424
accessibilityTraits: true,
2525
testID: true,
26+
shouldRasterizeIOS: true,
2627
onLayout: true,
2728
onAccessibilityTap: true,
2829
onMagicTap: true,

React/Views/RCTViewManager.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ - (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(__unused RCTSpars
112112
RCT_REMAP_VIEW_PROPERTY(shadowOpacity, layer.shadowOpacity, float)
113113
RCT_REMAP_VIEW_PROPERTY(shadowRadius, layer.shadowRadius, CGFloat)
114114
RCT_REMAP_VIEW_PROPERTY(overflow, clipsToBounds, css_clip_t)
115+
RCT_CUSTOM_VIEW_PROPERTY(shouldRasterizeIOS, BOOL, RCTView)
116+
{
117+
view.layer.shouldRasterize = json ? [RCTConvert BOOL:json] : defaultView.layer.shouldRasterize;
118+
view.layer.rasterizationScale = view.layer.shouldRasterize ? view.window.screen.scale : defaultView.layer.rasterizationScale;
119+
}
115120
RCT_CUSTOM_VIEW_PROPERTY(transformMatrix, CATransform3D, RCTView)
116121
{
117122
view.layer.transform = json ? [RCTConvert CATransform3D:json] : defaultView.layer.transform;

0 commit comments

Comments
 (0)