diff --git a/AGENTS.md b/AGENTS.md index af8ee3c0..9b3d3037 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -70,6 +70,10 @@ Both platforms: `TrueSheetView` (hidden host) → Controller → `ContainerView` 2. Create event class in `ios/events/` and `android/.../events/` 3. Emit from native view +### Adding an iOS source folder + +`RNTrueSheet.podspec` (CocoaPods) and `Package.swift` (SwiftPM) both build `ios/` and `common/cpp/`. CocoaPods flattens headers and SwiftPM does not, so add any new folder that holds headers to `headerSearchPaths` in `Package.swift`. CI only builds CocoaPods, so a missing entry breaks SwiftPM apps silently. + ### Updating the AI skill `skills/truesheet-usage/` is the consumer-facing skill installed via `npx skills add lodev09/react-native-true-sheet`. Whenever docs under `docs/content/docs/next/` change (new prop, event, method, guide, limitation, or troubleshooting entry), update the skill to match in the same PR: diff --git a/CHANGELOG.md b/CHANGELOG.md index c0b51ec5..c13397f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### 🎉 New features + +- **iOS**: Added Swift Package Manager support for apps using React Native's SwiftPM setup (`npx react-native spm`, React Native 0.88 and later). CocoaPods is unchanged. ([#1013](https://github.com/lodev09/react-native-true-sheet/pull/1013) by [@VladyslavMartynov10](https://github.com/VladyslavMartynov10) and [@lodev09](https://github.com/lodev09)) + ### 🐛 Bug fixes - **Android**: A sheet whose keyboard starts rising as the present slide ends, such as one that focuses an input around `onWillPresent`, now finishes presenting. It used to never fire `onDidPresent` or resolve `present()`, and kept swallowing taps. ([#1012](https://github.com/lodev09/react-native-true-sheet/pull/1012) by [@JacquesLeupin](https://github.com/JacquesLeupin)) diff --git a/Package.swift b/Package.swift new file mode 100644 index 00000000..17d49796 --- /dev/null +++ b/Package.swift @@ -0,0 +1,59 @@ +// swift-tools-version: 6.0 + +// Swift Package Manager manifest consumed by React Native's SwiftPM autolinking +// (react-native >= 0.88, `npx react-native spm`). CocoaPods keeps using +// RNTrueSheet.podspec and is unaffected. +// +// The autolinker references this package through a symlink at +// /ios/build/generated/autolinking/libs/RNTrueSheet, and SwiftPM resolves +// the relative `.package(path:)` entries below against that symlink, so they +// point at the app's prebuilt React Native and codegen packages. They do not +// resolve in a bare clone of this repository. + +import PackageDescription + +// CocoaPods flattens a pod's headers into one directory and SwiftPM does not, +// so every folder that holds headers must be listed here. +let headerSearchPaths = ["ios", "ios/core", "ios/events", "ios/utils", "common/cpp"] + +let package = Package( + name: "RNTrueSheet", + platforms: [.iOS("15.1")], + products: [ + .library(name: "RNTrueSheet", targets: ["RNTrueSheet"]), + ], + dependencies: [ + .package(name: "ReactNative", path: "../../../../xcframeworks"), + .package(name: "React-GeneratedCode", path: "../../../ios"), + ], + targets: [ + .target( + name: "RNTrueSheet", + dependencies: [ + .product(name: "ReactHeaders", package: "ReactNative"), + .product(name: "ReactNativeHeaders", package: "ReactNative"), + .product(name: "ReactNativeDependenciesHeaders", package: "ReactNative"), + .product(name: "ReactAppHeaders", package: "React-GeneratedCode"), + ], + path: ".", + // tvOS builds stubs only (see the podspec); SwiftPM autolinking targets iOS. + exclude: ["ios/tvos"], + sources: ["ios", "common/cpp"], + publicHeadersPath: "ios", + cSettings: [.define("RCT_NEW_ARCH_ENABLED", to: "1")] + + headerSearchPaths.map { CSetting.headerSearchPath($0) }, + cxxSettings: [ + .define("RCT_NEW_ARCH_ENABLED", to: "1"), + // Must match the prebuilt React.framework's config-gated C++ ABI. + .define("DEBUG", .when(configuration: .debug)), + .define("NDEBUG", .when(configuration: .release)), + ] + headerSearchPaths.map { CXXSetting.headerSearchPath($0) }, + linkerSettings: [ + .linkedFramework("UIKit"), + .linkedFramework("Foundation"), + .linkedFramework("CoreGraphics"), + ] + ), + ], + cxxLanguageStandard: .cxx20 +) diff --git a/README.md b/README.md index 057971e2..df10a43f 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,8 @@ yarn add @lodev09/react-native-true-sheet cd ios && pod install ``` +On apps using React Native's Swift Package Manager setup (React Native 0.88+), run `npx react-native spm` instead of `pod install`. + ## Documentation - [Example](example) diff --git a/docs/content/docs/next/install.mdx b/docs/content/docs/next/install.mdx index 8d5af9ee..94046ee4 100644 --- a/docs/content/docs/next/install.mdx +++ b/docs/content/docs/next/install.mdx @@ -45,3 +45,5 @@ Then install the native dependencies: ```sh cd ios && pod install ``` + +On apps using React Native's Swift Package Manager setup (React Native 0.88+), run `npx react-native spm` instead of `pod install`. diff --git a/ios/TrueSheetViewController.h b/ios/TrueSheetViewController.h index a4c7c22e..a6647b7a 100644 --- a/ios/TrueSheetViewController.h +++ b/ios/TrueSheetViewController.h @@ -14,6 +14,10 @@ #if __has_include() #import #define RNS_DISMISSIBLE_MODAL_PROTOCOL_AVAILABLE 1 +// SwiftPM does not flatten headers: react-native-screens is exposed under its package paths +#elif __has_include() +#import +#define RNS_DISMISSIBLE_MODAL_PROTOCOL_AVAILABLE 1 #else #define RNS_DISMISSIBLE_MODAL_PROTOCOL_AVAILABLE 0 #endif diff --git a/package.json b/package.json index fb19b3ff..277a5add 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "ios", "common", "*.podspec", + "Package.swift", "react-native.config.js", "!ios/build", "!android/build", @@ -308,5 +309,8 @@ } } } + }, + "swiftpmConfig": { + "name": "RNTrueSheet" } } diff --git a/skills/truesheet-usage/SKILL.md b/skills/truesheet-usage/SKILL.md index 086be933..f5406cf0 100644 --- a/skills/truesheet-usage/SKILL.md +++ b/skills/truesheet-usage/SKILL.md @@ -15,7 +15,7 @@ description: >- Use this skill to produce correct, idiomatic code for apps that consume `@lodev09/react-native-true-sheet` (v4). It covers choosing the right integration pattern, applying the public API correctly, and avoiding platform-specific pitfalls. -Requires React Native >= 0.82 (Expo SDK 55+) with the New Architecture. +Requires React Native >= 0.82 (Expo SDK 55+) with the New Architecture. On iOS it links through CocoaPods (`pod install`) or React Native's Swift Package Manager setup (`npx react-native spm`, RN 0.88+). ## Quick Start