Skip to content

Commit 07d6a37

Browse files
atljthymikee
andauthored
feat(ios): allow overriding the bundle instance (#112)
* allow overriding the bundle on ios * docs: add bundle to docs * docs: add objc docs, make values in backticks for consistency --------- Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
1 parent 292b049 commit 07d6a37

3 files changed

Lines changed: 58 additions & 48 deletions

File tree

docs/OBJECTIVE_C.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ Examples:
3030

3131
**Properties:**
3232

33-
| Property | Type | Default | Description |
34-
| -------------------------- | ----------------------- | -------------- | -------------------------------------------------- |
35-
| `entryFile` | `NSString` | `index` | Path to JavaScript root. |
36-
| `fallbackResource` | `NSString` | `nil` | Path to bundle fallback resource. |
37-
| `bundlePath` | `NSString` | `main.jsbundle`| Path to bundle fallback resource. |
33+
| Property | Type | Default | Description |
34+
| ------------------ | ---------- | --------------- | --------------------------------------------------------- |
35+
| `entryFile` | `NSString` | `index` | Path to JavaScript root. |
36+
| `fallbackResource` | `NSString` | `nil` | Path to bundle fallback resource. |
37+
| `bundlePath` | `NSString` | `main.jsbundle` | Path to bundle fallback resource. |
38+
| `bundle` | `NSBundle` | `Bundle.main` | Bundle instance to lookup the JavaScript bundle resource. |
3839

3940
---
4041

@@ -46,10 +47,10 @@ Starts React Native, produces an instance of React Native. You can use it to ini
4647

4748
Params:
4849

49-
| Param | Required | Type | Description |
50-
| ----------------------- | -------- | ----------------- | ----------------------------------------------------- |
51-
| `onBundleLoaded` | No | `void(^)(void)` | Callback invoked after JS bundle is fully loaded. |
52-
| `launchOptions` | No | `NSDictionary` | Launch options, typically passed from AppDelegate. |
50+
| Param | Required | Type | Description |
51+
| ---------------- | -------- | --------------- | -------------------------------------------------- |
52+
| `onBundleLoaded` | No | `void(^)(void)` | Callback invoked after JS bundle is fully loaded. |
53+
| `launchOptions` | No | `NSDictionary` | Launch options, typically passed from AppDelegate. |
5354

5455
Examples:
5556

@@ -75,11 +76,11 @@ Creates a React Native view for the specified module name.
7576

7677
Params:
7778

78-
| Param | Required | Type | Description |
79-
| ----------------------- | -------- | ----------------- | ----------------------------------------------------- |
80-
| `moduleName` | Yes | `NSString` | Name of React Native component registered to `AppRegistry`. |
81-
| `initialProps` | No | `NSDictionary` | Initial properties to be passed to React Native component. |
82-
| `launchOptions` | No | `NSDictionary` | Launch options, typically passed from AppDelegate. |
79+
| Param | Required | Type | Description |
80+
| --------------- | -------- | -------------- | ----------------------------------------------------------- |
81+
| `moduleName` | Yes | `NSString` | Name of React Native component registered to `AppRegistry`. |
82+
| `initialProps` | No | `NSDictionary` | Initial properties to be passed to React Native component. |
83+
| `launchOptions` | No | `NSDictionary` | Launch options, typically passed from AppDelegate. |
8384

8485
Examples:
8586

@@ -105,10 +106,10 @@ You can import it from:
105106

106107
`[ReactNativeViewController initWithModuleName:moduleName andInitialProperties:initialProps]`
107108

108-
| Param | Required | Type | Description |
109-
| --------------------- | --------- | --------------- | ------------------------------------------------------------- |
110-
| `moduleName` | Yes | `NSString` | Name of React Native component registered to `AppRegistry`. |
111-
| `initialProperties` | No | `NSDictionary` | Initial properties to be passed to React Native component. |
109+
| Param | Required | Type | Description |
110+
| ------------------- | -------- | -------------- | ----------------------------------------------------------- |
111+
| `moduleName` | Yes | `NSString` | Name of React Native component registered to `AppRegistry`. |
112+
| `initialProperties` | No | `NSDictionary` | Initial properties to be passed to React Native component. |
112113

113114
Examples:
114115

@@ -119,4 +120,3 @@ Examples:
119120
```objc
120121
[[ReactNativeViewController alloc] initWithModuleName:@"ReactNative" andInitialProperties:@{@"score": @12}]
121122
```
122-

docs/SWIFT.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Swift
22

3-
React Native Brownfield provides first-class support for Swift.
3+
React Native Brownfield provides first-class support for Swift.
44

55
### API Reference
66

@@ -30,27 +30,27 @@ ReactNativeBrownfield.shared
3030

3131
**Properties:**
3232

33-
| Property | Type | Default | Description |
34-
| -------------------------- | ----------------------- | -------------- | -------------------------------------------------- |
35-
| `entryFile` | `String` | index | Path to JavaScript root. |
36-
| `fallbackResource` | `String?` | nil | Path to bundle fallback resource. |
37-
| `bundlePath` | `String` | main.jsbundle | Path to bundle fallback resource. |
33+
| Property | Type | Default | Description |
34+
| ------------------ | --------- | --------------- | --------------------------------------------------------- |
35+
| `entryFile` | `String` | `index` | Path to JavaScript root. |
36+
| `fallbackResource` | `String?` | `nil` | Path to bundle fallback resource. |
37+
| `bundlePath` | `String` | `main.jsbundle` | Path to bundle fallback resource. |
38+
| `bundle` | `Bundle` | `Bundle.main` | Bundle instance to lookup the JavaScript bundle resource. |
3839

3940
---
4041

4142
**Methods:**
4243

43-
4444
`startReactNative`
4545

4646
Starts React Native. You can use it to initialize React Native in your app.
4747

4848
Params:
4949

50-
| Param | Required | Type | Description |
51-
| ----------------------- | -------- | ------------------- | ----------------------------------------------------- |
52-
| `onBundleLoaded` | No | `(() -> Void)?` | Callback invoked after JS bundle is fully loaded. |
53-
| `launchOptions` | No | `[AnyHashable: Any]?` | Launch options, typically passed from AppDelegate. |
50+
| Param | Required | Type | Description |
51+
| ---------------- | -------- | --------------------- | -------------------------------------------------- |
52+
| `onBundleLoaded` | No | `(() -> Void)?` | Callback invoked after JS bundle is fully loaded. |
53+
| `launchOptions` | No | `[AnyHashable: Any]?` | Launch options, typically passed from AppDelegate. |
5454

5555
Examples:
5656

@@ -76,11 +76,11 @@ Creates a React Native view for the specified module name.
7676

7777
Params:
7878

79-
| Param | Required | Type | Description |
80-
| ----------------------- | -------- | ------------------- | ----------------------------------------------------- |
81-
| `moduleName` | Yes | `String` | Name of React Native component registered to `AppRegistry`. |
82-
| `initialProps` | No | `[AnyHashable: Any]?` | Initial properties to be passed to React Native component. |
83-
| `launchOptions` | No | `[AnyHashable: Any]?` | Launch options, typically passed from AppDelegate. |
79+
| Param | Required | Type | Description |
80+
| --------------- | -------- | --------------------- | ----------------------------------------------------------- |
81+
| `moduleName` | Yes | `String` | Name of React Native component registered to `AppRegistry`. |
82+
| `initialProps` | No | `[AnyHashable: Any]?` | Initial properties to be passed to React Native component. |
83+
| `launchOptions` | No | `[AnyHashable: Any]?` | Launch options, typically passed from AppDelegate. |
8484

8585
Examples:
8686

@@ -105,7 +105,7 @@ import ReactBrownfield
105105

106106
class AppDelegate: UIResponder, UIApplicationDelegate {
107107
var window: UIWindow?
108-
108+
109109
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
110110
ReactNativeBrownfield.shared.startReactNative {
111111
print("React Native bundle loaded")
@@ -124,7 +124,7 @@ import ReactBrownfield
124124
class ViewController: UIViewController {
125125
@IBAction func openReactNativeScreen(_ sender: UIButton) {
126126
let reactNativeVC = ReactNativeViewController(moduleName: "ReactNative")
127-
127+
128128
present(reactNativeVC, animated: true)
129129
}
130130
}
@@ -143,7 +143,7 @@ struct MyApp: App {
143143
print("React Native bundle loaded")
144144
}
145145
}
146-
146+
147147
var body: some Scene {
148148
WindowGroup {
149149
ContentView()
@@ -164,7 +164,7 @@ struct ContentView: View {
164164
VStack {
165165
Text("Welcome to the Native App")
166166
.padding()
167-
167+
168168
NavigationLink("Push React Native Screen") {
169169
ReactNativeView(moduleName: "ReactNative")
170170
.navigationBarHidden(true)
@@ -197,10 +197,10 @@ import ReactBrownfield
197197

198198
`ReactNativeViewController(moduleName: moduleName, initialProperties: initialProperties)`
199199

200-
| Param | Required | Type | Description |
201-
| ------------------ | --------- | --------------- | ------------------------------------------------------------- |
202-
| `moduleName` | Yes | `String` | Name of React Native component registered to `AppRegistry`. |
203-
| `initialProperties`| No | `[String: Any]?`| Initial properties to be passed to React Native component. |
200+
| Param | Required | Type | Description |
201+
| ------------------- | -------- | ---------------- | ----------------------------------------------------------- |
202+
| `moduleName` | Yes | `String` | Name of React Native component registered to `AppRegistry`. |
203+
| `initialProperties` | No | `[String: Any]?` | Initial properties to be passed to React Native component. |
204204

205205
Examples:
206206

@@ -230,10 +230,10 @@ import ReactBrownfield
230230

231231
`ReactNativeView(moduleName: moduleName, initialProperties: initialProperties)`
232232

233-
| Param | Required | Type | Description |
234-
| ------------------- | --------- | -------------- | ------------------------------------------------------------- |
235-
| `moduleName` | Yes | `String` | Name of React Native component registered to `AppRegistry`. |
236-
| `initialProperties` | No | `[String: Any]`| Initial properties to be passed to React Native component. |
233+
| Param | Required | Type | Description |
234+
| ------------------- | -------- | --------------- | ----------------------------------------------------------- |
235+
| `moduleName` | Yes | `String` | Name of React Native component registered to `AppRegistry`. |
236+
| `initialProperties` | No | `[String: Any]` | Initial properties to be passed to React Native component. |
237237

238238
Examples:
239239

ios/ReactNativeBrownfield.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ internal import ReactAppDependencyProvider
66
class ReactNativeBrownfieldDelegate: RCTDefaultReactNativeFactoryDelegate {
77
var entryFile = "index"
88
var bundlePath = "main.jsbundle"
9+
var bundle = Bundle.main
910
// MARK: - RCTReactNativeFactoryDelegate Methods
1011

1112
override func sourceURL(for bridge: RCTBridge) -> URL? {
@@ -21,7 +22,7 @@ class ReactNativeBrownfieldDelegate: RCTDefaultReactNativeFactoryDelegate {
2122
let resourceName = withoutLast.joined()
2223
let fileExtension = resourceURLComponents.last ?? ""
2324

24-
return Bundle.main.url(forResource: resourceName, withExtension: fileExtension)
25+
return bundle.url(forResource: resourceName, withExtension: fileExtension)
2526
#endif
2627
}
2728
}
@@ -54,6 +55,15 @@ class ReactNativeBrownfieldDelegate: RCTDefaultReactNativeFactoryDelegate {
5455
delegate.bundlePath = bundlePath
5556
}
5657
}
58+
/**
59+
* Bundle instance to lookup the JavaScript bundle.
60+
* Default value: Bundle.main
61+
*/
62+
@objc public var bundle: Bundle = Bundle.main {
63+
didSet {
64+
delegate.bundle = bundle
65+
}
66+
}
5767
/**
5868
* React Native factory instance created when starting React Native.
5969
* Default value: nil

0 commit comments

Comments
 (0)