From 6920b65b9d66fa1fff62f974623f70b39bed71ad Mon Sep 17 00:00:00 2001 From: Jason Morse Date: Fri, 13 Nov 2026 01:45:33 +0000 Subject: [PATCH 1/2] fix(0.83, view): bridge safe-area inset changes on macOS Supply the missing UIKit-compatible callback and deliver it after actual AppKit inset changes. This separately fixes the initializer CI failure in react-native-safe-area-context without disabling that dependency or its assertions. Both registered native regressions pass; iOS remains on UIKit. This layer is based on the separate native test-host repair. The renderer synchronization fix remains a separate top layer. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 33ea5c72-8bbd-448d-aa21-c9b99dd03c96 --- .changeset/safe-area-callback.md | 7 ++ .../ReactApple/Libraries/RCTUIKit/RCTUIView.h | 2 + .../ReactApple/Libraries/RCTUIKit/RCTUIView.m | 18 ++++ .../RNTesterUnitTests_macOS.m | 86 +++++++++++++++---- .../RNTesterPods.xcodeproj/project.pbxproj | 4 + 5 files changed, 99 insertions(+), 18 deletions(-) create mode 100644 .changeset/safe-area-callback.md diff --git a/.changeset/safe-area-callback.md b/.changeset/safe-area-callback.md new file mode 100644 index 000000000000..ff042a7c0c16 --- /dev/null +++ b/.changeset/safe-area-callback.md @@ -0,0 +1,7 @@ +--- +"react-native-macos": patch +--- + + + +Bridge AppKit safe-area changes to the UIKit-compatible view callback used by Fabric components. diff --git a/packages/react-native/ReactApple/Libraries/RCTUIKit/RCTUIView.h b/packages/react-native/ReactApple/Libraries/RCTUIKit/RCTUIView.h index 76a97c0994da..d9b290958bf4 100644 --- a/packages/react-native/ReactApple/Libraries/RCTUIKit/RCTUIView.h +++ b/packages/react-native/ReactApple/Libraries/RCTUIKit/RCTUIView.h @@ -52,6 +52,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)layoutSubviews; +- (void)safeAreaInsetsDidChange; + - (void)setNeedsDisplay; @property (nonatomic, copy) NSColor *backgroundColor; diff --git a/packages/react-native/ReactApple/Libraries/RCTUIKit/RCTUIView.m b/packages/react-native/ReactApple/Libraries/RCTUIKit/RCTUIView.m index 19528853dd6e..be9f8e3b85d8 100644 --- a/packages/react-native/ReactApple/Libraries/RCTUIKit/RCTUIView.m +++ b/packages/react-native/ReactApple/Libraries/RCTUIKit/RCTUIView.m @@ -24,6 +24,7 @@ @implementation RCTUIView BOOL _respondsToDisplayLayer; CATransform3D _transform3D; BOOL _hasCustomTransform3D; + NSEdgeInsets _lastSafeAreaInsets; } + (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key @@ -60,6 +61,17 @@ @implementation RCTUIView return self; } +static void RCTUIViewUpdateSafeAreaInsets(RCTUIView *self) +{ + if (@available(macOS 11.0, *)) { + NSEdgeInsets insets = self.safeAreaInsets; + if (!NSEdgeInsetsEqual(insets, self->_lastSafeAreaInsets)) { + self->_lastSafeAreaInsets = insets; + [self safeAreaInsetsDidChange]; + } + } +} + - (instancetype)initWithFrame:(NSRect)frameRect { return RCTUIViewCommonInit([super initWithFrame:frameRect]); @@ -99,6 +111,7 @@ - (BOOL)isFirstResponder { - (void)viewDidMoveToWindow { [self didMoveToWindow]; + RCTUIViewUpdateSafeAreaInsets(self); } - (BOOL)mouseDownCanMoveWindow{ @@ -209,6 +222,7 @@ - (void)layout { [super layout]; if (self.window != nil) { + RCTUIViewUpdateSafeAreaInsets(self); [self layoutSubviews]; } } @@ -281,6 +295,10 @@ - (void)layoutSubviews [super layout]; } +- (void)safeAreaInsetsDidChange +{ +} + - (void)setNeedsDisplay { self.needsDisplay = YES; diff --git a/packages/rn-tester/RNTester-macOSUnitTests/RNTesterUnitTests_macOS.m b/packages/rn-tester/RNTester-macOSUnitTests/RNTesterUnitTests_macOS.m index 7d7bfd4d574a..154bda5a3c29 100644 --- a/packages/rn-tester/RNTester-macOSUnitTests/RNTesterUnitTests_macOS.m +++ b/packages/rn-tester/RNTester-macOSUnitTests/RNTesterUnitTests_macOS.m @@ -6,36 +6,86 @@ // Copyright © 2017 Facebook. All rights reserved. // +// [macOS] + +#import #import +@interface RCTSafeAreaObservingView : RCTUIView +@property (nonatomic, assign) NSUInteger safeAreaChangeCount; +@property (nonatomic, assign) NSEdgeInsets observedSafeAreaInsets; +@end + +@implementation RCTSafeAreaObservingView + +- (void)safeAreaInsetsDidChange +{ + [super safeAreaInsetsDidChange]; + self.safeAreaChangeCount++; + self.observedSafeAreaInsets = self.safeAreaInsets; +} + +@end + +static void RCTPerformOnMainThread(dispatch_block_t block) +{ + if (NSThread.isMainThread) { + block(); + } else { + dispatch_sync(dispatch_get_main_queue(), block); + } +} + @interface RNTesterUnitTests_macOS : XCTestCase @end @implementation RNTesterUnitTests_macOS -- (void)setUp +- (void)testSafeAreaCallbackSupportsSuperclassCalls { - [super setUp]; - // Put setup code here. This method is called before the invocation of each test method in the class. + RCTPerformOnMainThread(^{ + [NSApplication sharedApplication]; + RCTSafeAreaObservingView *view = [RCTSafeAreaObservingView new]; + XCTAssertNoThrow([view safeAreaInsetsDidChange]); + XCTAssertEqual(view.safeAreaChangeCount, 1u); + }); } -- (void)tearDown +- (void)testLayoutReportsChangedSafeAreaInsetsOnce { - // Put teardown code here. This method is called after the invocation of each test method in the class. - [super tearDown]; -} + RCTPerformOnMainThread(^{ + [NSApplication sharedApplication]; + NSWindow *window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 400, 300) + styleMask:NSWindowStyleMaskBorderless + backing:NSBackingStoreBuffered + defer:NO]; + window.releasedWhenClosed = NO; + @try { + RCTSafeAreaObservingView *view = [[RCTSafeAreaObservingView alloc] initWithFrame:window.contentView.bounds]; + window.contentView = view; + [view layoutSubtreeIfNeeded]; + NSUInteger originalCount = view.safeAreaChangeCount; -//- (void)testFunctionalExample { -// // This is an example of a functional test case. -// // Use XCTAssert and related functions to verify your tests produce the correct results. -//} -// -//- (void)testPerformanceExample { -// // This is an example of a performance test case. -// [self measureBlock:^{ -// // Put the code you want to measure the time of here. -// }]; -//} + view.additionalSafeAreaInsets = NSEdgeInsetsMake(5, 7, 11, 13); + view.needsLayout = YES; + [view layoutSubtreeIfNeeded]; + XCTAssertEqual(view.safeAreaChangeCount, originalCount + 1); + XCTAssertTrue(NSEdgeInsetsEqual(view.observedSafeAreaInsets, view.safeAreaInsets)); + + view.needsLayout = YES; + [view layoutSubtreeIfNeeded]; + XCTAssertEqual(view.safeAreaChangeCount, originalCount + 1); + + view.additionalSafeAreaInsets = NSEdgeInsetsMake(7, 11, 13, 17); + view.needsLayout = YES; + [view layoutSubtreeIfNeeded]; + XCTAssertEqual(view.safeAreaChangeCount, originalCount + 2); + XCTAssertTrue(NSEdgeInsetsEqual(view.observedSafeAreaInsets, view.safeAreaInsets)); + } @finally { + [window close]; + } + }); +} @end diff --git a/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj b/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj index e033f51a8a71..fb64f9d0a93e 100644 --- a/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj +++ b/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + D5E7A8F02FF0010100000002 /* RNTesterUnitTests_macOS.m in Sources */ = {isa = PBXBuildFile; fileRef = D5E7A8F02FF0010100000001 /* RNTesterUnitTests_macOS.m */; }; /* [macOS] */ 08E25EBE4A584CD7B70FBB1E /* libPods-RNTester.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D74056A5352F0925816E50E0 /* libPods-RNTester.a */; }; 0CBC915D60C701A81731A5A4 /* libPods-RNTester-macOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C88AE81E635231C7F0F3BA4 /* libPods-RNTester-macOS.a */; }; 0E3E8DF4F87D07566A9489D4 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = AC276E71CF27E40DFA22979F /* PrivacyInfo.xcprivacy */; }; @@ -143,6 +144,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + D5E7A8F02FF0010100000001 /* RNTesterUnitTests_macOS.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNTesterUnitTests_macOS.m; sourceTree = ""; }; /* [macOS] */ 07517909E4081E5D74D5DD60 /* libPods-RNTester-macOSUnitTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RNTester-macOSUnitTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 086F285685A842F5E52B6F9C /* Pods-RNTester-visionOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNTester-visionOS.debug.xcconfig"; path = "Target Support Files/Pods-RNTester-visionOS/Pods-RNTester-visionOS.debug.xcconfig"; sourceTree = ""; }; 0EA618022BE537D3001875EF /* RNTesterBundle.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; name = RNTesterBundle.bundle; path = RNTester/RNTesterBundle.bundle; sourceTree = ""; }; @@ -465,6 +467,7 @@ ACC52F56299ECB8A002A2B0B /* RNTester-macOSUnitTests */ = { isa = PBXGroup; children = ( + D5E7A8F02FF0010100000001 /* RNTesterUnitTests_macOS.m */, /* [macOS] */ 24C6EA492D04BAF1008C8E31 /* RCTFrameTimingsObserverTests.mm */, ); path = "RNTester-macOSUnitTests"; @@ -1293,6 +1296,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + D5E7A8F02FF0010100000002 /* RNTesterUnitTests_macOS.m in Sources */, /* [macOS] */ 24C6EA4A2D04BAF1008C8E31 /* RCTFrameTimingsObserverTests.mm in Sources */, AC73FCEF29B1318B0003586F /* RCTAnimationUtilsTests.m in Sources */, AC73FD0729B131DA0003586F /* RCTUIManagerTests.m in Sources */, From a1de6d100067cbf6b8e7cbad929195627431dbc3 Mon Sep 17 00:00:00 2001 From: Jason Morse Date: Fri, 13 Nov 2026 02:41:12 +0000 Subject: [PATCH 2/2] fix(0.83, init): initialize Swift template properties before super After the safe-area compiler blocker is removed, initializer CI reaches a pre-existing Swift definite-initialization error. Assign both immutable stored properties before NSObject.init; do not make them mutable or weaken validation. The exact extracted template class fails actual compilation before this change and passes afterward. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 33ea5c72-8bbd-448d-aa21-c9b99dd03c96 --- .changeset/safe-area-callback.md | 2 ++ .../templates/macos/HelloWorld-macOS/AppDelegate.swift | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.changeset/safe-area-callback.md b/.changeset/safe-area-callback.md index ff042a7c0c16..10d41319753f 100644 --- a/.changeset/safe-area-callback.md +++ b/.changeset/safe-area-callback.md @@ -5,3 +5,5 @@ Bridge AppKit safe-area changes to the UIKit-compatible view callback used by Fabric components. + +Initialize the generated Swift AppDelegate's stored properties before calling its superclass initializer. diff --git a/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/AppDelegate.swift b/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/AppDelegate.swift index 1a9040193722..65c55c8b53b1 100644 --- a/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/AppDelegate.swift +++ b/packages/react-native/local-cli/generator-macos/templates/macos/HelloWorld-macOS/AppDelegate.swift @@ -1,3 +1,5 @@ +// [macOS] + import SwiftUI import React import React_RCTAppDelegate @@ -22,14 +24,13 @@ class AppDelegate: NSObject, NSApplicationDelegate { let reactNativeFactory: RCTReactNativeFactory override init() { - super.init() - let delegate = ReactNativeDelegate() let factory = RCTReactNativeFactory(delegate: delegate) delegate.dependencyProvider = RCTAppDependencyProvider() reactNativeDelegate = delegate reactNativeFactory = factory + super.init() } }