React Native Brownfield provides first-class support for Swift.
ReactNativeBrownfieldYou can import the object from:
sharedA singleton that keeps an instance of ReactNativeBrownfield object.
| Property | Type | Default | Description |
|---|---|---|---|
entryFile | String | index | Path to JavaScript root. |
fallbackResource | String? | nil | Path to bundle fallback resource. |
bundlePath | String | main.jsbundle | Path to bundle fallback resource. |
bundle | Bundle | Bundle.main | Bundle instance to lookup the JavaScript bundle resource. |
startReactNativeStarts React Native. You can use it to initialize React Native in your app.
| Param | Required | Type | Description |
|---|---|---|---|
onBundleLoaded | No | (() -> Void)? | Callback invoked after JS bundle is fully loaded. |
launchOptions | No | [AnyHashable: Any]? | Launch options, typically passed from AppDelegate. |
Examples:
viewCreates a React Native view for the specified module name.
| Param | Required | Type | Description |
|---|---|---|---|
moduleName | Yes | String | Name of React Native component registered to AppRegistry. |
initialProps | No | [AnyHashable: Any]? | Initial properties to be passed to React Native component. |
launchOptions | No | [AnyHashable: Any]? | Launch options, typically passed from AppDelegate. |
Examples:
React Native Brownfield supports two main approaches for initialization:
To present a React Native view in a UIKit app, use ReactNativeViewController:
To display React Native views in SwiftUI, use the provided ReactNativeView component:
The ReactNativeView component is a SwiftUI wrapper around ReactNativeViewController that handles navigation and lifecycle events automatically.
Both approaches achieve the same result - initializing React Native when your app launches and presenting React Native screens when needed. Choose the approach that best fits your app architecture.
ReactNativeViewControllerA view controller that's rendering React Native view within its bounds. It automatically uses an instance of a factory created in startReactNative method. It works well with exposed JavaScript module. It's the simplest way to embed React Native into your navigation stack.
You can import it from:
ReactNativeViewController(moduleName: moduleName, initialProperties: initialProperties)| Param | Required | Type | Description |
|---|---|---|---|
moduleName | Yes | String | Name of React Native component registered to AppRegistry. |
initialProperties | No | [String: Any]? | Initial properties to be passed to React Native component. |
Examples:
ReactNativeViewA SwiftUI view that wraps the ReactNativeViewController, making it easy to integrate React Native into SwiftUI navigation flows. It automatically handles navigation events like "pop to native" from React Native.
You can import it from:
ReactNativeView(moduleName: moduleName, initialProperties: initialProperties)| Param | Required | Type | Description |
|---|---|---|---|
moduleName | Yes | String | Name of React Native component registered to AppRegistry. |
initialProperties | No | [String: Any] | Initial properties to be passed to React Native component. |
Examples:
Usage with SwiftUI navigation:
You can find an example app here.