From 729d54a86902b9bce5ff3967c68eec2d258b2724 Mon Sep 17 00:00:00 2001 From: Shawn Dempsey Date: Mon, 23 Jan 2023 21:55:40 -0800 Subject: [PATCH 1/4] Fix RCTLegacyViewManagerInteropComponentView --- .../RCTLegacyViewManagerInteropComponentView.mm | 6 +++--- React/Fabric/Mounting/RCTComponentViewRegistry.mm | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.mm b/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.mm index 26fdcf49318622..ea90c5c1f9d84c 100644 --- a/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.mm @@ -43,7 +43,7 @@ - (instancetype)initWithFrame:(CGRect)frame - (RCTUIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event // [macOS] { - RCTUIView *result = [super hitTest:point withEvent:event]; // [macOS] + RCTUIView *result = (RCTUIView *)[super hitTest:point withEvent:event]; // [macOS] if (result == _adapter.paperView) { return self; @@ -197,9 +197,9 @@ - (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask for (NSDictionary *mountInstruction in _viewsToBeMounted) { NSNumber *index = mountInstruction[kRCTLegacyInteropChildIndexKey]; - UIView *childView = mountInstruction[kRCTLegacyInteropChildComponentKey]; + RCTUIView *childView = mountInstruction[kRCTLegacyInteropChildComponentKey]; // [macOS] if ([childView isKindOfClass:[RCTLegacyViewManagerInteropComponentView class]]) { - UIView *target = ((RCTLegacyViewManagerInteropComponentView *)childView).contentView; + RCTUIView *target = ((RCTLegacyViewManagerInteropComponentView *)childView).contentView; // [macOS] [_adapter.paperView insertReactSubview:target atIndex:index.integerValue]; } else { [_adapter.paperView insertReactSubview:childView atIndex:index.integerValue]; diff --git a/React/Fabric/Mounting/RCTComponentViewRegistry.mm b/React/Fabric/Mounting/RCTComponentViewRegistry.mm index e08a3c199dcb69..23d305641f17f8 100644 --- a/React/Fabric/Mounting/RCTComponentViewRegistry.mm +++ b/React/Fabric/Mounting/RCTComponentViewRegistry.mm @@ -40,7 +40,9 @@ - (instancetype)init dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // Calling this a bit later, when the main thread is probably idle while JavaScript thread is busy. +#if !TARGET_OS_OSX // [macOS] [self preallocateViewComponents]; +#endif // [macOS] }); } From 958a0583a43511b709bfb630e4f890909f7a7e90 Mon Sep 17 00:00:00 2001 From: Shawn Dempsey Date: Mon, 23 Jan 2023 22:37:33 -0800 Subject: [PATCH 2/4] Fix Fabric crash setting frame --- React/Fabric/Mounting/UIView+ComponentViewProtocol.mm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm b/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm index 9d7b3717683e70..936779e8eddb13 100644 --- a/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm +++ b/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm @@ -103,7 +103,11 @@ - (void)updateLayoutMetrics:(LayoutMetrics const &)layoutMetrics } else { // Note: Changing `frame` when `layer.transform` is not the `identity transform` is undefined behavior. // Therefore, we must use `center` and `bounds`. +#if !TARGET_OS_OSX // [macOS] self.center = CGPoint{CGRectGetMidX(frame), CGRectGetMidY(frame)}; +#else // [macOS + self.frame = frame; +#endif // macOS] self.bounds = CGRect{CGPointZero, frame.size}; } } From 21bb1e400876c1eb6a37cffdaf0d52f6996c1e4f Mon Sep 17 00:00:00 2001 From: Shawn Dempsey Date: Mon, 23 Jan 2023 22:37:45 -0800 Subject: [PATCH 3/4] Fix crash w/ first responder --- .../ComponentViews/TextInput/RCTTextInputComponentView.mm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm index 0fee0499389bde..af4ab21632214e 100644 --- a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm @@ -85,7 +85,9 @@ - (void)didMoveToWindow if (self.window && !_didMoveToWindow) { auto const &props = *std::static_pointer_cast(_props); if (props.autoFocus) { +#if !TARGET_OS_OSX // [macOS] [_backedTextInputView becomeFirstResponder]; +#endif // [macOS] } _didMoveToWindow = YES; } From 816ff1a39d4eb47653a09b5779c3eb377e5fc4c5 Mon Sep 17 00:00:00 2001 From: Shawn Dempsey Date: Mon, 23 Jan 2023 22:39:20 -0800 Subject: [PATCH 4/4] Fix RCTFindTextInputWithNativeId --- .../InputAccessory/RCTInputAccessoryComponentView.mm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/React/Fabric/Mounting/ComponentViews/InputAccessory/RCTInputAccessoryComponentView.mm b/React/Fabric/Mounting/ComponentViews/InputAccessory/RCTInputAccessoryComponentView.mm index 364ea6c26b3773..af1604677acbe5 100644 --- a/React/Fabric/Mounting/ComponentViews/InputAccessory/RCTInputAccessoryComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/InputAccessory/RCTInputAccessoryComponentView.mm @@ -66,8 +66,12 @@ - (void)didMoveToWindow if (self.window && !_textInput) { if (self.nativeId) { +#if !TARGET_OS_OSX // [macOS] _textInput = RCTFindTextInputWithNativeId(self.window, self.nativeId); _textInput.inputAccessoryView = _contentView; +#else // [macOS + _textInput = RCTFindTextInputWithNativeId(self.window.contentView, self.nativeId); +#endif // macOS] } else { _textInput = RCTFindTextInputWithNativeId(_contentView, nil); }