fix(0.83, RCTUIKit): Extend support to SwiftUI#3006
Merged
Conversation
93d8e7a to
9124597
Compare
tido64
approved these changes
Jul 7, 2026
Saadnajmi
added a commit
to Saadnajmi/react-native-macos
that referenced
this pull request
Jul 7, 2026
PR microsoft#3006 moved the RCTSwiftUI platform types into the React_RCTUIKit Objective-C module via @compatibility_alias. That works for the Obj-C classes (RCTPlatformView -> UI/NSView, RCTPlatformColor -> UI/NSColor), which import into Swift fine, but it silently breaks for the SwiftUI types, so RCTSwiftUI-macOS fails to compile: RCTSwiftUIContainerView.swift: error: cannot find type 'RCTPlatformHostingController' in scope error: cannot find type 'RCTPlatformViewRepresentable' in scope error: cannot find type 'Context' in scope (x2) UI/NSHostingController and UI/NSViewRepresentable are Swift-only SwiftUI types (a generic class and a protocol). An Objective-C @compatibility_alias to them is not imported by Swift's Clang importer (and SwiftUI is not even imported in RCTUIKitCompat.h), so those two aliases resolve to nothing in Swift. The Context errors are secondary: once RCTPlatformViewRepresentable conformance is unknown, its associated Context type can't be resolved either. Fix (keeps microsoft#3006's intent of centralizing the platform types in React_RCTUIKit): - Add RCTUIKitCompat.swift to the React-RCTUIKit pod, declaring RCTPlatformHostingController and RCTPlatformViewRepresentable as Swift typealiases (guarded by #if os(macOS)). The pod now compiles Swift (SWIFT_VERSION) and links SwiftUI, so these types are exported to any module that does `import React_RCTUIKit`. - Remove the two non-functional SwiftUI @compatibility_alias entries from RCTUIKitCompat.h (nothing in Objective-C referenced them) and leave a note explaining why SwiftUI types must be declared in Swift. - Implement RCTPlatformViewWrapper with the concrete UI/NSViewRepresentable requirements (makeUIView/makeNSView + updateUIView/updateNSView); the previous makeRCTPlatformView/updateRCTPlatformView names did not satisfy either protocol. iOS behavior is unchanged (RCTPlatformHostingController -> UIHostingController, RCTPlatformViewRepresentable -> UIViewRepresentable). Validated locally with Xcode 26.4.1: a clean build of the RCTSwiftUI-macOS target and a full `RNTester-macOS` app build (arm64 + x86_64) both succeed. Note: the regressing PR microsoft#3006 merged just before microsoft#3007 ("ci(0.83): run PR checks on merge branch too"), so the merge-branch Build RNTester / macos job was not yet running when microsoft#3006 landed, which is why this compile break was not caught at merge time. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Saadnajmi
added a commit
to Saadnajmi/react-native-macos
that referenced
this pull request
Jul 7, 2026
PR microsoft#3006 moved the RCTSwiftUI platform types into the React_RCTUIKit Objective-C module via @compatibility_alias. That works for the Obj-C classes (RCTPlatformView -> UI/NSView, RCTPlatformColor -> UI/NSColor), which import into Swift fine, but it silently breaks for the SwiftUI types, so RCTSwiftUI-macOS fails to compile: RCTSwiftUIContainerView.swift: error: cannot find type 'RCTPlatformHostingController' in scope error: cannot find type 'RCTPlatformViewRepresentable' in scope error: cannot find type 'Context' in scope (x2) UI/NSHostingController and UI/NSViewRepresentable are Swift-only SwiftUI types (a generic class and a protocol). An Objective-C @compatibility_alias to them is not imported by Swift's Clang importer (and SwiftUI is not even imported in RCTUIKitCompat.h), so those two aliases resolve to nothing in Swift. The Context errors are secondary: once RCTPlatformViewRepresentable conformance is unknown, its associated Context type can't be resolved either. Fix (keeps microsoft#3006's intent of centralizing the platform types in React_RCTUIKit): - Add RCTUIKitCompat.swift to the React-RCTUIKit pod, declaring RCTPlatformHostingController and RCTPlatformViewRepresentable as Swift typealiases (guarded by #if os(macOS)). The pod now compiles Swift (SWIFT_VERSION) and links SwiftUI, so these types are exported to any module that does `import React_RCTUIKit`. - Remove the two non-functional SwiftUI @compatibility_alias entries from RCTUIKitCompat.h (nothing in Objective-C referenced them) and leave a note explaining why SwiftUI types must be declared in Swift. - Implement RCTPlatformViewWrapper with the concrete UI/NSViewRepresentable requirements (makeUIView/makeNSView + updateUIView/updateNSView); the previous makeRCTPlatformView/updateRCTPlatformView names did not satisfy either protocol. iOS behavior is unchanged (RCTPlatformHostingController -> UIHostingController, RCTPlatformViewRepresentable -> UIViewRepresentable). Validated locally with Xcode 26.4.1: a clean build of the RCTSwiftUI-macOS target and a full `RNTester-macOS` app build (arm64 + x86_64) both succeed. Note: the regressing PR microsoft#3006 merged just before microsoft#3007 ("ci(0.83): run PR checks on merge branch too"), so the merge-branch Build RNTester / macos job was not yet running when microsoft#3006 landed, which is why this compile break was not caught at merge time. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Saadnajmi
added a commit
to Saadnajmi/react-native-macos
that referenced
this pull request
Jul 7, 2026
PR microsoft#3006 moved the RCTSwiftUI platform types into the React_RCTUIKit Objective-C module via @compatibility_alias. That works for the Obj-C classes (RCTPlatformView -> UI/NSView, RCTPlatformColor -> UI/NSColor), which import into Swift fine, but it silently breaks for the SwiftUI types, so RCTSwiftUI-macOS fails to compile: RCTSwiftUIContainerView.swift: error: cannot find type 'RCTPlatformHostingController' in scope error: cannot find type 'RCTPlatformViewRepresentable' in scope error: cannot find type 'Context' in scope (x2) UI/NSHostingController and UI/NSViewRepresentable are Swift-only SwiftUI types (a generic class and a protocol). An Objective-C @compatibility_alias to them is not imported by Swift's Clang importer (and SwiftUI is not even imported in RCTUIKitCompat.h), so those two aliases resolve to nothing in Swift. The Context errors are secondary: once RCTPlatformViewRepresentable conformance is unknown, its associated Context type can't be resolved either. Fix (keeps microsoft#3006's intent of centralizing the platform types in React_RCTUIKit): - Add RCTUIKitCompat.swift to the React-RCTUIKit pod, declaring RCTPlatformHostingController and RCTPlatformViewRepresentable as Swift typealiases (guarded by #if os(macOS)). The pod now compiles Swift (SWIFT_VERSION) and links SwiftUI, so these types are exported to any module that does `import React_RCTUIKit`. - Remove the two non-functional SwiftUI @compatibility_alias entries from RCTUIKitCompat.h (nothing in Objective-C referenced them) and leave a note explaining why SwiftUI types must be declared in Swift. - Implement RCTPlatformViewWrapper with the concrete UI/NSViewRepresentable requirements (makeUIView/makeNSView + updateUIView/updateNSView); the previous makeRCTPlatformView/updateRCTPlatformView names did not satisfy either protocol. iOS behavior is unchanged (RCTPlatformHostingController -> UIHostingController, RCTPlatformViewRepresentable -> UIViewRepresentable). Validated locally with Xcode 26.4.1: a clean build of the RCTSwiftUI-macOS target and a full `RNTester-macOS` app build (arm64 + x86_64) both succeed. Note: the regressing PR microsoft#3006 merged just before microsoft#3007 ("ci(0.83): run PR checks on merge branch too"), so the merge-branch Build RNTester / macos job was not yet running when microsoft#3006 landed, which is why this compile break was not caught at merge time. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Saadnajmi
added a commit
to Saadnajmi/react-native-macos
that referenced
this pull request
Jul 7, 2026
PR microsoft#3006 moved the RCTSwiftUI platform types into the React_RCTUIKit Objective-C module via @compatibility_alias. That works for the Obj-C classes (RCTPlatformView -> UI/NSView, RCTPlatformColor -> UI/NSColor), which import into Swift fine, but it silently breaks for the SwiftUI types, so RCTSwiftUI-macOS fails to compile: RCTSwiftUIContainerView.swift: error: cannot find type 'RCTPlatformHostingController' in scope error: cannot find type 'RCTPlatformViewRepresentable' in scope error: cannot find type 'Context' in scope (x2) UI/NSHostingController and UI/NSViewRepresentable are Swift-only SwiftUI types (a generic class and a protocol). An Objective-C @compatibility_alias to them is not imported by Swift's Clang importer (and SwiftUI is not even imported in RCTUIKitCompat.h), so those two aliases resolve to nothing in Swift. The Context errors are secondary: once RCTPlatformViewRepresentable conformance is unknown, its associated Context type can't be resolved either. Fix (keeps microsoft#3006's intent of centralizing the platform types in React_RCTUIKit): - Add RCTUIKitCompat.swift to the React-RCTUIKit pod, which now compiles Swift (SWIFT_VERSION) and links SwiftUI so the types are exported to any module that does `import React_RCTUIKit`. It declares: - RCTPlatformHostingController: a Swift typealias to UI/NSHostingController. - RCTPlatformViewRepresentable: a protocol refining UI/NSViewRepresentable that bridges the platform requirements (makeUIView/makeNSView, etc.) to a unified makeRCTPlatformView/updateRCTPlatformView. A plain typealias can't work here because the two base protocols use different method names, so a conformer named makeRCTPlatformView would satisfy neither. - Remove the two non-functional SwiftUI @compatibility_alias entries from RCTUIKitCompat.h (nothing in Objective-C referenced them). - RCTPlatformViewWrapper now conforms to RCTPlatformViewRepresentable with the unified makeRCTPlatformView/updateRCTPlatformView, so the consumer no longer needs a per-platform #if. iOS behavior is unchanged. Validated locally with Xcode 26.4.1: a clean build of the RCTSwiftUI-macOS target and a full `RNTester-macOS` app build (arm64 + x86_64) both succeed. Note: the regressing PR microsoft#3006 merged just before microsoft#3007 ("ci(0.83): run PR checks on merge branch too"), so the merge-branch Build RNTester / macos job was not yet running when microsoft#3006 landed, which is why this compile break was not caught at merge time. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Saadnajmi
added a commit
to Saadnajmi/react-native-macos
that referenced
this pull request
Jul 7, 2026
PR microsoft#3006 moved the RCTSwiftUI platform types into the React_RCTUIKit Objective-C module via @compatibility_alias. That works for the Obj-C classes (RCTPlatformView -> UI/NSView, RCTPlatformColor -> UI/NSColor), which import into Swift fine, but it silently breaks for the SwiftUI types, so RCTSwiftUI-macOS fails to compile: RCTSwiftUIContainerView.swift: error: cannot find type 'RCTPlatformHostingController' in scope error: cannot find type 'RCTPlatformViewRepresentable' in scope error: cannot find type 'Context' in scope (x2) UI/NSHostingController and UI/NSViewRepresentable are Swift-only SwiftUI types (a generic class and a protocol). An Objective-C @compatibility_alias to them is not imported by Swift's Clang importer (and SwiftUI is not even imported in RCTUIKitCompat.h), so those two aliases resolve to nothing in Swift. The Context errors are secondary: once RCTPlatformViewRepresentable conformance is unknown, its associated Context type can't be resolved either. Fix (keeps microsoft#3006's intent of centralizing the platform types in React_RCTUIKit): - Add RCTUIKitCompat.swift to the React-RCTUIKit pod, which now compiles Swift (SWIFT_VERSION) and links SwiftUI so the types are exported to any module that does `import React_RCTUIKit`. It declares: - RCTPlatformHostingController: a Swift typealias to UI/NSHostingController. - RCTPlatformViewRepresentable: a protocol refining UI/NSViewRepresentable that bridges the platform requirements (makeUIView/makeNSView, etc.) to a unified makeRCTPlatformView/updateRCTPlatformView. A plain typealias can't work here because the two base protocols use different method names, so a conformer named makeRCTPlatformView would satisfy neither. - Remove the two non-functional SwiftUI @compatibility_alias entries from RCTUIKitCompat.h (nothing in Objective-C referenced them). - RCTPlatformViewWrapper now conforms to RCTPlatformViewRepresentable with the unified makeRCTPlatformView/updateRCTPlatformView, so the consumer no longer needs a per-platform #if. iOS behavior is unchanged. Validated locally with Xcode 26.4.1: a clean build of the RCTSwiftUI-macOS target and a full `RNTester-macOS` app build (arm64 + x86_64) both succeed. Note: the regressing PR microsoft#3006 merged just before microsoft#3007 ("ci(0.83): run PR checks on merge branch too"), so the merge-branch Build RNTester / macos job was not yet running when microsoft#3006 landed, which is why this compile break was not caught at merge time. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Saadnajmi
added a commit
to Saadnajmi/react-native-macos
that referenced
this pull request
Jul 7, 2026
PR microsoft#3006 moved the RCTSwiftUI platform types into the React_RCTUIKit Objective-C module via @compatibility_alias. That works for the Obj-C classes (RCTPlatformView -> UI/NSView, RCTPlatformColor -> UI/NSColor), which import into Swift fine, but it silently breaks for the SwiftUI types, so RCTSwiftUI-macOS fails to compile: RCTSwiftUIContainerView.swift: error: cannot find type 'RCTPlatformHostingController' in scope error: cannot find type 'RCTPlatformViewRepresentable' in scope error: cannot find type 'Context' in scope (x2) UI/NSHostingController and UI/NSViewRepresentable are Swift-only SwiftUI types (a generic class and a protocol). An Objective-C @compatibility_alias to them is not imported by Swift's Clang importer (and SwiftUI is not even imported in RCTUIKitCompat.h), so those two aliases resolve to nothing in Swift. The Context errors are secondary: once RCTPlatformViewRepresentable conformance is unknown, its associated Context type can't be resolved either. Fix: - Remove the two non-functional SwiftUI @compatibility_alias entries from RCTUIKitCompat.h (nothing in Objective-C referenced them). - Define RCTPlatformHostingController (a typealias to UI/NSHostingController) and RCTPlatformViewRepresentable (a protocol refining UI/NSViewRepresentable that bridges the platform requirements to a unified makeRCTPlatformView/ updateRCTPlatformView) in the RCTSwiftUI module that consumes them. They would ideally sit with the other RCTPlatform* aliases in React-RCTUIKit, but that module is Objective-C and SwiftPM does not support mixing Objective-C and Swift in one target, so they live in the consuming module for now. iOS behavior is unchanged, and React-RCTUIKit stays Objective-C only so the SwiftPM prebuild is unaffected. Validated locally with Xcode 26.4.1: a clean build of the RCTSwiftUI-macOS target and a full `RNTester-macOS` app build both succeed. Note: the regressing PR microsoft#3006 merged just before microsoft#3007 ("ci(0.83): run PR checks on merge branch too"), so the merge-branch Build RNTester / macos job was not yet running when microsoft#3006 landed, which is why this compile break was not caught at merge time. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Saadnajmi
added a commit
to Saadnajmi/react-native-macos
that referenced
this pull request
Jul 7, 2026
PR microsoft#3006 moved the RCTSwiftUI platform types into the React_RCTUIKit Objective-C module via @compatibility_alias. That works for the Obj-C classes (RCTPlatformView -> UI/NSView, RCTPlatformColor -> UI/NSColor), which import into Swift fine, but it silently breaks for the SwiftUI types, so RCTSwiftUI-macOS fails to compile: RCTSwiftUIContainerView.swift: error: cannot find type 'RCTPlatformHostingController' in scope error: cannot find type 'RCTPlatformViewRepresentable' in scope error: cannot find type 'Context' in scope (x2) UI/NSHostingController and UI/NSViewRepresentable are Swift-only SwiftUI types (a generic class and a protocol). An Objective-C @compatibility_alias to them is not imported by Swift's Clang importer (and SwiftUI is not even imported in RCTUIKitCompat.h), so those two aliases resolve to nothing in Swift. The Context errors are secondary: once RCTPlatformViewRepresentable conformance is unknown, its associated Context type can't be resolved either. Fix: - Remove the two non-functional SwiftUI @compatibility_alias entries from RCTUIKitCompat.h (nothing in Objective-C referenced them). - Define RCTPlatformHostingController (a typealias to UI/NSHostingController) and RCTPlatformViewRepresentable (a protocol refining UI/NSViewRepresentable that bridges the platform requirements to a unified makeRCTPlatformView/ updateRCTPlatformView) in the RCTSwiftUI module that consumes them. They would ideally sit with the other RCTPlatform* aliases in React-RCTUIKit, but that module is Objective-C and SwiftPM does not support mixing Objective-C and Swift in one target, so they live in the consuming module for now. iOS behavior is unchanged, and React-RCTUIKit stays Objective-C only so the SwiftPM prebuild is unaffected. Validated locally with Xcode 26.4.1: a clean build of the RCTSwiftUI-macOS target and a full `RNTester-macOS` app build both succeed. Note: the regressing PR microsoft#3006 merged just before microsoft#3007 ("ci(0.83): run PR checks on merge branch too"), so the merge-branch Build RNTester / macos job was not yet running when microsoft#3006 landed, which is why this compile break was not caught at merge time. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Saadnajmi
added a commit
to Saadnajmi/react-native-macos
that referenced
this pull request
Jul 7, 2026
PR microsoft#3006 moved the RCTSwiftUI platform types into the React_RCTUIKit Objective-C module via @compatibility_alias. That works for the Obj-C classes (RCTPlatformView -> UI/NSView, RCTPlatformColor -> UI/NSColor), which import into Swift fine, but it silently breaks for the SwiftUI types, so RCTSwiftUI-macOS fails to compile: RCTSwiftUIContainerView.swift: error: cannot find type 'RCTPlatformHostingController' in scope error: cannot find type 'RCTPlatformViewRepresentable' in scope error: cannot find type 'Context' in scope (x2) UI/NSHostingController and UI/NSViewRepresentable are Swift-only SwiftUI types (a generic class and a protocol). An Objective-C @compatibility_alias to them is not imported by Swift's Clang importer (and SwiftUI is not even imported in RCTUIKitCompat.h), so those two aliases resolve to nothing in Swift. The Context errors are secondary: once RCTPlatformViewRepresentable conformance is unknown, its associated Context type can't be resolved either. Fix: - Remove the two non-functional SwiftUI @compatibility_alias entries from RCTUIKitCompat.h (nothing in Objective-C referenced them). - Define RCTPlatformHostingController (a typealias to UI/NSHostingController) and RCTPlatformViewRepresentable (a protocol refining UI/NSViewRepresentable that bridges the platform requirements to a unified makeRCTPlatformView/ updateRCTPlatformView) in the RCTSwiftUI module that consumes them. They would ideally sit with the other RCTPlatform* aliases in React-RCTUIKit, but that module is Objective-C and SwiftPM does not support mixing Objective-C and Swift in one target, so they live in the consuming module for now. - Package.swift: make the RCTSwiftUI / RCTSwiftUIWrapper SwiftPM targets depend on React-RCTUIKit. microsoft#3006 added that pod dependency but did not update Package.swift, so `import React_RCTUIKit` failed with "no such module" in the SwiftPM prebuild. iOS behavior is unchanged, and React-RCTUIKit stays Objective-C only so its SwiftPM target is not turned into an unsupported mixed-language target. Validated locally with Xcode 26.4.1: clean builds of the RCTSwiftUI-macOS Pods target and the full RNTester-macOS app, plus the SwiftPM prebuild (`node scripts/ios-prebuild.js -s`/`-b -p macos`) now compiles React_RCTUIKit, RCTSwiftUI and RCTSwiftUIWrapper without the "no such module" error. Note: the regressing PR microsoft#3006 merged just before microsoft#3007 ("ci(0.83): run PR checks on merge branch too"), so the merge-branch Build RNTester / macos job was not yet running when microsoft#3006 landed, which is why this compile break was not caught at merge time. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Followup to #2958 , whose repo is still locked so we can't edit it.
Extend RCTUIKit support to SwiftUI
Test Plan:
CI should pass