Skip to content

Commit 45b6015

Browse files
Nick LefeverSaadnajmi
authored andcommitted
[upstream][paper] Fix crash when statically enabling wantsUpdateLayer for View component
Summary: This diff fixes an invariant that wasn't valid anymore after having enabled `wantsUpdateLayer` statically for the View component in Fabric. `RCTUIView` in RCTUIKit enables `wantsUpdateLayer` only if the instance implements the `displayLayer:` method. Because the View component always wants to have `wantsUpdateLayer` enabled, the assumption that `displayLayer:` exists wasn't valid anymore. This diff only calls the `displayLayer:` method if the instance effectively responds to it. To avoid a perf hit on the check, we only test for it in the initialization and cache the result. Test Plan: * Run the Cosmo app ``` ~/fbsource/xplat/arfx/cosmo/mac/run.sh ``` | Before | After | |--| | {F1460101180} | {F1460101226} | Reviewers: shawndempsey, jorgecab, #rn-desktop Reviewed By: shawndempsey Differential Revision: https://phabricator.intern.facebook.com/D54090975 # Conflicts: # packages/react-native/React/Base/macOS/RCTUIKit.m
1 parent 8600765 commit 45b6015

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/react-native/React/Base/macOS/RCTUIKit.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ @implementation RCTUIView
129129
BOOL _clipsToBounds;
130130
BOOL _userInteractionEnabled;
131131
BOOL _mouseDownCanMoveWindow;
132+
BOOL _respondsToDisplayLayer;
132133
}
133134

134135
+ (NSSet<NSString *> *)keyPathsForValuesAffectingValueForKey:(NSString *)key
@@ -158,6 +159,7 @@ @implementation RCTUIView
158159
self->_userInteractionEnabled = YES;
159160
self->_enableFocusRing = YES;
160161
self->_mouseDownCanMoveWindow = YES;
162+
self->_respondsToDisplayLayer = [self respondsToSelector:@selector(displayLayer:)];
161163
}
162164
return self;
163165
}
@@ -259,7 +261,12 @@ - (void)updateLayer
259261
// so it has to be reset from the view's NSColor ivar.
260262
[layer setBackgroundColor:[_backgroundColor CGColor]];
261263
}
262-
[(id<CALayerDelegate>)self displayLayer:layer];
264+
265+
// In Fabric, wantsUpdateLayer is always enabled and doesn't guarantee that
266+
// the instance has a displayLayer method.
267+
if (_respondsToDisplayLayer) {
268+
[(id<CALayerDelegate>)self displayLayer:layer];
269+
}
263270
}
264271

265272
- (void)drawRect:(CGRect)rect

0 commit comments

Comments
 (0)