Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/social-seas-see.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@callstack/react-native-brownfield': minor
---

feat(ios): add bundleURL provider for dynamic bundle loading
13 changes: 7 additions & 6 deletions docs/docs/docs/api-reference/react-native-brownfield/swift.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ 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. |
| `bundle` | `Bundle` | `Bundle.main` | Bundle instance to lookup the JavaScript bundle 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. |
| `bundleURLOverride` | `(() -> URL?)?` | `nil` | Dynamic bundle URL provider called on every bundle load. When set, overrides default behavior. |

---

Expand Down
16 changes: 16 additions & 0 deletions packages/react-native-brownfield/ios/ReactNativeBrownfield.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ class ReactNativeBrownfieldDelegate: RCTDefaultReactNativeFactoryDelegate {
var entryFile = "index"
var bundlePath = "main.jsbundle"
var bundle = Bundle.main
var bundleURLOverride: (() -> URL?)? = nil
// MARK: - RCTReactNativeFactoryDelegate Methods

override func sourceURL(for bridge: RCTBridge) -> URL? {
return bundleURL()
}

public override func bundleURL() -> URL? {
if let bundleURLProvider = bundleURLOverride {
return bundleURLProvider()
}

#if DEBUG
return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: entryFile)
#else
Expand Down Expand Up @@ -64,6 +69,17 @@ class ReactNativeBrownfieldDelegate: RCTDefaultReactNativeFactoryDelegate {
delegate.bundle = bundle
}
}
/**
* Dynamic bundle URL provider called on every bundle load.
* When set, this overrides the default bundleURL() behavior in the delegate.
* Returns a URL to load a custom bundle, or nil to use default behavior.
* Default value: nil
*/
@objc public var bundleURLOverride: (() -> URL?)? = nil {
didSet {
delegate.bundleURLOverride = bundleURLOverride
}
}
/**
* React Native factory instance created when starting React Native.
* Default value: nil
Expand Down