Skip to content

feat(ios): add Swift Package Manager support - #847

Open
chrfalch wants to merge 1 commit into
callstack:mainfrom
chrfalch:spm-support
Open

chrfalch wants to merge 1 commit into
callstack:mainfrom
chrfalch:spm-support

Conversation

@chrfalch

Copy link
Copy Markdown
Contributor

Overview

React Native 0.88 can link iOS libraries with Swift Package Manager (SwiftPM) instead of CocoaPods. An app in SwiftPM mode cannot use the slider today: the build stops with Package.swift is missing for library "@react-native-community/slider".

This PR adds SwiftPM support in package/. No file under ios/ or common/ changes, and the CocoaPods setup is not touched.

  1. package/Package.swift: the manifest that React Native's SwiftPM autolinking uses.
    • The product is ReactNativeSlider. The podspec name react-native-slider is not a valid Swift identifier, so the SwiftPM name is set explicitly (see item 3).
    • It compiles ios/ and common/cpp/, and excludes the other root entries so SwiftPM does not scan the example or other folders.
    • It defines RCT_NEW_ARCH_ENABLED=1 for C, Objective-C and C++, which CocoaPods gets from install_modules_dependencies.
    • It targets iOS 15.1 only. The podspec also lists visionOS; I left it out because I could not test it.
  2. Header shims, one line each, so the sources compile unchanged:
    • package/include/ReactNativeSlider/: the public headers, each forwarding to the file in ios/.
    • package/spm-headers/: RCTImagePrimitivesConversions.h and RCTFabricComponentsPlugins.h, which the sources import by bare name. They forward to <react/renderer/imagemanager/RCTImagePrimitivesConversions.h> and <React/RCTFabricComponentsPlugins.h>.
  3. package/package.json: sets swiftpmConfig.name to ReactNativeSlider, which React Native 0.88 reads for the SwiftPM product name. The package has no files list, so the new files are published without further changes.

Test Plan

  • New React Native 0.88.0 app, switched to SwiftPM with npx react-native spm add --deintegrate, the slider from this branch.
  • Without this change: Package.swift is missing for library "@react-native-community/slider".
  • With this change: xcodebuild Debug for the iOS Simulator ends with ** BUILD SUCCEEDED **. No warnings come from the manifest.
  • Release build on an iPhone 18 Pro simulator (iOS 27.0): a Slider (0 to 100, value 40) renders with custom track colours, and UIManager.hasViewManagerConfig('RNCSlider') is true.
  • npm pack --dry-run in package/ includes Package.swift, include/ and spm-headers/.
  • Not tested: visionOS, dragging the thumb, and installing from a published npm tarball.

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