Skip to content

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

Open
chrfalch wants to merge 6 commits into
react-native-menu:masterfrom
chrfalch:spm-support
Open

chrfalch wants to merge 6 commits into
react-native-menu:masterfrom
chrfalch:spm-support

Conversation

@chrfalch

@chrfalch chrfalch commented Nov 3, 2026

Copy link
Copy Markdown

Overview

React Native 0.88 can build apps with Swift Package Manager. React Native 0.89 plans to make it the default. This library has no Package.swift, so SwiftPM apps cannot use it.

  1. Add Package.swift with separate Swift and Objective-C++ targets.
  2. Add swiftpmConfig.name and ship the package support files through npm.
  3. Add a hand-written Swift API header and a compile-time Swift API pin.

Under SwiftPM, the Objective-C++ code cannot import Xcode's generated Swift header. spm-headers/react_native_menu-Swift.h declares the needed Swift API by hand. spm-support/SwiftHeaderPin.swift makes the SwiftPM build fail if the checked Swift API changes. Both files must be updated together.
MenuView.h stays private and is not exposed to other packages.

CocoaPods is unchanged. The podspec and ios/ sources are untouched.

Limits: iOS 15.1 and later. The pin cannot check Objective-C class or member name strings. No CI job here builds the Swift package yet.
Closes #1231.
RFC: react-native-community/discussions-and-proposals#994

Test Plan

How I tested

In a new React Native 0.88.1 app, with the library installed from the local checkout:

npx react-native spm add --deintegrate --yes
npx react-native spm update
xcodebuild -project ios/<App>.xcodeproj -scheme <App> -configuration Debug -destination "generic/platform=iOS Simulator" CODE_SIGNING_ALLOWED=NO build
xcodebuild -project ios/<App>.xcodeproj -scheme <App> -configuration Release -destination "generic/platform=iOS Simulator" CODE_SIGNING_ALLOWED=NO build

Add and update passed. Debug and Release ended with ** BUILD SUCCEEDED **.
Changing onOpenMenu to return Bool in the protocol and both implementations built with the pin removed, then failed in the restored pin. Restoring the API built successfully.
Runtime check: the simulator menu opened with two actions. Selecting First action returned first and showed selected action: first.

@chrfalch
chrfalch requested a review from Naturalclar as a code owner November 3, 2026 16:26
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.

Support Swift Package Manager (React Native 0.87+)

1 participant