Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/microsoft-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
uses: ./.github/actions/microsoft-setup-toolchain
with:
node-version: '22'
cache-npm-dependencies: ''
# We lint the PR title instead of the commit message to avoid script injection attacks.
# Using environment variables prevents potential security vulnerabilities as described in:
# https://docs.github.com/en/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions#example-of-a-script-injection-attack
Expand Down
5 changes: 5 additions & 0 deletions .nx/version-plans/version-plan-1763131586011.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
__default__: patch
---

Pick a bunch of bug fixes
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ - (void)handleOpenURLNotification:(NSNotification *)notification
RCT_EXPORT_METHOD(getInitialURL : (RCTPromiseResolveBlock)resolve reject : (__unused RCTPromiseRejectBlock)reject)
{
NSURL *initialURL = nil;
#pragma clang diagnostic push // [macOS]
#pragma clang diagnostic ignored "-Wdeprecated-declarations" // [macOS]
if (self.bridge.launchOptions[UIApplicationLaunchOptionsURLKey]) {
initialURL = self.bridge.launchOptions[UIApplicationLaunchOptionsURLKey];
} else {
Expand All @@ -164,6 +166,7 @@ - (void)handleOpenURLNotification:(NSNotification *)notification
initialURL = ((NSUserActivity *)userActivityDictionary[@"UIApplicationLaunchOptionsUserActivityKey"]).webpageURL;
}
}
#pragma clang diagnostic pop // [macOS]
resolve(RCTNullIfNil(initialURL.absoluteString));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) Microsoft Corporation.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#if TARGET_OS_OSX // [macOS
#import <AppKit/AppKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface RCTAppearanceProxy : NSObject

+ (instancetype)sharedInstance;

/*
* Property to access the current appearance.
* Thread safe.
*/
@property (nonatomic, readonly) NSAppearance *currentAppearance;

- (void)startObservingAppearance;

@end

NS_ASSUME_NONNULL_END
#endif // macOS]
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright (c) Microsoft Corporation.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#if TARGET_OS_OSX // [macOS
#import "RCTAppearanceProxy.h"

#import <React/RCTConstants.h>
#import <React/RCTUtils.h>

#import <mutex>

@implementation RCTAppearanceProxy {
BOOL _isObserving;
std::mutex _mutex;
NSAppearance *_currentAppearance;
}

+ (instancetype)sharedInstance
{
static RCTAppearanceProxy *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [RCTAppearanceProxy new];
});
return sharedInstance;
}

- (instancetype)init
{
self = [super init];
if (self) {
_isObserving = NO;
_currentAppearance = [NSApp effectiveAppearance];
}
return self;
}

- (void)startObservingAppearance
{
RCTAssertMainQueue();
std::lock_guard<std::mutex> lock(_mutex);
if (!_isObserving) {
_isObserving = YES;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_appearanceDidChange:)
name:RCTUserInterfaceStyleDidChangeNotification
object:nil];
}
}

- (NSAppearance *)currentAppearance
{
{
std::lock_guard<std::mutex> lock(_mutex);
if (_isObserving) {
return _currentAppearance;
}
}

__block NSAppearance *appearance = nil;
if (RCTIsMainQueue()) {
appearance = [NSApp effectiveAppearance];
} else {
dispatch_sync(dispatch_get_main_queue(), ^{
appearance = [NSApp effectiveAppearance];
});
}
return appearance;
}

- (void)_appearanceDidChange:(NSNotification *)notification
{
std::lock_guard<std::mutex> lock(_mutex);

NSDictionary *userInfo = [notification userInfo];
if (userInfo) {
NSAppearance *appearance = userInfo[RCTUserInterfaceStyleDidChangeNotificationAppearanceKey];
if (appearance != nil) {
_currentAppearance = appearance;
return;
}
}

_currentAppearance = [NSApp effectiveAppearance];
}

@end
#endif // macOS]
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#import "RCTKeyWindowValuesProxy.h"
#import "RCTTraitCollectionProxy.h"
#import "RCTWindowSafeAreaProxy.h"
#if TARGET_OS_OSX // [macOS
#import "RCTAppearanceProxy.h"
#endif // macOS]

void RCTInitializeUIKitProxies(void)
{
Expand All @@ -19,7 +22,9 @@ void RCTInitializeUIKitProxies(void)
#if !TARGET_OS_OSX // [macOS]
[[RCTTraitCollectionProxy sharedInstance] startObservingTraitCollection];
[[RCTInitialAccessibilityValuesProxy sharedInstance] recordAccessibilityValues];
#endif // [macOS]
#else // [macOS
[[RCTAppearanceProxy sharedInstance] startObservingAppearance];
#endif // macOS]
[[RCTKeyWindowValuesProxy sharedInstance] startObservingWindowSizeIfNecessary];
});
}
43 changes: 24 additions & 19 deletions packages/react-native/React/CoreModules/RCTAppearance.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

#import "CoreModulesPlugins.h"

#if TARGET_OS_OSX // [macOS
#import <React/RCTUtils.h>

#import "RCTAppearanceProxy.h"
#endif // macOS]

using namespace facebook::react;

NSString *const RCTAppearanceColorSchemeLight = @"light";
Expand Down Expand Up @@ -119,7 +125,7 @@ - (instancetype)init
UITraitCollection *traitCollection = [RCTTraitCollectionProxy sharedInstance].currentTraitCollection;
_currentColorScheme = RCTColorSchemePreference(traitCollection);
#else // [macOS
NSAppearance *appearance = RCTSharedApplication().appearance;
NSAppearance *appearance = [RCTAppearanceProxy sharedInstance].currentAppearance;
_currentColorScheme = RCTColorSchemePreference(appearance);
#endif // macOS]
[[NSNotificationCenter defaultCenter] addObserver:self
Expand All @@ -134,7 +140,11 @@ - (instancetype)init

+ (BOOL)requiresMainQueueSetup
{
#if !TARGET_OS_OSX // [macOS]
return NO;
#else // [macOS
return YES;
#endif // macOS]
}

- (dispatch_queue_t)methodQueue
Expand All @@ -160,13 +170,15 @@ - (dispatch_queue_t)methodQueue
window.overrideUserInterfaceStyle = userInterfaceStyle;
}
#else // [macOS
NSAppearance *appearance = nil;
if ([style isEqualToString:@"light"]) {
appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
} else if ([style isEqualToString:@"dark"]) {
appearance = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
}
RCTSharedApplication().appearance = appearance;
RCTExecuteOnMainQueue(^{
NSAppearance *appearance = nil;
if ([style isEqualToString:@"light"]) {
appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
} else if ([style isEqualToString:@"dark"]) {
appearance = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
}
RCTSharedApplication().appearance = appearance;
});
#endif // macOS]
}

Expand All @@ -177,10 +189,7 @@ - (dispatch_queue_t)methodQueue
UITraitCollection *traitCollection = [RCTTraitCollectionProxy sharedInstance].currentTraitCollection;
_currentColorScheme = RCTColorSchemePreference(traitCollection);
#else // [macOS
__block NSAppearance *appearance = nil;
RCTUnsafeExecuteOnMainQueueSync(^{
appearance = RCTKeyWindow().appearance;
});
NSAppearance *appearance = [RCTAppearanceProxy sharedInstance].currentAppearance;
_currentColorScheme = RCTColorSchemePreference(appearance);
#endif // macOS]
}
Expand All @@ -190,23 +199,19 @@ - (dispatch_queue_t)methodQueue

- (void)appearanceChanged:(NSNotification *)notification
{
#if !TARGET_OS_OSX // [macOS
NSDictionary *userInfo = [notification userInfo];
#if !TARGET_OS_OSX // [macOS]
UITraitCollection *traitCollection = nil;
if (userInfo) {
traitCollection = userInfo[RCTUserInterfaceStyleDidChangeNotificationTraitCollectionKey];
}
NSString *newColorScheme = RCTColorSchemePreference(traitCollection);
#else // [macOS
NSAppearance *appearance = nil;
if (userInfo) {
appearance = userInfo[RCTUserInterfaceStyleDidChangeNotificationAppearanceKey];
}
NSString *newColorScheme = RCTColorSchemePreference(appearance);
NSString *newColorScheme = RCTColorSchemePreference([RCTAppearanceProxy sharedInstance].currentAppearance);
#endif // macOS]
if (![_currentColorScheme isEqualToString:newColorScheme]) {
_currentColorScheme = newColorScheme;
[self sendEventWithName:@"appearanceChanged" body:@{@"colorScheme" : newColorScheme}];
[self sendEventWithName:@"appearanceChanged" body:@{ @"colorScheme" : newColorScheme }];
}
}

Expand Down
16 changes: 15 additions & 1 deletion packages/react-native/React/CoreModules/RCTDevLoadingView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo
#if !TARGET_OS_OSX // [macOS]
[self->_window.rootViewController.view addSubview:self->_container];
#else // [macOS
[self->_window.contentViewController.view addSubview:self->_container];
[self->_window.contentView addSubview:self->_container];
#endif // macOS]
[self->_container addSubview:self->_label];

Expand All @@ -175,6 +175,20 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo
[self->_label.bottomAnchor constraintEqualToAnchor:self->_container.bottomAnchor constant:-5],
]];
#else // [macOS
// Container constraints
[NSLayoutConstraint activateConstraints:@[
[self->_container.topAnchor constraintEqualToAnchor:self->_window.contentView.topAnchor],
[self->_container.leadingAnchor constraintEqualToAnchor:self->_window.contentView.leadingAnchor],
[self->_container.trailingAnchor constraintEqualToAnchor:self->_window.contentView.trailingAnchor],
[self->_container.bottomAnchor constraintEqualToAnchor:self->_window.contentView.bottomAnchor],

// Label constraints
[self->_label.centerXAnchor constraintEqualToAnchor:self->_container.centerXAnchor],
[self->_label.centerYAnchor constraintEqualToAnchor:self->_container.centerYAnchor],
[self->_label.leadingAnchor constraintGreaterThanOrEqualToAnchor:self->_container.leadingAnchor constant:10],
[self->_label.trailingAnchor constraintLessThanOrEqualToAnchor:self->_container.trailingAnchor constant:-10],
]];

if (![[RCTKeyWindow() sheets] doesContain:self->_window]) {
[RCTKeyWindow() beginSheet:self->_window completionHandler:^(NSModalResponse returnCode) {
[self->_window orderOut:self];
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native/React/CoreModules/RCTDeviceInfo.mm
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ - (void)observeValueForKeyPath:(NSString *)keyPath

+ (BOOL)requiresMainQueueSetup
{
#if !TARGET_OS_OSX // [macOS]
return NO;
#else // [macOS
return YES;
#endif // macOS]
}

- (dispatch_queue_t)methodQueue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
require_relative '../node_modules/react-native-macos/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
require 'pathname'

ws_dir = Pathname.new(__dir__)
ws_dir = ws_dir.parent until
File.exist?("#{ws_dir}/node_modules/react-native-macos/scripts/react_native_pods.rb") ||
ws_dir.expand_path.to_s == '/'
require "#{ws_dir}/node_modules/react-native-macos/scripts/react_native_pods.rb"

prepare_react_native_project!

target 'HelloWorld-macOS' do
platform :macos, '11.0'
platform :macos, '14.0'
use_native_modules!

# Flags change depending on the env values.
Expand Down
Loading