Skip to content

Commit 48f12bc

Browse files
committed
More new architecture and macOS fixes
1 parent e87426f commit 48f12bc

File tree

12 files changed

+82
-113
lines changed

12 files changed

+82
-113
lines changed

Libraries/AppDelegate/RCTAppDelegate.mm

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@ @interface RCTAppDelegate () {
2727

2828
@implementation RCTAppDelegate
2929

30+
#if !TARGET_OS_OSX // [macOS]
3031
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
3132
{
33+
#else // [macOS
34+
- (void)applicationDidFinishLaunching:(NSNotification *)notification
35+
{
36+
NSApplication *application = [notification object];
37+
NSDictionary *launchOptions = [notification userInfo];
38+
#endif // macOS]
3239
BOOL enableTM = NO;
3340
#if RCT_NEW_ARCH_ENABLED
3441
enableTM = self.turboModuleEnabled;
@@ -67,14 +74,14 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
6774
rootViewController.view = rootView;
6875
self.window.rootViewController = rootViewController;
6976
[self.window makeKeyAndVisible];
77+
return YES;
7078
#else // [macOS
7179
self.window = [[NSWindow alloc] init];
7280
NSViewController *rootViewController = [self createRootViewController];
7381
rootViewController.view = rootView;
7482
self.window.contentViewController = rootViewController;
7583
[self.window makeKeyAndOrderFront:self];
7684
#endif // macOS]
77-
return YES;
7885
}
7986

8087
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
@@ -118,7 +125,7 @@ - (RCTPlatformView *)createRootViewWithBridge:(RCTBridge *)bridge // [macOS]
118125
return RCTAppSetupDefaultRootView(bridge, moduleName, initProps, enableFabric);
119126
}
120127

121-
#if !TARGET_OS_OSX
128+
#if !TARGET_OS_OSX // [macOS]
122129
- (UIViewController *)createRootViewController
123130
{
124131
return [UIViewController new];

Libraries/AppDelegate/React-RCTAppDelegate.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Pod::Spec.new do |s|
4747
s.documentation_url = "https://reactnative.dev/docs/actionsheetios"
4848
s.license = package["license"]
4949
s.author = "Facebook, Inc. and its affiliates"
50-
s.platforms = { :ios => "12.4", :osx => "10.15" }
50+
s.platforms = { :ios => "12.4", :osx => "10.15" } # [macOS]
5151
s.source = source
5252
s.source_files = "**/*.{c,h,m,mm,S,cpp}"
5353

React-Core.podspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ Pod::Spec.new do |s|
109109
end
110110

111111
s.dependency "RCT-Folly", folly_version
112-
s.osx.dependency "RCT-Folly/Futures", folly_version # [macOS] Github issue ##1733: macOS needs this extra dependency
113112
s.dependency "React-cxxreact", version
114113
s.dependency "React-perflogger", version
115114
s.dependency "React-jsi", version

React/Views/RCTViewManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
@class RCTSparseArray;
2020
@class RCTUIManager;
2121

22-
typedef void (^RCTViewManagerUIBlock)(RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTPlatformView *> *viewRegistry); // [macOS]
22+
typedef void (^RCTViewManagerUIBlock)(RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTUIView *> *viewRegistry); // [macOS]
2323

2424
@interface RCTViewManager : NSObject <RCTBridgeModule>
2525

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ @interface RNTMyNativeViewComponentView () <RCTRNTMyNativeViewViewProtocol>
2020
@end
2121

2222
@implementation RNTMyNativeViewComponentView {
23-
UIView *_view;
23+
RCTUIView *_view; // [macOS]
2424
}
2525

2626
+ (ComponentDescriptorProvider)componentDescriptorProvider
@@ -34,34 +34,34 @@ - (instancetype)initWithFrame:(CGRect)frame
3434
static const auto defaultProps = std::make_shared<const RNTMyNativeViewProps>();
3535
_props = defaultProps;
3636

37-
_view = [[UIView alloc] init];
38-
_view.backgroundColor = [UIColor redColor];
37+
_view = [[RCTUIView alloc] init]; // [macOS]
38+
_view.backgroundColor = [RCTUIColor redColor]; // [macOS]
3939

4040
self.contentView = _view;
4141
}
4242

4343
return self;
4444
}
4545

46-
- (UIColor *)UIColorFromHexString:(const std::string)hexString
46+
- (RCTUIColor *)RCTUIColorFromHexString:(const std::string)hexString // [macOS]
4747
{
4848
unsigned rgbValue = 0;
4949
NSString *colorString = [NSString stringWithCString:hexString.c_str() encoding:[NSString defaultCStringEncoding]];
5050
NSScanner *scanner = [NSScanner scannerWithString:colorString];
5151
[scanner setScanLocation:1]; // bypass '#' character
5252
[scanner scanHexInt:&rgbValue];
53-
return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0
54-
green:((rgbValue & 0xFF00) >> 8) / 255.0
55-
blue:(rgbValue & 0xFF) / 255.0
56-
alpha:1.0];
53+
return [RCTUIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0 // [macOS]
54+
green:((rgbValue & 0xFF00) >> 8) / 255.0
55+
blue:(rgbValue & 0xFF) / 255.0
56+
alpha:1.0];
5757
}
5858

5959
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
6060
{
6161
[super updateProps:props oldProps:oldProps];
6262
}
6363

64-
- (void)onChange:(UIView *)sender
64+
- (void)onChange:(RCTUIView *)sender // [macOS]
6565
{
6666
// No-op
6767
// std::dynamic_pointer_cast<const ViewEventEmitter>(_eventEmitter)
@@ -77,7 +77,7 @@ - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args
7777

7878
- (void)callNativeMethodToChangeBackgroundColor:(NSString *)colorString
7979
{
80-
UIColor *color = [self UIColorFromHexString:std::string([colorString UTF8String])];
80+
RCTUIColor *color = [self RCTUIColorFromHexString:std::string([colorString UTF8String])]; // [macOS]
8181
_view.backgroundColor = color;
8282
}
8383
@end

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ @implementation RNTMyNativeViewManager
2020

2121
RCT_EXPORT_METHOD(callNativeMethodToChangeBackgroundColor : (nonnull NSNumber *)reactTag color : (NSString *)color)
2222
{
23-
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
24-
UIView *view = viewRegistry[reactTag];
25-
if (!view || ![view isKindOfClass:[UIView class]]) {
23+
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTUIView *> *viewRegistry) { // [macOS]
24+
RCTUIView *view = viewRegistry[reactTag]; // [macOS]
25+
if (!view || ![view isKindOfClass:[RCTPlatformView class]]) { // [macOS]
2626
RCTLogError(@"Cannot find NativeView with tag #%@", reactTag);
2727
return;
2828
}
@@ -33,17 +33,16 @@ @implementation RNTMyNativeViewManager
3333
NSScanner *scanner = [NSScanner scannerWithString:colorString];
3434
[scanner setScanLocation:1]; // bypass '#' character
3535
[scanner scanHexInt:&rgbValue];
36-
37-
view.backgroundColor = [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0
38-
green:((rgbValue & 0xFF00) >> 8) / 255.0
39-
blue:(rgbValue & 0xFF) / 255.0
40-
alpha:1.0];
36+
view.backgroundColor = [RCTUIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0 // [macOS
37+
green:((rgbValue & 0xFF00) >> 8) / 255.0
38+
blue:(rgbValue & 0xFF) / 255.0
39+
alpha:1.0];
4140
}];
4241
}
4342

44-
- (UIView *)view
43+
- (RCTUIView *)view // [macOS]
4544
{
46-
return [[UIView alloc] init];
45+
return [[RCTUIView alloc] init]; // [macOS]
4746
}
4847

4948
@end

packages/rn-tester/NativeComponentExample/js/MyNativeView.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,6 @@ const colors = [
2929
export default function MyNativeView(props: {}): React.Node {
3030
const ref = useRef<React.ElementRef<MyNativeViewType> | null>(null);
3131
const [opacity, setOpacity] = useState(1.0);
32-
33-
// [macOS Use this "hack" to only render this example if Fabric is enabled and allow CI to pass
34-
// Fabric Detection
35-
const [isFabric, setIsFabric] = useState<boolean>(false);
36-
// Avoid dot notation because at Meta, private properties are obfuscated.
37-
// $FlowFixMe[prop-missing]
38-
const _internalInstanceHandler = ref['_internalInstanceHandle']; // eslint-disable-line dot-notation
39-
setIsFabric(Boolean(_internalInstanceHandler?.stateNode?.canonical));
40-
41-
if (!isFabric) {
42-
return <View ref={ref} />;
43-
}
44-
// macOS]
45-
4632
return (
4733
<View style={{flex: 1}}>
4834
<RNTMyNativeView ref={ref} style={{flex: 1}} opacity={opacity} />

packages/rn-tester/Podfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def pods(target_name, options = {}, use_flipper: !IN_CI && !USE_FRAMEWORKS)
1919
project 'RNTesterPods.xcodeproj'
2020

2121
# [macOS Disable Fabric by default till macOS supports it
22-
fabric_enabled = ENV['USE_FABRIC'] == '1'
22+
fabric_enabled = ENV['USE_FABRIC'] == '1' || ENV['RCT_NEW_ARCH_ENABLED'] == '1'
2323
# macOS]
2424

2525
# Hermes is now enabled by default.
@@ -56,9 +56,6 @@ def pods(target_name, options = {}, use_flipper: !IN_CI && !USE_FRAMEWORKS)
5656

5757
# RNTester native modules and components
5858
pod 'ScreenshotManager', :path => "NativeModuleExample"
59-
if ENV['RCT_NEW_ARCH_ENABLED'] == '1'
60-
pod 'NativeCxxModuleExample', :path => "NativeCxxModuleExample"
61-
end
6259
end
6360

6461
target 'RNTester' do

0 commit comments

Comments
 (0)