Skip to content

Commit dee0b6a

Browse files
Saadnajmiclaude
andcommitted
Fix switch shadow node compilation for cross-platform SPM builds
Package.swift's #if os(macOS) runs on the host (always macOS), not the target platform. This meant iOS builds got macOS switch excludes, causing AppKit import errors. Instead of conditionally excluding files in Package.swift, add #if TARGET_OS_OSX guards directly in the .mm files. Both files are now included in all builds but compile to empty on the wrong platform. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e31da84 commit dee0b6a

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

packages/react-native/Package.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,9 @@ let reactCore = RNTarget(
385385
#if os(macOS)
386386
let reactFabricViewPlatformSources = ["components/view/platform/macos"]
387387
let reactFabricViewPlatformExcludes = ["components/view/platform/cxx"]
388-
let reactFabricComponentsSwitchExcludes = ["components/switch/iosswitch/react/renderer/components/switch/IOSSwitchShadowNode.mm"]
389388
#else
390389
let reactFabricViewPlatformExcludes = ["components/view/platform/macos"]
391390
let reactFabricViewPlatformSources = ["components/view/platform/cxx"]
392-
let reactFabricComponentsSwitchExcludes = ["components/switch/iosswitch/react/renderer/components/switch/MacOSSwitchShadowNode.mm"]
393391
#endif
394392
// macOS]
395393
let reactFabric = RNTarget(
@@ -448,7 +446,8 @@ let reactFabricComponents = RNTarget(
448446
"components/view/platform/android",
449447
"components/view/platform/windows",
450448
"components/view/platform/macos",
451-
// "components/switch/iosswitch/.../MacOSSwitchShadowNode.mm" or "IOSSwitchShadowNode.mm" — [macOS] see reactFabricComponentsSwitchExcludes
449+
// [macOS] Both IOSSwitchShadowNode.mm and MacOSSwitchShadowNode.mm are included;
450+
// they use #if TARGET_OS_OSX guards internally so only the correct one compiles.
452451
"components/textinput/platform/android",
453452
"components/text/platform/android",
454453
"components/textinput/platform/macos",
@@ -459,7 +458,7 @@ let reactFabricComponents = RNTarget(
459458
"textlayoutmanager/platform/windows",
460459
"textlayoutmanager/platform/macos",
461460
"conponents/rncore", // this was the old folder where RN Core Components were generated. If you ran codegen in the past, you might have some files in it that might make the build fail.
462-
] + reactFabricComponentsSwitchExcludes, // [macOS]
461+
],
463462
dependencies: [.reactNativeDependencies, .reactCore, .reactJsiExecutor, .reactTurboModuleCore, .jsi, .logger, .reactDebug, .reactFeatureFlags, .reactUtils, .reactRuntimeScheduler, .reactCxxReact, .yoga, .reactRendererDebug, .reactGraphics, .reactFabric, .reactTurboModuleBridging],
464463
sources: ["components/inputaccessory", "components/modal", "components/safeareaview", "components/text", "components/text/platform/cxx", "components/textinput", "components/textinput/platform/ios/", "components/unimplementedview", "components/virtualview", "textlayoutmanager", "textlayoutmanager/platform/ios", "components/switch/iosswitch"]
465464
)

packages/react-native/ReactCommon/react/renderer/components/switch/iosswitch/react/renderer/components/switch/IOSSwitchShadowNode.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
#include <TargetConditionals.h> // [macOS]
9+
#if !TARGET_OS_OSX // [macOS]
10+
811
#import <React/RCTUtils.h>
912
#import <UIKit/UIKit.h>
1013
#include "AppleSwitchShadowNode.h"
@@ -26,3 +29,5 @@
2629
}
2730

2831
} // namespace facebook::react
32+
33+
#endif // !TARGET_OS_OSX [macOS]

packages/react-native/ReactCommon/react/renderer/components/switch/iosswitch/react/renderer/components/switch/MacOSSwitchShadowNode.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
#include <TargetConditionals.h> // [macOS]
9+
#if TARGET_OS_OSX // [macOS]
10+
811
#import <AppKit/AppKit.h>
912
#include "AppleSwitchShadowNode.h"
1013

@@ -30,3 +33,5 @@
3033
}
3134

3235
} // namespace facebook::react
36+
37+
#endif // TARGET_OS_OSX [macOS]

0 commit comments

Comments
 (0)