Skip to content

Commit 7d8a1b1

Browse files
author
Adam Gleitman
committed
macOS-specific changes to get RNTester to compile
1 parent 212ab8a commit 7d8a1b1

File tree

10 files changed

+283
-238
lines changed

10 files changed

+283
-238
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515

1616
const NSUInteger kRCTBundleURLProviderDefaultPort = RCT_METRO_PORT;
1717

18-
#if !TARGET_OS_OSX // [macOS]
19-
NSString *const kRCTPlatformName = @"ios";
20-
#else // [macOS
21-
NSString *const kRCTPlatformName = @"macos";
22-
#endif // macOS]
23-
2418
#if RCT_DEV_MENU | RCT_PACKAGER_LOADING_FUNCTIONALITY
2519
static BOOL kRCTAllowPackagerAccess = YES;
2620
void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed)
2721
{
2822
kRCTAllowPackagerAccess = allowed;
2923
}
3024
#endif
31-
static NSString *const kRCTPlatformName = @"ios";
25+
26+
#if !TARGET_OS_OSX // [macOS]
27+
NSString *const kRCTPlatformName = @"ios";
28+
#else // [macOS
29+
NSString *const kRCTPlatformName = @"macos";
30+
#endif // macOS]
31+
3232
static NSString *const kRCTPackagerSchemeKey = @"RCT_packager_scheme";
3333
static NSString *const kRCTJsLocationKey = @"RCT_jsLocation";
3434
static NSString *const kRCTEnableDevKey = @"RCT_enableDev";

packages/react-native/ReactCommon/react/debug/React-debug.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Pod::Spec.new do |s|
2323
s.homepage = "https://reactnative.dev/"
2424
s.license = package["license"]
2525
s.author = "Meta Platforms, Inc. and its affiliates"
26-
s.platforms = { :ios => min_ios_version_supported }
26+
s.platforms = { :ios => min_ios_version_supported, :osx => '10.15' } # [macOS]
2727
s.source = source
2828
s.source_files = "**/*.{cpp,h}"
2929
s.header_dir = "react/debug"

packages/react-native/ReactCommon/react/renderer/components/legacyviewmanagerinterop/RCTLegacyViewManagerInteropCoordinator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ typedef void (^InterceptorBlock)(std::string eventName, folly::dynamic event);
3636
- (void)handleCommand:(NSString *)commandName
3737
args:(NSArray *)args
3838
reactTag:(NSInteger)tag
39-
paperView:(UIView *)paperView;
39+
paperView:(RCTUIView *)paperView; // [macOS]
4040

4141
- (void)removeViewFromRegistryWithTag:(NSInteger)tag;
4242

43-
- (void)addViewToRegistry:(UIView *)view withTag:(NSInteger)tag;
43+
- (void)addViewToRegistry:(RCTUIView *)view withTag:(NSInteger)tag; // [macOS]
4444

4545
@end
4646

packages/react-native/ReactCommon/react/renderer/components/legacyviewmanagerinterop/RCTLegacyViewManagerInteropCoordinator.mm

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ - (NSString *)componentViewName
103103
- (void)handleCommand:(NSString *)commandName
104104
args:(NSArray *)args
105105
reactTag:(NSInteger)tag
106-
paperView:(nonnull UIView *)paperView
106+
paperView:(nonnull RCTUIView *)paperView // [macOS]
107107
{
108108
Class managerClass = _componentData.managerClass;
109109
[self _lookupModuleMethodsIfNecessary];
@@ -143,27 +143,27 @@ - (void)handleCommand:(NSString *)commandName
143143
}
144144
}
145145

146-
- (void)addViewToRegistry:(UIView *)view withTag:(NSInteger)tag
146+
- (void)addViewToRegistry:(RCTUIView *)view withTag:(NSInteger)tag // [macOS]
147147
{
148-
[self _addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
148+
[self _addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTUIView *> *viewRegistry) { // [macOS]
149149
if ([viewRegistry objectForKey:@(tag)] != NULL) {
150150
return;
151151
}
152-
NSMutableDictionary<NSNumber *, UIView *> *mutableViewRegistry =
153-
(NSMutableDictionary<NSNumber *, UIView *> *)viewRegistry;
152+
NSMutableDictionary<NSNumber *, RCTUIView *> *mutableViewRegistry =
153+
(NSMutableDictionary<NSNumber *, RCTUIView *> *)viewRegistry; // [macOS]
154154
[mutableViewRegistry setObject:view forKey:@(tag)];
155155
}];
156156
}
157157

158158
- (void)removeViewFromRegistryWithTag:(NSInteger)tag
159159
{
160-
[self _addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
160+
[self _addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTUIView *> *viewRegistry) { // [macOS]
161161
if ([viewRegistry objectForKey:@(tag)] == NULL) {
162162
return;
163163
}
164164

165-
NSMutableDictionary<NSNumber *, UIView *> *mutableViewRegistry =
166-
(NSMutableDictionary<NSNumber *, UIView *> *)viewRegistry;
165+
NSMutableDictionary<NSNumber *, RCTUIView *> *mutableViewRegistry =
166+
(NSMutableDictionary<NSNumber *, RCTUIView *> *)viewRegistry; // [macOS]
167167
[mutableViewRegistry removeObjectForKey:@(tag)];
168168
}];
169169
}

packages/react-native/ReactCommon/react/renderer/runtimescheduler/React-runtimescheduler.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Pod::Spec.new do |s|
3535
s.homepage = "https://reactnative.dev/"
3636
s.license = package["license"]
3737
s.author = "Meta Platforms, Inc. and its affiliates"
38-
s.platforms = { :ios => min_ios_version_supported }
38+
s.platforms = { :ios => min_ios_version_supported, :osx => '10.15' } # [macOS]
3939
s.source = source
4040
s.source_files = "**/*.{cpp,h}"
4141
s.compiler_flags = folly_compiler_flags

packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ - (void)drawAttributedString:(AttributedString)attributedString
9494
CGRect rect = [layoutManager usedRectForTextContainer:textContainer];
9595
static auto threshold = 1.0 / RCTScreenScale() + 0.01; // Size of a pixel plus some small threshold.
9696

97+
#if !TARGET_OS_OSX // [macOS]
9798
// `rect`'s width is stored in double precesion.
9899
// `frame`'s width is also in double precesion but was stored as float in Yoga previously, precesion was lost.
99100
if (std::abs(RCTCeilPixelValue(rect.size.width) - frame.size.width) < threshold) {
@@ -103,6 +104,12 @@ - (void)drawAttributedString:(AttributedString)attributedString
103104
// We could create new `NSTextStorage` for the specific frame, but that is expensive.
104105
origin.x -= RCTCeilPixelValue(rect.origin.x);
105106
}
107+
#else // [macOS
108+
CGFloat scale = [[NSScreen mainScreen] backingScaleFactor];
109+
if (std::abs(RCTCeilPixelValue(rect.size.width, scale) - frame.size.width) < threshold) {
110+
origin.x -= RCTCeilPixelValue(rect.origin.x, scale);
111+
}
112+
#endif // macOS]
106113
}
107114

108115
#if TARGET_OS_MACCATALYST
@@ -288,15 +295,15 @@ - (TextMeasurement)_measureTextStorage:(NSTextStorage *)textStorage
288295
NSTextContainer *textContainer = layoutManager.textContainers.firstObject;
289296
[layoutManager ensureLayoutForTextContainer:textContainer];
290297

298+
CGSize size = [layoutManager usedRectForTextContainer:textContainer].size;
299+
291300
#if !TARGET_OS_OSX // [macOS]
292301
size = (CGSize){RCTCeilPixelValue(size.width), RCTCeilPixelValue(size.height)};
293302
#else // [macOS
294303
CGFloat scale = [[NSScreen mainScreen] backingScaleFactor];
295304
size = (CGSize){RCTCeilPixelValue(size.width, scale), RCTCeilPixelValue(size.height, scale)};
296305
#endif // macOS]
297306

298-
size = (CGSize){RCTCeilPixelValue(size.width), RCTCeilPixelValue(size.height)};
299-
300307
__block auto attachments = TextMeasurement::Attachments{};
301308

302309
[textStorage

packages/react-native/ReactCommon/react/utils/React-utils.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Pod::Spec.new do |s|
3636
s.homepage = "https://reactnative.dev/"
3737
s.license = package["license"]
3838
s.author = "Meta Platforms, Inc. and its affiliates"
39-
s.platforms = { :ios => min_ios_version_supported }
39+
s.platforms = { :ios => min_ios_version_supported, :osx => '10.15' } # [macOS]
4040
s.source = source
4141
s.source_files = "**/*.{cpp,h,mm}"
4242
s.compiler_flags = folly_compiler_flags

packages/rn-tester/NativeComponentExample/ios/RNTMyLegacyNativeViewManager.mm

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ + (BOOL)requiresMainQueueSetup
3939

4040
RCT_EXPORT_METHOD(changeBackgroundColor : (nonnull NSNumber *)reactTag color : (NSString *)color)
4141
{
42-
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
43-
UIView *view = viewRegistry[reactTag];
42+
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTUIView *> *viewRegistry) { // [macOS]
43+
RCTUIView *view = viewRegistry[reactTag]; // [macOS]
4444
if (!view || ![view isKindOfClass:[RNTLegacyView class]]) {
4545
RCTLogError(@"Cannot find RNTLegacyView with tag #%@", reactTag);
4646
return;
@@ -53,18 +53,18 @@ + (BOOL)requiresMainQueueSetup
5353
[scanner setScanLocation:1]; // bypass '#' character
5454
[scanner scanHexInt:&rgbValue];
5555

56-
UIColor *newColor = [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0
57-
green:((rgbValue & 0xFF00) >> 8) / 255.0
58-
blue:(rgbValue & 0xFF) / 255.0
59-
alpha:1.0];
56+
RCTUIColor *newColor = [RCTUIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0 // [macOS]
57+
green:((rgbValue & 0xFF00) >> 8) / 255.0
58+
blue:(rgbValue & 0xFF) / 255.0
59+
alpha:1.0];
6060
view.backgroundColor = newColor;
6161
}];
6262
}
6363

6464
- (RCTUIView *)view // [macOS]
6565
{
6666
RNTLegacyView *view = [[RNTLegacyView alloc] init];
67-
view.backgroundColor = UIColor.redColor;
67+
view.backgroundColor = RCTUIColor.redColor; // [macOS]
6868
return view;
6969
}
7070

0 commit comments

Comments
 (0)