diff --git a/docs/OBJECTIVE_C.md b/docs/OBJECTIVE_C.md index 89c26cda..8e057795 100644 --- a/docs/OBJECTIVE_C.md +++ b/docs/OBJECTIVE_C.md @@ -30,11 +30,12 @@ Examples: **Properties:** -| Property | Type | Default | Description | -| -------------------------- | ----------------------- | -------------- | -------------------------------------------------- | -| `entryFile` | `NSString` | `index` | Path to JavaScript root. | -| `fallbackResource` | `NSString` | `nil` | Path to bundle fallback resource. | -| `bundlePath` | `NSString` | `main.jsbundle`| Path to bundle fallback resource. | +| Property | Type | Default | Description | +| ------------------ | ---------- | --------------- | --------------------------------------------------------- | +| `entryFile` | `NSString` | `index` | Path to JavaScript root. | +| `fallbackResource` | `NSString` | `nil` | Path to bundle fallback resource. | +| `bundlePath` | `NSString` | `main.jsbundle` | Path to bundle fallback resource. | +| `bundle` | `NSBundle` | `Bundle.main` | Bundle instance to lookup the JavaScript bundle resource. | --- @@ -46,10 +47,10 @@ Starts React Native, produces an instance of React Native. You can use it to ini Params: -| Param | Required | Type | Description | -| ----------------------- | -------- | ----------------- | ----------------------------------------------------- | -| `onBundleLoaded` | No | `void(^)(void)` | Callback invoked after JS bundle is fully loaded. | -| `launchOptions` | No | `NSDictionary` | Launch options, typically passed from AppDelegate. | +| Param | Required | Type | Description | +| ---------------- | -------- | --------------- | -------------------------------------------------- | +| `onBundleLoaded` | No | `void(^)(void)` | Callback invoked after JS bundle is fully loaded. | +| `launchOptions` | No | `NSDictionary` | Launch options, typically passed from AppDelegate. | Examples: @@ -75,11 +76,11 @@ Creates a React Native view for the specified module name. Params: -| Param | Required | Type | Description | -| ----------------------- | -------- | ----------------- | ----------------------------------------------------- | -| `moduleName` | Yes | `NSString` | Name of React Native component registered to `AppRegistry`. | -| `initialProps` | No | `NSDictionary` | Initial properties to be passed to React Native component. | -| `launchOptions` | No | `NSDictionary` | Launch options, typically passed from AppDelegate. | +| Param | Required | Type | Description | +| --------------- | -------- | -------------- | ----------------------------------------------------------- | +| `moduleName` | Yes | `NSString` | Name of React Native component registered to `AppRegistry`. | +| `initialProps` | No | `NSDictionary` | Initial properties to be passed to React Native component. | +| `launchOptions` | No | `NSDictionary` | Launch options, typically passed from AppDelegate. | Examples: @@ -105,10 +106,10 @@ You can import it from: `[ReactNativeViewController initWithModuleName:moduleName andInitialProperties:initialProps]` -| Param | Required | Type | Description | -| --------------------- | --------- | --------------- | ------------------------------------------------------------- | -| `moduleName` | Yes | `NSString` | Name of React Native component registered to `AppRegistry`. | -| `initialProperties` | No | `NSDictionary` | Initial properties to be passed to React Native component. | +| Param | Required | Type | Description | +| ------------------- | -------- | -------------- | ----------------------------------------------------------- | +| `moduleName` | Yes | `NSString` | Name of React Native component registered to `AppRegistry`. | +| `initialProperties` | No | `NSDictionary` | Initial properties to be passed to React Native component. | Examples: @@ -119,4 +120,3 @@ Examples: ```objc [[ReactNativeViewController alloc] initWithModuleName:@"ReactNative" andInitialProperties:@{@"score": @12}] ``` - diff --git a/docs/SWIFT.md b/docs/SWIFT.md index a38bbd1a..06681614 100644 --- a/docs/SWIFT.md +++ b/docs/SWIFT.md @@ -1,6 +1,6 @@ ## Swift -React Native Brownfield provides first-class support for Swift. +React Native Brownfield provides first-class support for Swift. ### API Reference @@ -30,27 +30,27 @@ ReactNativeBrownfield.shared **Properties:** -| 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. | +| 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. | --- **Methods:** - `startReactNative` Starts React Native. You can use it to initialize React Native in your app. Params: -| 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. | +| 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: @@ -76,11 +76,11 @@ Creates a React Native view for the specified module name. Params: -| 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. | +| 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: @@ -105,7 +105,7 @@ import ReactBrownfield class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { ReactNativeBrownfield.shared.startReactNative { print("React Native bundle loaded") @@ -124,7 +124,7 @@ import ReactBrownfield class ViewController: UIViewController { @IBAction func openReactNativeScreen(_ sender: UIButton) { let reactNativeVC = ReactNativeViewController(moduleName: "ReactNative") - + present(reactNativeVC, animated: true) } } @@ -143,7 +143,7 @@ struct MyApp: App { print("React Native bundle loaded") } } - + var body: some Scene { WindowGroup { ContentView() @@ -164,7 +164,7 @@ struct ContentView: View { VStack { Text("Welcome to the Native App") .padding() - + NavigationLink("Push React Native Screen") { ReactNativeView(moduleName: "ReactNative") .navigationBarHidden(true) @@ -197,10 +197,10 @@ import ReactBrownfield `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. | +| 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: @@ -230,10 +230,10 @@ import ReactBrownfield `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. | +| 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: diff --git a/ios/ReactNativeBrownfield.swift b/ios/ReactNativeBrownfield.swift index fb36cb7a..da8b3c40 100644 --- a/ios/ReactNativeBrownfield.swift +++ b/ios/ReactNativeBrownfield.swift @@ -6,6 +6,7 @@ internal import ReactAppDependencyProvider class ReactNativeBrownfieldDelegate: RCTDefaultReactNativeFactoryDelegate { var entryFile = "index" var bundlePath = "main.jsbundle" + var bundle = Bundle.main // MARK: - RCTReactNativeFactoryDelegate Methods override func sourceURL(for bridge: RCTBridge) -> URL? { @@ -21,7 +22,7 @@ class ReactNativeBrownfieldDelegate: RCTDefaultReactNativeFactoryDelegate { let resourceName = withoutLast.joined() let fileExtension = resourceURLComponents.last ?? "" - return Bundle.main.url(forResource: resourceName, withExtension: fileExtension) + return bundle.url(forResource: resourceName, withExtension: fileExtension) #endif } } @@ -54,6 +55,15 @@ class ReactNativeBrownfieldDelegate: RCTDefaultReactNativeFactoryDelegate { delegate.bundlePath = bundlePath } } + /** + * Bundle instance to lookup the JavaScript bundle. + * Default value: Bundle.main + */ + @objc public var bundle: Bundle = Bundle.main { + didSet { + delegate.bundle = bundle + } + } /** * React Native factory instance created when starting React Native. * Default value: nil