Rock helps you package your React Native code into files that your iOS and Android apps can use. For iOS, it creates a .xcframework file that you can easily add to your app.
To add React Native to your iOS app, we'll package your React Native code into an XCFramework. This way, you don't need to set up Node.js or CocoaPods in your main app.
To make the integration simpler and more powerful, we'll use the React Native Brownfield library.
If you are creating a new Rock project, you can select the brownfield-ios plugin:
to add brownfield capabilities, install dependencies. Then jump to:
If you have an existing Rock project, follow the instructions below.
Open your React Native project's ios/<project_name>.xcworkspace in Xcode
Add a new target by clicking File > New > Target
Choose the Framework template

Give your framework a unique name. You'll use this name when adding it to your main app
Right-click the framework folder and select Convert to Group. CocoaPods doesn't work properly with references. Perform this step for both <FrameworkName> and <FrameworkName>Tests folders.

Set these build settings for your framework:
| Build Setting | Value | What it does |
|---|---|---|
| Build Libraries for Distribution | YES | Creates a module interface for Swift. Also checks if the framework works with your Xcode version. |
| User Script Sandboxing | NO | Lets scripts modify files, which we need to create the JavaScript bundle. |
| Skip Install | NO | Makes sure Xcode creates the framework files we need. |
| Enable Module Verifier | NO | Skips testing the framework during build, which makes builds faster. |
Add your new framework to ios/Podfile:
Bundle React Native code and images step

New Run Script Phase

Bundle React Native code and images$(SRCROOT)/.xcode.env.local$(SRCROOT)/.xcode.envAdd @rock-js/plugin-brownfield-ios to your React Native project
Add this to your rock.config.mjs:
Run the following command in Terminal to compile frameworks for Hermes, React Native Brownfield library, and your app:
If you want to run the React Native app independently from the native iOS app, you'll still need to run the package:ios command and add the ReactBrownfield.xcframework to the project, as instructed in step 7.
Otherwise, the run:ios command will fail with:
Open the .rock/cache/ios/package directory and drag the following files into your app's Xcode project (you can select all at once):

Xcode builds depend on files being referenced in the project file. If you create a new source file without using Xcode, your file is not going to be referenced by the project.
Initialize React Native in AppDelegate.swift and show it using ReactNativeViewController available from React Native Brownfield library:
Instead of using AppDelegate you can also use SceneDelegate
Now that you have everything set up, you can run your app in Debug or Release configuration, and it will display a React Native app we just packaged with package:ios command.
When running in Debug, React Native Brownfield will expect you to run a JS dev server.
You can do so by running start command in your Terminal app:
When running in Release, React Native Brownfield will load the JS bundle (main.jsbundle) directly from the release XCFramework file without requiring you to run any JavaScript tooling.