From 86007654ae89fba8bfd3be31a07a6604c7feb361 Mon Sep 17 00:00:00 2001 From: Shawn Dempsey Date: Fri, 26 Apr 2024 17:54:13 -0700 Subject: [PATCH 1/2] [fabric] Make RCTViewComponentView to be layer-backed by enabling wantsUpdateLayer Summary: As title Test Plan: TBD I believe this is tested after cloning changes to fbsource and then testing there? Reviewers: shawndempsey, lefever, helenistic Reviewed By: lefever Differential Revision: https://phabricator.intern.facebook.com/D53783607 Tasks: T163838856 --- .../Mounting/ComponentViews/View/RCTViewComponentView.mm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm index 08fd12bbd59325..af394b1535ddf7 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm @@ -2025,6 +2025,11 @@ - (NSString *)componentViewName_DO_NOT_USE_THIS_IS_BROKEN return RCTNSStringFromString([[self class] componentDescriptorProvider].name); } +- (BOOL)wantsUpdateLayer +{ + return YES; +} + @end #ifdef __cplusplus From 45b6015dbc6da5352da0004fee872df219ffcf8e Mon Sep 17 00:00:00 2001 From: Nick Lefever Date: Fri, 23 Feb 2024 00:20:42 +0100 Subject: [PATCH 2/2] [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 --- packages/react-native/React/Base/macOS/RCTUIKit.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/react-native/React/Base/macOS/RCTUIKit.m b/packages/react-native/React/Base/macOS/RCTUIKit.m index 042c64b94fda23..08e6c95545ac6d 100644 --- a/packages/react-native/React/Base/macOS/RCTUIKit.m +++ b/packages/react-native/React/Base/macOS/RCTUIKit.m @@ -129,6 +129,7 @@ @implementation RCTUIView BOOL _clipsToBounds; BOOL _userInteractionEnabled; BOOL _mouseDownCanMoveWindow; + BOOL _respondsToDisplayLayer; } + (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key @@ -158,6 +159,7 @@ @implementation RCTUIView self->_userInteractionEnabled = YES; self->_enableFocusRing = YES; self->_mouseDownCanMoveWindow = YES; + self->_respondsToDisplayLayer = [self respondsToSelector:@selector(displayLayer:)]; } return self; } @@ -259,7 +261,12 @@ - (void)updateLayer // so it has to be reset from the view's NSColor ivar. [layer setBackgroundColor:[_backgroundColor CGColor]]; } - [(id)self displayLayer:layer]; + + // In Fabric, wantsUpdateLayer is always enabled and doesn't guarantee that + // the instance has a displayLayer method. + if (_respondsToDisplayLayer) { + [(id)self displayLayer:layer]; + } } - (void)drawRect:(CGRect)rect