Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions .github/actions/build-app/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ inputs:
required: false
default: 'true'

ios-package-manager:
description: 'iOS dependency manager (pods or spm)'
required: false
default: 'pods'

platform:
description: 'Platform (example: android or ios))'
required: true
Expand Down Expand Up @@ -82,9 +87,9 @@ runs:
fi

if [[ '${{ inputs.platform }}' == 'ios' ]]; then
# Use xcode 16 for RN 0.80+
# Use Xcode 16.4 for RN 0.80+; macos-15 includes its iOS 18.5 simulator runtime.
if [[ '${{ inputs.rn-ver }}' == "0.8"* || "${{ inputs.rn-ver }}" == "latest" ]]; then
sudo xcode-select --switch /Applications/Xcode_16.2.app/Contents/Developer
sudo xcode-select --switch /Applications/Xcode_16.4.app/Contents/Developer
fi
fi

Expand All @@ -94,11 +99,18 @@ runs:
if [[ '${{ inputs.platform }}' == 'ios' ]]; then
brew install xcbeautify

# Update pods after adding new module
npx pod-install
xcodebuild_container=(-workspace "ios/${APP_NAME}.xcworkspace")
if [[ '${{ inputs.ios-package-manager }}' == 'spm' ]]; then
npx react-native spm add --deintegrate --yes
xcodebuild_container=(-project "ios/${APP_NAME}.xcodeproj")
else
# Update pods after adding new module
npx pod-install
fi

# Build iOS App
xcodebuild -scheme ${{ env.APP_NAME }} -workspace ios/${{ env.APP_NAME }}.xcworkspace -configuration Release -sdk iphonesimulator -destination 'generic/platform=iOS Simulator' | xcbeautify --quiet
set -o pipefail
xcodebuild -scheme "${APP_NAME}" "${xcodebuild_container[@]}" -configuration Release -sdk iphonesimulator -destination 'generic/platform=iOS Simulator' | xcbeautify --quiet

# set output variable
echo "app_path=$(find ~/Library/Developer/Xcode/DerivedData -type d -name "${{ env.APP_NAME }}.app")" >> $GITHUB_OUTPUT
Expand Down
30 changes: 27 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
branches:
- master

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Expand Down Expand Up @@ -73,9 +76,9 @@ jobs:
store-artifacts: true
platform: android

build-ios:
name: Build iOS
runs-on: macos-14
build-ios-pods:
name: Build iOS (CocoaPods)
runs-on: macos-15
strategy:
fail-fast: false
max-parallel: 3
Expand All @@ -92,3 +95,24 @@ jobs:
module-to-install: ${{ github.workspace }}
store-artifacts: true
platform: ios

build-ios-spm:
name: Build iOS (SPM)
runs-on: macos-15
strategy:
fail-fast: false
max-parallel: 3
matrix:
rn_ver: [ latest ] # also, can be any npm tag: 0.71-stable, next, nightly
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: ./.github/actions/build-app
with:
rn-ver: ${{ matrix.rn_ver }}
module-to-install: ${{ github.workspace }}
store-artifacts: false
platform: ios
ios-package-manager: spm
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ android.iml
#
example/ios/Pods

# Swift Package Manager (Package.swift at the repo root)
.build/
.swiftpm/
Package.resolved

# node.js
#
node_modules/
Expand Down
84 changes: 84 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// swift-tools-version: 6.0
/**
* Swift Package Manager support.
*
* This is a hand-maintained ("self-managed") manifest: React Native's SPM
* autolinker sees a checked-in Package.swift and uses it as-is instead of
* generating a wrapper around this package — see `findSelfManagedPackageDir`
* in react-native/scripts/spm/generate-spm-autolinking.js. CocoaPods keeps
* using react-native-image-editor.podspec, so apps on RN < 0.87 are unaffected.
*
* Two contracts the autolinker imposes, both easy to break silently:
*
* 1. The package, its single library product and the target must all be named
* `ImageEditor`. The `swiftpmConfig.name` in package.json pins this name so
* CocoaPods' dashed pod name does not become the SPM product name. The
* aggregator references us as
* `.product(name: "ImageEditor", package: "ImageEditor")`, so renaming any
* of the three fails resolution with "no product named ... available".
*
* 2. The `.package(path:)` references below are constant relative strings, not
* paths to discover at manifest-evaluation time. The autolinker routes this
* package through a symlink at
* `<appRoot>/build/generated/autolinking/libs/ImageEditor`, and SwiftPM
* resolves a manifest's relative package paths against that symlink without
* canonicalizing it, so both packages sit at a fixed depth in every app:
* build/xcframeworks -> ../../../../xcframeworks
* build/generated/ios -> ../../../ios
* That is exactly what react-native/scripts/spm/scaffold-package-swift.js
* emits. Do not replace them with `#filePath` walks or absolute paths.
*
* React headers need no search paths here — they arrive through the products
* listed on the target. `RCTImage` is not a separate product: the React
* xcframework vends RCTImageLoader / RCTImageUtils / RCTConvert flat under the
* `React` module and umbrella, and exports RCTTransformImage et al.
*/

import PackageDescription

let package = Package(
name: "ImageEditor",
platforms: [.iOS(.v15)],
products: [
.library(name: "ImageEditor", targets: ["ImageEditor"]),
],
dependencies: [
.package(name: "ReactNative", path: "../../../../xcframeworks"),
.package(name: "React-GeneratedCode", path: "../../../ios"),
],
targets: [
.target(
name: "ImageEditor",
dependencies: [
.product(name: "ReactHeaders", package: "ReactNative"),
.product(name: "ReactNativeHeaders", package: "ReactNative"),
.product(name: "ReactNativeDependenciesHeaders", package: "ReactNative"),
.product(name: "ReactAppHeaders", package: "React-GeneratedCode"),
],
// Scoped to `ios` so SPM discovers sources itself — a new native
// file needs no manifest edit. `publicHeadersPath: "."` keeps the
// same include surface as CocoaPods (`#import "RNCFileSystem.h"`),
// and keeps SPM's artifacts (.build/, .swiftpm/) out of the source
// dir's way.
path: "ios",
publicHeadersPath: ".",
cxxSettings: [
// DEBUG/NDEBUG must match the prebuilt React.framework's
// config-gated C++ ABI: NDEBUG strips DebugStringConvertible's
// vtable and shifts the ShadowNode layout codegen'd types
// inherit, so a mismatched Release link fails on undefined
// symbols. Mirrors React Native's own SPM manifests.
.define("DEBUG", .when(configuration: .debug)),
.define("NDEBUG", .when(configuration: .release)),
],
linkerSettings: [
.linkedFramework("UIKit"),
.linkedFramework("Foundation"),
.linkedFramework("CoreGraphics"),
]
),
],
// Required by the React headers (concepts, std::optional) and by the
// codegen'd spec this module imports.
cxxLanguageStandard: .cxx20
)
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ npm install @react-native-community/image-editor --save
npx pod-install
```

> [!NOTE]
> **Swift Package Manager** — React Native 0.87+ supports building the iOS side with SPM. Once your app is configured to use React Native's SPM integration, this library's `Package.swift` is picked up by the autolinker automatically. Apps on React Native 0.77–0.86 continue to use CocoaPods through `react-native-image-editor.podspec`, which compiles the same `ios/` sources.

## Usage

Start by importing the library:
Expand Down
6 changes: 6 additions & 0 deletions example/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
approvedGitRepositories:
- "**"

enableScripts: true

npmMinimalAgeGate: 0
Loading
Loading