You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`onBundleLoaded`| No |`void(^)(void)`| Callback invoked after JS bundle is fully loaded. |
91
+
|`launchOptions`| No |`NSDictionary`| Launch options, typically passed from AppDelegate. |
92
92
93
93
Examples:
94
94
@@ -110,7 +110,7 @@ Examples:
110
110
111
111
---
112
112
113
-
#### ReactNativeViewController
113
+
#### `ReactNativeViewController`
114
114
115
115
A 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.
Please reffer to [this issue](https://github.com/facebook/react-native/issues/25349) to learn more about `use_frameworks!` state in React Native.
16
-
17
-
Until this behavior is fixed, you can access `react-native-brownfield` API in Swift via [Bridging Header](../example/swift/BridgingHeader.h).
18
-
19
5
### Linking
20
6
21
7
The library is meant to work with [auto linking](https://github.com/react-native-community/cli/blob/master/docs/autolinking.md). In case you can't use this feature, please check out the following options:
@@ -56,7 +42,7 @@ Click on your main project file (the one that represents the `.xcodeproj`) selec
56
42
57
43
### API Reference
58
44
59
-
#### ReactNativeBrownfield
45
+
#### `ReactNativeBrownfield`
60
46
61
47
You can import the object from:
62
48
@@ -70,7 +56,7 @@ You can import the object from:
70
56
71
57
`shared`
72
58
73
-
A singleton that keeps an instance of ReactNativeBrownfield object.
59
+
A singleton that keeps an instance of `ReactNativeBrownfield` object.
let reactNativeVC =ReactNativeViewController(moduleName: "ReactNative")
144
+
145
+
present(reactNativeVC, animated: true)
146
+
}
147
+
}
148
+
```
149
+
150
+
**2. SwiftUI App Approach (Modern)**
151
+
152
+
```swift
153
+
importSwiftUI
154
+
importReactNativeBrownfield
155
+
156
+
@main
157
+
structMyApp: App {
158
+
init() {
159
+
ReactNativeBrownfield.shared.startReactNative {
160
+
print("React Native bundle loaded")
161
+
}
162
+
}
163
+
164
+
var body: some Scene {
165
+
WindowGroup {
166
+
ContentView()
167
+
}
168
+
}
169
+
}
170
+
```
171
+
172
+
To display React Native views in SwiftUI, use the provided `ReactNativeView` component:
173
+
174
+
```swift
175
+
importSwiftUI
176
+
importReactNativeBrownfield
177
+
178
+
structContentView: View {
179
+
var body: some View {
180
+
NavigationView {
181
+
VStack {
182
+
Text("Welcome to the Native App")
183
+
.padding()
184
+
185
+
NavigationLink("Push React Native Screen") {
186
+
ReactNativeView(moduleName: "ReactNative")
187
+
.navigationBarHidden(true)
188
+
}
189
+
}
190
+
}
191
+
}
192
+
}
193
+
```
194
+
195
+
The `ReactNativeView` component is a SwiftUI wrapper around `ReactNativeViewController` that handles navigation and lifecycle events automatically.
196
+
197
+
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.
198
+
199
+
---
200
+
201
+
#### `ReactNativeViewController`
128
202
129
203
A 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.
|`moduleName`| Yes |`String`| Name of React Native component registered to `AppRegistry`. |
220
+
|`initialProperties`| No |`[String: Any]?`| Initial properties to be passed to React Native component. |
147
221
148
222
Examples:
149
223
@@ -157,6 +231,48 @@ Examples:
157
231
158
232
---
159
233
234
+
#### `ReactNativeView`
235
+
236
+
A 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.
0 commit comments