Skip to content

Commit 7f3436c

Browse files
Fix macOS build issues
1 parent 3a602db commit 7f3436c

File tree

27 files changed

+88
-41
lines changed

27 files changed

+88
-41
lines changed

packages/react-native/Libraries/Components/Pressable/Pressable.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,6 @@ function Pressable({
317317
onPressMove,
318318
onPressOut,
319319
// [macOS
320-
onFocus,
321-
onBlur,
322320
onKeyDown,
323321
onKeyUp,
324322
keyDownEvents,
@@ -428,8 +426,6 @@ function Pressable({
428426
}
429427
},
430428
// [macOS
431-
onFocus,
432-
onBlur,
433429
onKeyDown,
434430
onKeyUp,
435431
// macOS]
@@ -453,8 +449,6 @@ function Pressable({
453449
onPressMove,
454450
onPressOut,
455451
// [macOS
456-
onFocus,
457-
onBlur,
458452
onKeyDown,
459453
onKeyUp,
460454
// macOS]

packages/react-native/Libraries/Image/RCTUIImageViewAnimated.mm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ - (void)setImage:(RCTPlatformImage *)image // [macOS]
9494
if (image == thisImage) {
9595
return;
9696
}
97-
97+
98+
#if !TARGET_OS_OSX // [macOS]
9899
[self stop];
99100
[self resetAnimatedImage];
100101

@@ -128,6 +129,9 @@ - (void)setImage:(RCTPlatformImage *)image // [macOS]
128129
}
129130

130131
super.image = image;
132+
#else // [macOS
133+
[super setImage:image];
134+
#endif // macOS]
131135
}
132136

133137
#pragma mark - Private

packages/react-native/Libraries/Network/RCTNetworkConversions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
#import <UIKit/UIKit.h>
8+
#import <React/RCTUIKit.h> // [macOS]
99

1010
#ifdef __cplusplus
1111

packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.mm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ - (instancetype)initWithTextField:(UITextField<RCTBackedTextInputViewProtocol> *
3636
if (self = [super init]) {
3737
_backedTextInputView = backedTextInputView;
3838
backedTextInputView.delegate = self;
39+
40+
#if !TARGET_OS_OSX // [macOS]
3941
backedTextInputView.textDropDelegate = self;
42+
#endif // [macOS]
4043

4144
#if !TARGET_OS_OSX // [macOS]
4245
[_backedTextInputView addTarget:self
@@ -181,6 +184,8 @@ - (void)textFieldProbablyDidChangeSelection
181184
[_backedTextInputView.textInputDelegate textInputDidChangeSelection];
182185
}
183186

187+
188+
#if !TARGET_OS_OSX // [macOS]
184189
#pragma mark - UITextDropDelegate
185190

186191
- (UITextDropEditability)textDroppableView:(UIView<UITextDroppable> *)textDroppableView
@@ -216,6 +221,7 @@ - (bool)_shouldAcceptDrop:(id<UITextDropRequest>)drop
216221
return true;
217222
}
218223
}
224+
#endif // macOS]
219225

220226
#if TARGET_OS_OSX // [macOS
221227

@@ -297,7 +303,11 @@ - (void)textFieldDidChangeSelection:(NSTextField *)textField
297303

298304
#pragma mark - RCTBackedTextViewDelegateAdapter (for UITextView)
299305

306+
#if !TARGET_OS_OSX // [macOS]
300307
@interface RCTBackedTextViewDelegateAdapter () <UITextViewDelegate, UITextDropDelegate>
308+
#else // [macOS
309+
@interface RCTBackedTextViewDelegateAdapter () <UITextViewDelegate>
310+
#endif // macOS]
301311
@end
302312

303313
@implementation RCTBackedTextViewDelegateAdapter {
@@ -322,7 +332,9 @@ - (instancetype)initWithTextView:(UITextView<RCTBackedTextInputViewProtocol> *)b
322332
if (self = [super init]) {
323333
_backedTextInputView = backedTextInputView;
324334
backedTextInputView.delegate = self;
335+
#if !TARGET_OS_OSX // [macOS]
325336
backedTextInputView.textDropDelegate = self;
337+
#endif // [macOS]
326338
}
327339

328340
return self;
@@ -535,6 +547,7 @@ - (void)textViewProbablyDidChangeSelection
535547
[_backedTextInputView.textInputDelegate textInputDidChangeSelection];
536548
}
537549

550+
#if !TARGET_OS_OSX // [macOS]
538551
#pragma mark - UITextDropDelegate
539552

540553
- (UITextDropEditability)textDroppableView:(UIView<UITextDroppable> *)textDroppableView
@@ -570,5 +583,6 @@ - (bool)_shouldAcceptDrop:(id<UITextDropRequest>)drop
570583
return true;
571584
}
572585
}
586+
#endif // macOS]
573587

574588
@end

packages/react-native/Libraries/WebSocket/WebSocket.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class WebSocket extends EventTarget {
141141
this._eventEmitter = new NativeEventEmitter(
142142
// T88715063: NativeEventEmitter only used this parameter on iOS. Now it uses it on all platforms, so this code was modified automatically to preserve its behavior
143143
// If you want to use the native module on other platforms, please remove this condition and test its behavior
144-
(Platform.OS !== 'ios' || Platform.OS !== 'macos') ? null : NativeWebSocketModule, // [macOS]
144+
(Platform.OS !== 'ios' && Platform.OS !== 'macos') ? null : NativeWebSocketModule, // [macOS]
145145
);
146146
this._socketId = nextWebSocketId++;
147147
this._registerEvents();

packages/react-native/React/Base/RCTUtils.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@
3939
// Determines if a given image URL refers to a image in Home directory (~)
4040
BOOL RCTIsHomeAssetURL(NSURL *__nullable imageURL);
4141

42+
#if !TARGET_OS_OSX // [macOS]
4243
// Returns the current device's orientation
4344
UIDeviceOrientation RCTDeviceOrientation(void);
45+
#endif // [macOS]
4446

4547
// Whether the New Architecture is enabled or not
4648
BOOL RCTIsNewArchEnabled(void)
@@ -363,6 +365,8 @@ static void RCTUnsafeExecuteOnMainQueueOnceSync(dispatch_once_t *onceToken, disp
363365
dispatch_sync(dispatch_get_main_queue(), executeOnce);
364366
}
365367

368+
#if !TARGET_OS_OSX // [macOS]
369+
366370
CGFloat RCTScreenScale(void)
367371
{
368372
static dispatch_once_t onceTokenScreenScale;

packages/react-native/React/CoreModules/RCTAppearance.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ - (instancetype)init
115115
UITraitCollection *traitCollection = RCTKeyWindow().traitCollection;
116116
_currentColorScheme = RCTColorSchemePreference(traitCollection);
117117
#else // [macOS
118-
NSAppearance *appearance = [RCTKeyWindow().currentAppearance;
118+
NSAppearance *appearance = [NSApp effectiveAppearance];
119119
_currentColorScheme = RCTColorSchemePreference(appearance);
120120
#endif // macOS]
121121
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -214,4 +214,4 @@ - (void)invalidate
214214
Class RCTAppearanceCls(void)
215215
{
216216
return RCTAppearance.class;
217-
}
217+
}

packages/react-native/React/CoreModules/RCTDeviceInfo.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ @implementation RCTDeviceInfo {
3434
std::atomic<BOOL> _invalidated;
3535
NSDictionary *_constants;
3636

37-
__weak UIWindow *_applicationWindow;
37+
__weak RCTPlatformWindow *_applicationWindow; // [macOS]
3838
}
3939

4040
static NSString *const kFrameKeyPath = @"frame";
@@ -198,7 +198,7 @@ static BOOL RCTIsIPhoneNotched()
198198
#endif // macOS]
199199

200200
// We fallback to screen size if a key window is not found.
201-
CGSize windowSize = mainWindow ? mainWindow.bounds.size : screenSize;
201+
CGSize windowSize = mainWindow ? mainWindow.frame.size : screenSize; //[macOS]
202202

203203
#if !TARGET_OS_OSX // [macOS]
204204
#if !TARGET_OS_VISION // [visionOS]

packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ - (void)presentationControllerDidAttemptToDismiss:(UIPresentationController *)co
291291
eventEmitter->onRequestClose({});
292292
}
293293
}
294-
#endif // [macOS]
295294

296295
- (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController
297296
{
@@ -302,6 +301,7 @@ - (void)presentationControllerDidDismiss:(UIPresentationController *)presentatio
302301
eventEmitter->onRequestClose({});
303302
}
304303
}
304+
#endif // [macOS]
305305

306306
@end
307307

@@ -319,4 +319,4 @@ - (void)presentationControllerDidDismiss:(UIPresentationController *)presentatio
319319
Class<RCTComponentViewProtocol> RCTModalHostViewCls(void)
320320
{
321321
return RCTModalHostViewComponentView.class;
322-
}
322+
}

packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -512,16 +512,20 @@ - (void)updateState:(const State::Shared &)state oldState:(const State::Shared &
512512
}];
513513
}
514514

515-
- (UIView *)betterHitTest:(CGPoint)point withEvent:(UIEvent *)event
515+
- (RCTUIView *)betterHitTest:(CGPoint)point withEvent:(UIEvent *)event // [macOS]
516516
{
517517
// This is the same algorithm as in the RCTViewComponentView with the exception of
518518
// skipping the immediate child (_containerView) and checking grandchildren instead.
519519
// This prevents issues with touches outside of _containerView being ignored even
520520
// if they are within the bounds of the _containerView's children.
521521

522+
#if !TARGET_OS_OSX // [macOS]
522523
if (!self.userInteractionEnabled || self.hidden || self.alpha < 0.01) {
523-
return nil;
524-
}
524+
#else // [macOS
525+
if (!self.userInteractionEnabled || self.hidden) {
526+
#endif // macOS]
527+
return nil;
528+
}
525529

526530
BOOL isPointInside = [self pointInside:point withEvent:event];
527531

@@ -533,8 +537,8 @@ - (UIView *)betterHitTest:(CGPoint)point withEvent:(UIEvent *)event
533537
return nil;
534538
}
535539

536-
for (UIView *subview in [_containerView.subviews reverseObjectEnumerator]) {
537-
UIView *hitView = [subview hitTest:[subview convertPoint:point fromView:self] withEvent:event];
540+
for (RCTUIView *subview in [_containerView.subviews reverseObjectEnumerator]) { // [macOS]
541+
RCTUIView *hitView = [subview hitTest:[subview convertPoint:point fromView:self] withEvent:event]; // [macOS]
538542
if (hitView) {
539543
return hitView;
540544
}

0 commit comments

Comments
 (0)