Skip to content

Commit 862e1f2

Browse files
authored
chore(0.79): pick a bunch of fixes (#2760)
1 parent 74c4147 commit 862e1f2

File tree

10 files changed

+186
-24
lines changed

10 files changed

+186
-24
lines changed

.github/workflows/microsoft-pr.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
uses: ./.github/actions/microsoft-setup-toolchain
2525
with:
2626
node-version: '22'
27+
cache-npm-dependencies: ''
2728
# We lint the PR title instead of the commit message to avoid script injection attacks.
2829
# Using environment variables prevents potential security vulnerabilities as described in:
2930
# https://docs.github.com/en/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions#example-of-a-script-injection-attack
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
__default__: patch
3+
---
4+
5+
Pick a bunch of bug fixes

packages/react-native/Libraries/LinkingIOS/RCTLinkingManager.mm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ - (void)handleOpenURLNotification:(NSNotification *)notification
155155
RCT_EXPORT_METHOD(getInitialURL : (RCTPromiseResolveBlock)resolve reject : (__unused RCTPromiseRejectBlock)reject)
156156
{
157157
NSURL *initialURL = nil;
158+
#pragma clang diagnostic push // [macOS]
159+
#pragma clang diagnostic ignored "-Wdeprecated-declarations" // [macOS]
158160
if (self.bridge.launchOptions[UIApplicationLaunchOptionsURLKey]) {
159161
initialURL = self.bridge.launchOptions[UIApplicationLaunchOptionsURLKey];
160162
} else {
@@ -164,6 +166,7 @@ - (void)handleOpenURLNotification:(NSNotification *)notification
164166
initialURL = ((NSUserActivity *)userActivityDictionary[@"UIApplicationLaunchOptionsUserActivityKey"]).webpageURL;
165167
}
166168
}
169+
#pragma clang diagnostic pop // [macOS]
167170
resolve(RCTNullIfNil(initialURL.absoluteString));
168171
}
169172

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#if TARGET_OS_OSX // [macOS
9+
#import <AppKit/AppKit.h>
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface RCTAppearanceProxy : NSObject
14+
15+
+ (instancetype)sharedInstance;
16+
17+
/*
18+
* Property to access the current appearance.
19+
* Thread safe.
20+
*/
21+
@property (nonatomic, readonly) NSAppearance *currentAppearance;
22+
23+
- (void)startObservingAppearance;
24+
25+
@end
26+
27+
NS_ASSUME_NONNULL_END
28+
#endif // macOS]
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#if TARGET_OS_OSX // [macOS
9+
#import "RCTAppearanceProxy.h"
10+
11+
#import <React/RCTConstants.h>
12+
#import <React/RCTUtils.h>
13+
14+
#import <mutex>
15+
16+
@implementation RCTAppearanceProxy {
17+
BOOL _isObserving;
18+
std::mutex _mutex;
19+
NSAppearance *_currentAppearance;
20+
}
21+
22+
+ (instancetype)sharedInstance
23+
{
24+
static RCTAppearanceProxy *sharedInstance = nil;
25+
static dispatch_once_t onceToken;
26+
dispatch_once(&onceToken, ^{
27+
sharedInstance = [RCTAppearanceProxy new];
28+
});
29+
return sharedInstance;
30+
}
31+
32+
- (instancetype)init
33+
{
34+
self = [super init];
35+
if (self) {
36+
_isObserving = NO;
37+
_currentAppearance = [NSApp effectiveAppearance];
38+
}
39+
return self;
40+
}
41+
42+
- (void)startObservingAppearance
43+
{
44+
RCTAssertMainQueue();
45+
std::lock_guard<std::mutex> lock(_mutex);
46+
if (!_isObserving) {
47+
_isObserving = YES;
48+
[[NSNotificationCenter defaultCenter] addObserver:self
49+
selector:@selector(_appearanceDidChange:)
50+
name:RCTUserInterfaceStyleDidChangeNotification
51+
object:nil];
52+
}
53+
}
54+
55+
- (NSAppearance *)currentAppearance
56+
{
57+
{
58+
std::lock_guard<std::mutex> lock(_mutex);
59+
if (_isObserving) {
60+
return _currentAppearance;
61+
}
62+
}
63+
64+
__block NSAppearance *appearance = nil;
65+
if (RCTIsMainQueue()) {
66+
appearance = [NSApp effectiveAppearance];
67+
} else {
68+
dispatch_sync(dispatch_get_main_queue(), ^{
69+
appearance = [NSApp effectiveAppearance];
70+
});
71+
}
72+
return appearance;
73+
}
74+
75+
- (void)_appearanceDidChange:(NSNotification *)notification
76+
{
77+
std::lock_guard<std::mutex> lock(_mutex);
78+
79+
NSDictionary *userInfo = [notification userInfo];
80+
if (userInfo) {
81+
NSAppearance *appearance = userInfo[RCTUserInterfaceStyleDidChangeNotificationAppearanceKey];
82+
if (appearance != nil) {
83+
_currentAppearance = appearance;
84+
return;
85+
}
86+
}
87+
88+
_currentAppearance = [NSApp effectiveAppearance];
89+
}
90+
91+
@end
92+
#endif // macOS]

packages/react-native/React/Base/UIKitProxies/RCTInitializeUIKitProxies.mm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#import "RCTKeyWindowValuesProxy.h"
1111
#import "RCTTraitCollectionProxy.h"
1212
#import "RCTWindowSafeAreaProxy.h"
13+
#if TARGET_OS_OSX // [macOS
14+
#import "RCTAppearanceProxy.h"
15+
#endif // macOS]
1316

1417
void RCTInitializeUIKitProxies(void)
1518
{
@@ -19,7 +22,9 @@ void RCTInitializeUIKitProxies(void)
1922
#if !TARGET_OS_OSX // [macOS]
2023
[[RCTTraitCollectionProxy sharedInstance] startObservingTraitCollection];
2124
[[RCTInitialAccessibilityValuesProxy sharedInstance] recordAccessibilityValues];
22-
#endif // [macOS]
25+
#else // [macOS
26+
[[RCTAppearanceProxy sharedInstance] startObservingAppearance];
27+
#endif // macOS]
2328
[[RCTKeyWindowValuesProxy sharedInstance] startObservingWindowSizeIfNecessary];
2429
});
2530
}

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

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
#import "CoreModulesPlugins.h"
1616

17+
#if TARGET_OS_OSX // [macOS
18+
#import <React/RCTUtils.h>
19+
20+
#import "RCTAppearanceProxy.h"
21+
#endif // macOS]
22+
1723
using namespace facebook::react;
1824

1925
NSString *const RCTAppearanceColorSchemeLight = @"light";
@@ -119,7 +125,7 @@ - (instancetype)init
119125
UITraitCollection *traitCollection = [RCTTraitCollectionProxy sharedInstance].currentTraitCollection;
120126
_currentColorScheme = RCTColorSchemePreference(traitCollection);
121127
#else // [macOS
122-
NSAppearance *appearance = RCTSharedApplication().appearance;
128+
NSAppearance *appearance = [RCTAppearanceProxy sharedInstance].currentAppearance;
123129
_currentColorScheme = RCTColorSchemePreference(appearance);
124130
#endif // macOS]
125131
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -134,7 +140,11 @@ - (instancetype)init
134140

135141
+ (BOOL)requiresMainQueueSetup
136142
{
143+
#if !TARGET_OS_OSX // [macOS]
137144
return NO;
145+
#else // [macOS
146+
return YES;
147+
#endif // macOS]
138148
}
139149

140150
- (dispatch_queue_t)methodQueue
@@ -160,13 +170,15 @@ - (dispatch_queue_t)methodQueue
160170
window.overrideUserInterfaceStyle = userInterfaceStyle;
161171
}
162172
#else // [macOS
163-
NSAppearance *appearance = nil;
164-
if ([style isEqualToString:@"light"]) {
165-
appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
166-
} else if ([style isEqualToString:@"dark"]) {
167-
appearance = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
168-
}
169-
RCTSharedApplication().appearance = appearance;
173+
RCTExecuteOnMainQueue(^{
174+
NSAppearance *appearance = nil;
175+
if ([style isEqualToString:@"light"]) {
176+
appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
177+
} else if ([style isEqualToString:@"dark"]) {
178+
appearance = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
179+
}
180+
RCTSharedApplication().appearance = appearance;
181+
});
170182
#endif // macOS]
171183
}
172184

@@ -177,10 +189,7 @@ - (dispatch_queue_t)methodQueue
177189
UITraitCollection *traitCollection = [RCTTraitCollectionProxy sharedInstance].currentTraitCollection;
178190
_currentColorScheme = RCTColorSchemePreference(traitCollection);
179191
#else // [macOS
180-
__block NSAppearance *appearance = nil;
181-
RCTUnsafeExecuteOnMainQueueSync(^{
182-
appearance = RCTKeyWindow().appearance;
183-
});
192+
NSAppearance *appearance = [RCTAppearanceProxy sharedInstance].currentAppearance;
184193
_currentColorScheme = RCTColorSchemePreference(appearance);
185194
#endif // macOS]
186195
}
@@ -190,23 +199,19 @@ - (dispatch_queue_t)methodQueue
190199

191200
- (void)appearanceChanged:(NSNotification *)notification
192201
{
202+
#if !TARGET_OS_OSX // [macOS
193203
NSDictionary *userInfo = [notification userInfo];
194-
#if !TARGET_OS_OSX // [macOS]
195204
UITraitCollection *traitCollection = nil;
196205
if (userInfo) {
197206
traitCollection = userInfo[RCTUserInterfaceStyleDidChangeNotificationTraitCollectionKey];
198207
}
199208
NSString *newColorScheme = RCTColorSchemePreference(traitCollection);
200209
#else // [macOS
201-
NSAppearance *appearance = nil;
202-
if (userInfo) {
203-
appearance = userInfo[RCTUserInterfaceStyleDidChangeNotificationAppearanceKey];
204-
}
205-
NSString *newColorScheme = RCTColorSchemePreference(appearance);
210+
NSString *newColorScheme = RCTColorSchemePreference([RCTAppearanceProxy sharedInstance].currentAppearance);
206211
#endif // macOS]
207212
if (![_currentColorScheme isEqualToString:newColorScheme]) {
208213
_currentColorScheme = newColorScheme;
209-
[self sendEventWithName:@"appearanceChanged" body:@{@"colorScheme" : newColorScheme}];
214+
[self sendEventWithName:@"appearanceChanged" body:@{ @"colorScheme" : newColorScheme }];
210215
}
211216
}
212217

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo
150150
#if !TARGET_OS_OSX // [macOS]
151151
[self->_window.rootViewController.view addSubview:self->_container];
152152
#else // [macOS
153-
[self->_window.contentViewController.view addSubview:self->_container];
153+
[self->_window.contentView addSubview:self->_container];
154154
#endif // macOS]
155155
[self->_container addSubview:self->_label];
156156

@@ -175,6 +175,20 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo
175175
[self->_label.bottomAnchor constraintEqualToAnchor:self->_container.bottomAnchor constant:-5],
176176
]];
177177
#else // [macOS
178+
// Container constraints
179+
[NSLayoutConstraint activateConstraints:@[
180+
[self->_container.topAnchor constraintEqualToAnchor:self->_window.contentView.topAnchor],
181+
[self->_container.leadingAnchor constraintEqualToAnchor:self->_window.contentView.leadingAnchor],
182+
[self->_container.trailingAnchor constraintEqualToAnchor:self->_window.contentView.trailingAnchor],
183+
[self->_container.bottomAnchor constraintEqualToAnchor:self->_window.contentView.bottomAnchor],
184+
185+
// Label constraints
186+
[self->_label.centerXAnchor constraintEqualToAnchor:self->_container.centerXAnchor],
187+
[self->_label.centerYAnchor constraintEqualToAnchor:self->_container.centerYAnchor],
188+
[self->_label.leadingAnchor constraintGreaterThanOrEqualToAnchor:self->_container.leadingAnchor constant:10],
189+
[self->_label.trailingAnchor constraintLessThanOrEqualToAnchor:self->_container.trailingAnchor constant:-10],
190+
]];
191+
178192
if (![[RCTKeyWindow() sheets] doesContain:self->_window]) {
179193
[RCTKeyWindow() beginSheet:self->_window completionHandler:^(NSModalResponse returnCode) {
180194
[self->_window orderOut:self];

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
6464

6565
+ (BOOL)requiresMainQueueSetup
6666
{
67+
#if !TARGET_OS_OSX // [macOS]
68+
return NO;
69+
#else // [macOS
6770
return YES;
71+
#endif // macOS]
6872
}
6973

7074
- (dispatch_queue_t)methodQueue

packages/react-native/local-cli/generator-macos/templates/macos/Podfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
require_relative '../node_modules/react-native-macos/scripts/react_native_pods'
2-
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
1+
require 'pathname'
2+
3+
ws_dir = Pathname.new(__dir__)
4+
ws_dir = ws_dir.parent until
5+
File.exist?("#{ws_dir}/node_modules/react-native-macos/scripts/react_native_pods.rb") ||
6+
ws_dir.expand_path.to_s == '/'
7+
require "#{ws_dir}/node_modules/react-native-macos/scripts/react_native_pods.rb"
38

49
prepare_react_native_project!
510

611
target 'HelloWorld-macOS' do
7-
platform :macos, '11.0'
12+
platform :macos, '14.0'
813
use_native_modules!
914

1015
# Flags change depending on the env values.

0 commit comments

Comments
 (0)