diff --git a/.nx/version-plans/version-plan-1792418983966.md b/.nx/version-plans/version-plan-1792418983966.md new file mode 100644 index 00000000..db132a9a --- /dev/null +++ b/.nx/version-plans/version-plan-1792418983966.md @@ -0,0 +1,5 @@ +--- +__default__: patch +--- + +Use @react-native-harness/ui in iOS apps built with React Native SwiftPM integration without a local package patch. diff --git a/packages/ui/Package.swift b/packages/ui/Package.swift new file mode 100644 index 00000000..4d00fdd0 --- /dev/null +++ b/packages/ui/Package.swift @@ -0,0 +1,40 @@ +// swift-tools-version: 6.0 + +import PackageDescription + +// React Native resolves these dependencies from +// build/generated/autolinking/libs/HarnessUI in the app's iOS directory. +let package = Package( + name: "HarnessUI", + platforms: [.iOS("15.1")], + products: [ + .library(name: "HarnessUI", targets: ["HarnessUI"]), + ], + dependencies: [ + .package(name: "ReactNative", path: "../../../../xcframeworks"), + .package(name: "React-GeneratedCode", path: "../../../ios"), + ], + targets: [ + .target( + name: "HarnessUI", + dependencies: [ + .product(name: "ReactHeaders", package: "ReactNative"), + .product(name: "ReactNativeHeaders", package: "ReactNative"), + .product(name: "ReactNativeDependenciesHeaders", package: "ReactNative"), + .product(name: "ReactAppHeaders", package: "React-GeneratedCode"), + ], + path: "ios", + publicHeadersPath: ".", + cxxSettings: [ + .define("DEBUG", .when(configuration: .debug)), + .define("NDEBUG", .when(configuration: .release)), + ], + linkerSettings: [ + .linkedFramework("UIKit"), + .linkedFramework("Foundation"), + .linkedFramework("CoreGraphics"), + ] + ), + ], + cxxLanguageStandard: .cxx20 +) diff --git a/packages/ui/README.md b/packages/ui/README.md index dbe22896..59960a4f 100644 --- a/packages/ui/README.md +++ b/packages/ui/README.md @@ -26,6 +26,13 @@ pnpm add @react-native-harness/ui yarn add @react-native-harness/ui ``` +### iOS with Swift Package Manager + +For apps using React Native's SwiftPM integration, run `npx react-native spm` from +the app directory after installing this package. The package includes the +`HarnessUI` SwiftPM manifest and autolinking metadata; no local manifest patch is +needed. Apps using CocoaPods can continue to use `pod install`. + ## Usage Import the UI testing utilities in your test files: diff --git a/packages/ui/ios/HarnessUI.h b/packages/ui/ios/HarnessUI.h index 3695d1be..2af4af88 100644 --- a/packages/ui/ios/HarnessUI.h +++ b/packages/ui/ios/HarnessUI.h @@ -1,3 +1,5 @@ +#import +#import #import @interface HarnessUI : NSObject diff --git a/packages/ui/package.json b/packages/ui/package.json index b8208733..c9c6ee41 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -11,6 +11,7 @@ "dist", "android", "ios", + "Package.swift", "*.podspec", "react-native.config.js", "!ios/build", @@ -52,6 +53,9 @@ "javaPackageName": "com.harnessui" } }, + "swiftpmConfig": { + "name": "HarnessUI" + }, "author": { "name": "Szymon Chmal", "email": "szymon.chmal@callstack.com" diff --git a/website/src/docs/guides/ui-testing.mdx b/website/src/docs/guides/ui-testing.mdx index 473f0949..0705d992 100644 --- a/website/src/docs/guides/ui-testing.mdx +++ b/website/src/docs/guides/ui-testing.mdx @@ -18,6 +18,8 @@ To enable UI testing in your project, install the UI testing package: +On iOS, resolve native dependencies before rebuilding. For apps using React Native's SwiftPM integration, run `npx react-native spm` from the app directory. `@react-native-harness/ui` ships its own `HarnessUI` package manifest and autolinking metadata. For CocoaPods apps, run `pod install` in the iOS directory. + After installation, **rebuild your app** since this package contains native code that needs to be compiled and linked. ## Screen API