Skip to content

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

Open
chrfalch wants to merge 1 commit into
react-native-datetimepicker:masterfrom
chrfalch:spm-support
Open

chrfalch wants to merge 1 commit into
react-native-datetimepicker:masterfrom
chrfalch:spm-support

Conversation

@chrfalch

Copy link
Copy Markdown

Overview

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

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

  1. Package.swift: the manifest that React Native's SwiftPM autolinking uses.
    • The product is RNDateTimePicker, the same name as the podspec.
    • The target is named RNDateTimePickerTarget and uses ios/ as its path, with publicHeadersPath: ".". With the target named like RNDateTimePicker.h, SwiftPM would treat that header as an umbrella header next to RNDateTimePicker.xcodeproj, so the target name differs from the product name. Apps link the product only.
    • Header search paths for fabric/ and fabric/cpp/ let the existing quoted includes in the Fabric sources resolve without source edits.
    • 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. package.json: adds Package.swift to files, and sets swiftpmConfig.name, which React Native 0.88 reads for the SwiftPM product name.

I saw that an earlier SwiftPM PR (#1068) was closed. This one is limited to the two files above, and I am happy to change it to fit how you want this done.

Test Plan

  • New React Native 0.88.0 app, switched to SwiftPM with npx react-native spm add --deintegrate, datetimepicker from this branch.
  • Without this change: Package.swift is missing for library "@react-native-community/datetimepicker".
  • 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 DateTimePicker with display="inline" and mode="date" shows the native calendar with the set date selected.
  • npm pack --dry-run includes Package.swift.
  • Not tested: visionOS, changing the date by tapping, 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