Skip to content

Commit 08cd3b8

Browse files
committed
load bundle from file
1 parent 3bcfb10 commit 08cd3b8

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactHost.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,10 @@ public interface ReactHost {
189189

190190
/** Remove a listener previously added with [addReactInstanceEventListener]. */
191191
public fun removeReactInstanceEventListener(listener: ReactInstanceEventListener)
192-
192+
193+
/** Sets the source of the bundle to be loaded from the file system. */
194+
public fun setBundleSource(filePath: String)
195+
193196
/**
194197
* Sets the source of the bundle to be loaded from the packager server and updates the packager connection.
195198
*

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public abstract class DevSupportManagerBase(
9191
private val surfaceDelegateFactory: SurfaceDelegateFactory?,
9292
public var devLoadingViewManager: DevLoadingViewManager?,
9393
private var pausedInDebuggerOverlayManager: PausedInDebuggerOverlayManager?,
94+
private var customBundleFilePathField: String? = null
9495
) : DevSupportManager {
9596

9697
public interface CallbackWithBundleLoader {
@@ -129,6 +130,12 @@ public abstract class DevSupportManagerBase(
129130
reloadSettings()
130131
}
131132

133+
override var customBundleFilePath: String?
134+
get() = customBundleFilePathField
135+
set(value) {
136+
customBundleFilePathField = value
137+
}
138+
132139
override val sourceMapUrl: String
133140
get() = jsAppBundleName?.let { devServerHelper.getSourceMapUrl(it) } ?: ""
134141

@@ -547,7 +554,7 @@ public abstract class DevSupportManagerBase(
547554
isEnabled = isEnabled(position)
548555
if (this is TextView) {
549556
setTextColor(
550-
if (isEnabled) android.graphics.Color.WHITE else android.graphics.Color.GRAY
557+
if (isEnabled) android.graphics.Color.BLACK else android.graphics.Color.GRAY
551558
)
552559
}
553560
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/interfaces/DevSupportManager.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public interface DevSupportManager : JSExceptionHandler {
3636
public val currentActivity: Activity?
3737
public val currentReactContext: ReactContext?
3838

39+
public var customBundleFilePath: String?
40+
get() = null
41+
set(_) = Unit
42+
3943
public var devSupportEnabled: Boolean
4044

4145
public fun showNewJavaError(message: String?, e: Throwable)

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,12 @@ public class ReactHostImpl(
646646
}
647647
}
648648

649+
@ThreadConfined(value = ThreadConfined.UI)
650+
override fun setBundleSource(filePath: String) {
651+
devSupportManager.customBundleFilePath = filePath
652+
reload("Change bundle source")
653+
}
654+
649655
@ThreadConfined(value = ThreadConfined.UI)
650656
override fun setBundleSource(debugServerHost: String, moduleName: String, queryBuilder: (Map<String, String>) -> Map<String, String>) {
651657
CoroutineScope(Dispatchers.Default).launch {
@@ -1073,6 +1079,14 @@ public class ReactHostImpl(
10731079
get() {
10741080
stateTracker.enterState("getJSBundleLoader()")
10751081

1082+
if (devSupportManager.customBundleFilePath != null) {
1083+
return try {
1084+
Task.forResult(JSBundleLoader.createFileLoader(devSupportManager.customBundleFilePath!!))
1085+
} catch(e: Exception) {
1086+
Task.forError(e)
1087+
}
1088+
}
1089+
10761090
if (useDevSupport && allowPackagerServerAccess) {
10771091
return isMetroRunning.onSuccessTask(
10781092
{ task ->

0 commit comments

Comments
 (0)