From 8d1688fd0ee30d53c2e4fe0ac3f39a7b2e125718 Mon Sep 17 00:00:00 2001 From: Thiago Vinhas Date: Wed, 13 May 2026 14:45:28 -0500 Subject: [PATCH] fix(macos): expose React-RCTUIKit module to RCTSwiftUI Swift consumers --- .../ReactApple/RCTSwiftUI/RCTSwiftUI.podspec | 8 ++++++++ .../RCTSwiftUI/RCTSwiftUIContainerView.swift | 15 +++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/react-native/ReactApple/RCTSwiftUI/RCTSwiftUI.podspec b/packages/react-native/ReactApple/RCTSwiftUI/RCTSwiftUI.podspec index 4fae2c71426a..45c1b4c40946 100644 --- a/packages/react-native/ReactApple/RCTSwiftUI/RCTSwiftUI.podspec +++ b/packages/react-native/ReactApple/RCTSwiftUI/RCTSwiftUI.podspec @@ -30,6 +30,14 @@ Pod::Spec.new do |s| s.module_name = "RCTSwiftUI" s.header_dir = "RCTSwiftUI" + # [macOS] Expose the React_RCTUIKit clang module to Swift so + # RCTSwiftUIContainerView.swift can `import React_RCTUIKit` and pick up + # the ObjC `@compatibility_alias RCTUIColor → NSColor` / `RCTPlatformView` + # without re-declaring them as Swift typealiases. The dep is harmless on + # iOS (the umbrella headers are mostly typedef-only there); kept + # unconditional to preserve parity with the rest of the apple pods. + s.dependency "React-RCTUIKit" + # Swift-specific configuration s.pod_target_xcconfig = { "SWIFT_VERSION" => "5.0", diff --git a/packages/react-native/ReactApple/RCTSwiftUI/RCTSwiftUIContainerView.swift b/packages/react-native/ReactApple/RCTSwiftUI/RCTSwiftUIContainerView.swift index 20c64858e79c..52297cec751b 100644 --- a/packages/react-native/ReactApple/RCTSwiftUI/RCTSwiftUIContainerView.swift +++ b/packages/react-native/ReactApple/RCTSwiftUI/RCTSwiftUIContainerView.swift @@ -6,6 +6,17 @@ */ import SwiftUI +// [macOS] Pull in the ObjC @compatibility_alias declarations for +// `RCTPlatformView` (UIView/NSView) and `RCTUIColor` (UIColor/NSColor) +// from RCTUIKit. Without this import the Swift file used to re-declare +// these as local `public typealias`es, which shadowed the ObjC aliases +// and forced every consumer of this module to choose between the Swift +// and ObjC name. After the React-RCTUIKit pod dep is wired in +// RCTSwiftUI.podspec, the import is the canonical source of truth. +// `RCTPlatformHostingController` stays as a Swift typealias below — it +// wraps NSHostingController / UIHostingController which are SwiftUI +// generics and not in the ObjC compat layer. +import React_RCTUIKit #if os(macOS) // [macOS import AppKit #else @@ -13,12 +24,8 @@ import UIKit #endif // macOS] #if os(macOS) // [macOS -public typealias RCTPlatformView = NSView -public typealias RCTUIColor = NSColor public typealias RCTPlatformHostingController = NSHostingController #else -public typealias RCTPlatformView = UIView -public typealias RCTUIColor = UIColor public typealias RCTPlatformHostingController = UIHostingController #endif // macOS]