fix(macos): guard iOS-only methods in RCTViewComponentView.mm so the file compiles on macOS#2962
Open
tvinhas wants to merge 1 commit into
Open
Conversation
…file compiles on macOS
|
@tvinhas please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
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
RCTViewComponentView.mmdid not compile on macOS in0.83-merge. The upstream 0.83 merge brought in new iOS-only methods that aren't wrapped in#if !TARGET_OS_OSXguards, leaving them visible to the macOS compile where they tripduplicate-declaration errors against the existing AppKit-flavored methods in the macOS branch + use
UIView/UIColortypes unknown to AppKit.Concrete errors blocking
xcodebuild -scheme RNTester-macOS:RCTViewComponentView.mm:810:3: error: unknown type name 'UIView'; did you mean 'NSView'?
RCTViewComponentView.mm:1048:4: error: expected a type (- (UIView )effectiveContentView)
RCTViewComponentView.mm:1371:11: error: unknown type name 'UIColor'; did you mean 'CIColor'?
RCTViewComponentView.mm:2412:43: error: expected a type (transferVisualPropertiesFromView:(UIView))
RCTViewComponentView.mm:2465:1: error: duplicate declaration of method 'handleCommand:args:'
RCTViewComponentView.mm:2478:1: error: duplicate declaration of method 'focus'
RCTViewComponentView.mm:2483:1: error: duplicate declaration of method 'blur'
RCTViewComponentView.mm:2490:1: error: duplicate declaration of method 'becomeFirstResponder'
RCTViewComponentView.mm:2503:1: error: duplicate declaration of method 'resignFirstResponder'
The macOS branch at lines
1846-2381already provides AppKit-flavored versions offocus,blur,becomeFirstResponder,resignFirstResponder,handleCommand:— the duplicates after that block are iOS-canonical implementationsbrought in by the upstream merge.
This PR is surgical: every change is either (a) wrapping iOS code in
#if !TARGET_OS_OSXso it disappears from the macOS compile, or (b) swappingUIView*/UIColor*types for the existing fork-wideRCTPlatformView*/RCTUIColor*compatibility aliases that resolve to the right AppKit class on macOS. No iOS behavior changes — every iOS code path executes identically before and after.Changes (5 surgical edits)
Line 810 —
hitTest:local var.UIView *currentContainerView→RCTPlatformView *currentContainerView. The getter (currentContainerViewdeclared at 1107) already returnsRCTUIView*which isNSView*on macOS andUIView*on iOS; the local just needed to match.
Lines 1048-1102 —
effectiveContentViewmethod. Return typeUIView*→RCTPlatformView*. Wrapped the SwiftUI-filter body in#if TARGET_OS_OSX ... return self; #else ... <existing body> ... #endif. The SwiftUI-filter wrappinguses
RCTSwiftUIContainerViewWrapperwhich currently assumes UIKit'sUIViewsurface — not yet ported to macOS. macOS falls back to the trivialreturn selfpath (callers continue to work because the type isRCTPlatformView*).Line 1109 —
currentContainerViewcaller.UIView *effectiveContentView = self.effectiveContentView;→RCTPlatformView *effectiveContentView = .... Matches the updated return type from change Update readme #2.Line 1371 — SwiftUI dropShadow color.
UIColor *shadowColor = RCTUIColorFromSharedColor(...)→RCTUIColor *shadowColor = ....RCTUIColoris the existing@compatibility_aliasdefined atReact/RCTUIKit/RCTUIKitCompat.h:25-29(UIColor on iOS, NSColor on macOS).RCTUIColorFromSharedColoralready returns NSColor on macOS, andRCTSwiftUIContainerViewWrapper.hexposes theupdateDropShadow:...color:selector with bothUIColor (iOS) and NSColor (macOS) overloads — the typed alias picks the right one per platform.
Lines 2412-2515 — wrap iOS-only methods in
#if !TARGET_OS_OSX. CoverstransferVisualPropertiesFromView:toView:(UIView-typed args),canBecomeFirstResponder(UIResponder semantics — macOS usesacceptsFirstResponderinstead), and the duplicates of
handleCommand:args:/focus/blur/becomeFirstResponder/resignFirstResponderthat conflict with the AppKit-flavored versions in the macOS branch above.Relationship to other in-flight PRs
pod install+xcodebuildfails atPods/fmt/src/format.ccbefore ever reaching this file on Xcode 26.x.Together, #2961 + this PR + #2959 are the minimum set required for
xcodebuild -scheme RNTester-macOS buildto succeed on0.83-mergefor Xcode 26.x. Without this PR, the file is rejected at the type-check stage and the wholeReact-RCTFabric-macOStarget fails to compile.Closes the macOS-compile half of the "Verify focus changes" + "RNTester validation" items on the Road to 0.83 tracking issue (#2901). With #2960 (pbxproj restore) + this PR + #2961,
xcodebuild ... -scheme RNTester-macOS buildnow completes with
** BUILD SUCCEEDED **.Test Plan
xcodebuild -workspace packages/rn-tester/RNTesterPods.xcworkspace -scheme RNTester-macOS -configuration Debug -destination 'generic/platform=macOS' ARCHS=arm64 ONLY_ACTIVE_ARCH=YES CODE_SIGNING_ALLOWED=NO buildfails atCompileC .../React-RCTFabric-macOS.build/.../RCTViewComponentView.owith the 9+ errors quoted above. Reproducible on a clean0.83-mergecheckout running Xcode 26.x.xcodebuildproduces** BUILD SUCCEEDED **and a runnableBuild/Products/Debug/RNTester-macOS.app. Validated locally with Xcode 26.5 / arm64 / Debug after applying both fix(fmt): patch base.h consteval gate via prepare_command for Xcode 26.x #2961 and this PR.UIView/UIColorforRCTPlatformView/RCTUIColor(compat aliases that resolve identically to the original types on iOS) or moves iOS code inside#if !TARGET_OS_OSX. No iOS codepath is removed; iOS
RNTesterbuild is unaffected.0.83-merge(deprecation notices on AppKit APIs, "build phase runs every build" hints, etc.), unrelated to this change.Related
pod installon0.83-merge)