Skip to content

feat(ios): add Swift Package Manager manifest for React Native SwiftPM - #843

Closed
ghultink wants to merge 1 commit into
callstack:mainfrom
ghultink:swiftpm-support
Closed

ghultink wants to merge 1 commit into
callstack:mainfrom
ghultink:swiftpm-support

Conversation

@ghultink

Copy link
Copy Markdown

Summary:

Adds a Package.swift so apps that build iOS with React Native's SwiftPM support (react-native >= 0.87, npx react-native spm) can autolink the slider without scaffolding a manifest from the podspec first. CocoaPods is unaffected; the podspec stays the source of truth there.

Related: #832 proposed the raw react-native spm scaffold output and was closed. This one is hand-written like react-native-safe-area-context's manifest and was built and run, see the test plan.

  • package/Package.swift: one target over ios/ and common/cpp (same files as the podspec and its common subspec), ios/RNCSlider.xcodeproj excluded. The two React Native packages resolve through the autolinker's build/generated/autolinking/libs/react-native-slider alias at app resolve time, so the manifest does not resolve in a bare clone (same as safe-area-context). It carries the compiler flags CocoaPods gives pods through React Native's setup; FOLLY_CFG_NO_COROUTINES=1 is the one that matters, without it folly includes <folly/coro/Coroutine.h>, which the prebuilt React Native headers don't ship.
  • ios/RNCSliderComponentView.mm: two React Native headers are imported by bare name (RCTImagePrimitivesConversions.h, RCTFabricComponentsPlugins.h). CocoaPods resolves that through header maps; SwiftPM only offers them namespaced. Each import now prefers the namespaced header via __has_include and falls back to the old bare import, so the CocoaPods build resolves exactly what it did before.
  • package.json: swiftpmConfig.name. The package has no files list, so Package.swift is published as is.

Test Plan:

Built and run on the iOS simulator with react-native 0.88.0, no CocoaPods, and no scaffold patches for this library:

  1. App on react-native 0.88.0 with @react-native-community/slider 5.2.2 (published; identical to main) plus this Package.swift and .mm.
  2. npx react-native spm scaffold --deintegrate --yes, then xcodebuild for the iOS simulator in Release: BUILD SUCCEEDED. The autolinker logs "Self-managed: react-native-slider (using its own Package.swift)".
  3. In the app the slider renders and is interactive: dragging it moved the value from 50% to 84% and the view it controls resized accordingly.

Not run: the CocoaPods build (by construction the __has_include fallback keeps the old import), macOS/visionOS/Windows.

🤖 Generated with Claude Code

Adds Package.swift so apps that build iOS with React Native's SwiftPM support (react-native >= 0.87, `npx react-native spm`) can autolink the slider without scaffolding a manifest from the podspec. CocoaPods is unaffected: the podspec stays the source of truth there.

Two React Native headers are included by bare name in RNCSliderComponentView.mm; CocoaPods resolves that through header maps, SwiftPM only offers them namespaced. Each include now prefers the namespaced header via __has_include and falls back to the old one, so the CocoaPods build is unchanged.

The two React Native packages resolve through the autolinker's libs/<name> alias at app resolve time, the same shape react-native-safe-area-context ships. Adds `swiftpmConfig.name`.
@ghultink

Copy link
Copy Markdown
Author

Closing: the app that prompted this no longer uses the native slider, so there is no need for a SwiftPM manifest from our side. The notes in the description (React Native's SwiftPM autolinker, the namespaced header includes and the FOLLY_CFG_NO_COROUTINES flag) may still help if you want SwiftPM support, feel free to reuse them.

@ghultink ghultink closed this Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant