Skip to content

Commit cec4238

Browse files
Fix macOS build issues
1 parent e8363dd commit cec4238

File tree

22 files changed

+237
-196
lines changed

22 files changed

+237
-196
lines changed

packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ - (void)initializeReactHostWithLaunchOptions:(NSDictionary *)launchOptions
163163
return;
164164
}
165165

166-
- (UIView *)viewWithModuleName:(NSString *)moduleName
166+
- (RCTPlatformView *)viewWithModuleName:(NSString *)moduleName // [macOS]
167167
initialProperties:(NSDictionary *)initialProperties
168168
launchOptions:(NSDictionary *)launchOptions
169169
{
@@ -214,7 +214,7 @@ - (RCTPlatformView *)createRootViewWithBridge:(RCTBridge *)bridge
214214
RCTPlatformView *rootView = RCTAppSetupDefaultRootView(bridge, moduleName, initProps, YES); // [macOS]
215215

216216
#if RCT_DEV_MENU // [macOS
217-
if (enableFabric && [rootView isKindOfClass:[RCTSurfaceHostingView class]]) {
217+
if ([rootView isKindOfClass:[RCTSurfaceHostingView class]]) {
218218
RCTDevMenu *devMenu = [bridge moduleForClass:[RCTDevMenu class]];
219219
if (devMenu) {
220220
[(RCTSurfaceHostingView *)rootView setDevMenu:devMenu];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// convert to ARGB if it isn't
2727
if (CGImageGetBitsPerPixel(imageRef) != 32 || (((CGImageGetBitmapInfo(imageRef) & kCGBitmapAlphaInfoMask)) == 0u)) {
2828
RCTUIGraphicsImageRendererFormat *const rendererFormat = [RCTUIGraphicsImageRendererFormat defaultFormat]; // [macOS]
29-
rendererFormat.scale = inputImage.scale;
29+
rendererFormat.scale = UIImageGetScale(inputImage); // [macOS]
3030
RCTUIGraphicsImageRenderer *const renderer = [[RCTUIGraphicsImageRenderer alloc] initWithSize:inputImage.size // [macOS]
3131
format:rendererFormat];
3232

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

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,21 @@ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) {
195195
overrides.verticalAlign = undefined;
196196
}
197197

198+
// [macOS
199+
// For some reason on macOS, Setting backgroundColor without borderRadius on Text will
200+
// cause the color to spill pass the frame of the Text. We can solve this by setting a dummy
201+
// value for borderRadius.
202+
if (Platform.OS === 'macos') {
203+
if (
204+
'backgroundColor' in processedStyle &&
205+
!('borderRadius' in processedStyle)
206+
) {
207+
overrides = overrides || ({}: {...TextStyleInternal});
208+
overrides.borderRadius = Number.MIN_VALUE;
209+
}
210+
}
211+
// macOS]
212+
198213
if (overrides != null) {
199214
// $FlowFixMe[incompatible-type]
200215
_style = [_style, overrides];
@@ -444,6 +459,21 @@ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) {
444459
overrides.verticalAlign = undefined;
445460
}
446461

462+
// [macOS
463+
// For some reason on macOS, Setting backgroundColor without borderRadius on Text will
464+
// cause the color to spill pass the frame of the Text. We can solve this by setting a dummy
465+
// value for borderRadius.
466+
if (Platform.OS === 'macos') {
467+
if (
468+
'backgroundColor' in processedStyle &&
469+
!('borderRadius' in processedStyle)
470+
) {
471+
overrides = overrides || ({}: {...TextStyleInternal});
472+
overrides.borderRadius = Number.MIN_VALUE;
473+
}
474+
}
475+
// macOS]
476+
447477
if (overrides != null) {
448478
// $FlowFixMe[incompatible-type]
449479
_style = [_style, overrides];
@@ -529,21 +559,6 @@ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) {
529559
default: accessible,
530560
});
531561

532-
// [macOS
533-
// For some reason on macOS, Setting backgroundColor without borderRadius on Text will
534-
// cause the color to spill pass the frame of the Text. We can solve this by setting a dummy
535-
// value for borderRadius.
536-
if (Platform.OS === 'macos') {
537-
if (
538-
'backgroundColor' in processedStyle &&
539-
!('borderRadius' in processedStyle)
540-
) {
541-
overrides = overrides || ({}: {...TextStyleInternal});
542-
overrides.borderRadius = Number.MIN_VALUE;
543-
}
544-
}
545-
// macOS]
546-
547562
let nativeText = null;
548563
if (isPressable) {
549564
nativeText = (

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,11 @@ CGSize RCTSwitchSize(void)
451451
static dispatch_once_t onceToken;
452452
dispatch_once(&onceToken, ^{
453453
RCTUnsafeExecuteOnMainQueueSync(^{
454+
#if !TARGET_OS_OSX // [macOS]
454455
rctSwitchSize = [UISwitch new].intrinsicContentSize;
456+
#else // [macOS
457+
rctSwitchSize = [NSSwitch new].intrinsicContentSize;
458+
#endif // macOS]
455459
});
456460
});
457461
return rctSwitchSize;
@@ -492,7 +496,7 @@ IMP RCTSwapClassMethods(Class cls, SEL original, SEL replacement) // [macOS]
492496
} else {
493497
method_exchangeImplementations(originalMethod, replacementMethod);
494498
}
495-
499+
496500
return originalImplementation; // [macOS]
497501
}
498502

@@ -511,7 +515,7 @@ IMP RCTSwapInstanceMethods(Class cls, SEL original, SEL replacement) // [macOS]
511515
} else {
512516
method_exchangeImplementations(originalMethod, replacementMethod);
513517
}
514-
518+
515519
return originalImplementation; // [macOS]
516520
}
517521

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,9 @@ - (void)setDefaultJSBundle
554554
NSAlertStyle style = NSAlertStyleInformational;
555555
#endif // macOS]
556556

557+
#if !TARGET_OS_OSX // [macOS]
557558
_actionSheet = [UIAlertController alertControllerWithTitle:@"React Native Dev Menu" message:nil preferredStyle:style];
558559

559-
#if !TARGET_OS_OSX // [macOS]
560560
NSAttributedString *title =
561561
[[NSAttributedString alloc] initWithString:@"React Native Dev Menu"
562562
attributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:17]}];
@@ -581,8 +581,7 @@ - (void)setDefaultJSBundle
581581
[RCTPresentedViewController() presentViewController:_actionSheet animated:YES completion:nil];
582582
#else // [macOS
583583
_alert = [NSAlert new];
584-
[_alert setMessageText:devMenuTitle];
585-
[_alert setInformativeText:description];
584+
[_alert setMessageText:@"React Native Dev Menu"];
586585
[_alert setAlertStyle:NSAlertStyleInformational];
587586

588587
NSArray<RCTDevMenuItem *> *items = [self _menuItemsToPresent];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static UIModalPresentationStyle presentationConfiguration(const ModalHostViewPro
9898

9999
@interface RCTModalHostViewComponentView () <RCTFabricModalHostViewControllerDelegate>
100100

101-
@property (nonatomic, weak) UIView *accessibilityFocusedView;
101+
@property (nonatomic, weak) RCTPlatformView *accessibilityFocusedView; // [macOS]
102102

103103
@end
104104

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,11 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
117117
#endif // [macOS]
118118
}
119119

120+
#if !TARGET_OS_OSX // [macOS]
120121
if (_recycled || newConcreteProps.zIndex != oldConcreteProps.zIndex) {
121122
_refreshControl.layer.zPosition = newConcreteProps.zIndex.value_or(0);
122123
}
124+
#endif // [macOS]
123125

124126
_recycled = NO;
125127
}
@@ -170,6 +172,7 @@ - (void)layoutSubviews
170172
{
171173
[super layoutSubviews];
172174

175+
#if !TARGET_OS_OSX // [macOS]
173176
// Attempts to begin refreshing before the initial layout are ignored by _refreshControl. So if the control is
174177
// refreshing when mounted, we need to call beginRefreshing in layoutSubviews or it won't work.
175178
if (self.window) {
@@ -179,6 +182,7 @@ - (void)layoutSubviews
179182
[self beginRefreshingProgrammatically];
180183
}
181184
}
185+
#endif // [macOS]
182186
}
183187

184188
#if !TARGET_OS_OSX // [macOS]

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ - (void)_disableViewCullingIfNecessary
653653
}
654654
}
655655

656+
#if !TARGET_OS_OSX // [macOS]
656657
- (NSInteger)accessibilityElementCount
657658
{
658659
// From empirical testing, method `accessibilityElementCount` is called lazily only
@@ -673,6 +674,7 @@ - (NSInteger)accessibilityElementCount
673674
[self _disableViewCullingIfNecessary];
674675
return [super focusItemsInRect:rect];
675676
}
677+
#endif // macOS]
676678

677679
- (void)_updateStateWithContentOffset
678680
{
@@ -696,8 +698,12 @@ - (void)_updateStateWithContentOffset
696698
}
697699
auto newData = oldData;
698700
newData.contentOffset = contentOffset;
701+
#if !TARGET_OS_OSX // [macOS]
699702
newData.disableViewCulling =
700703
UIAccessibilityIsVoiceOverRunning() || UIAccessibilityIsSwitchControlRunning() || isAccessibilityAPIUsed;
704+
#else // [macOS
705+
newData.disableViewCulling = isAccessibilityAPIUsed;
706+
#endif // macOS]
701707
return std::make_shared<const ScrollViewShadowNode::ConcreteState::Data>(newData);
702708
},
703709
enableImmediateUpdateModeForContentOffsetChanges ? EventQueue::UpdateMode::unstable_Immediate

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#import <React/RCTLog.h>
99
#import <React/RCTScrollViewComponentView.h>
1010
#import <React/RCTVirtualViewMode.h>
11-
#import <UIKit/UIKit.h>
11+
#import <React/RCTUIKit.h> // [macOS]
1212
#import <react/featureflags/ReactNativeFeatureFlags.h>
1313

1414
#import "RCTVirtualViewContainerState.h"
@@ -62,7 +62,7 @@ static BOOL CGRectOverlaps(CGRect rect1, CGRect rect2)
6262
return YES;
6363
}
6464

65-
@interface RCTVirtualViewContainerState () <UIScrollViewDelegate>
65+
@interface RCTVirtualViewContainerState () <RCTUIScrollViewDelegate> // [macOS]
6666
@end
6767

6868
@interface RCTVirtualViewContainerState () {
@@ -181,9 +181,9 @@ - (void)_updateModes:(id<RCTVirtualViewProtocol>)virtualView
181181
}
182182
}
183183

184-
#pragma mark - UIScrollViewDelegate
184+
#pragma mark - RCTUIScrollViewDelegate // [macOS]
185185

186-
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
186+
- (void)scrollViewDidScroll:(RCTUIScrollView *)scrollView // [macOS]
187187
{
188188
[self _updateModes:nil];
189189
}

packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTVirtualViewProtocol.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
*/
77

88
#import <React/RCTVirtualViewMode.h>
9-
#import <UIKit/UIKit.h>
9+
#import <React/RCTUIKit.h> // [macOS]
1010

1111
NS_ASSUME_NONNULL_BEGIN
1212

1313
@protocol RCTVirtualViewProtocol <NSObject>
1414

1515
- (NSString *)virtualViewID;
16-
- (CGRect)containerRelativeRect:(UIView *)view;
16+
- (CGRect)containerRelativeRect:(RCTPlatformView *)view; // [macOS]
1717
- (void)onModeChange:(RCTVirtualViewMode)newMode targetRect:(CGRect)targetRect thresholdRect:(CGRect)thresholdRect;
1818
@end
1919

0 commit comments

Comments
 (0)