Skip to content

Commit 887069c

Browse files
vzaidmanmeta-codesync[bot]
authored andcommitted
sync bundling progress between Metro cli and app hints (facebook#55655)
Summary: Pull Request resolved: facebook#55655 Changelog: [Android][Fixed] sync bundling progress between Metro cli and app hints Reviewed By: cortinico Differential Revision: D93738119
1 parent 8d3f6fa commit 887069c

File tree

6 files changed

+27
-21
lines changed

6 files changed

+27
-21
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,7 +1864,7 @@ public final class com/facebook/react/devsupport/DefaultDevLoadingViewImplementa
18641864
public fun hide ()V
18651865
public fun showMessage (Ljava/lang/String;)V
18661866
public fun showMessage (Ljava/lang/String;Ljava/lang/Double;Ljava/lang/Double;Ljava/lang/Boolean;)V
1867-
public fun updateProgress (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;)V
1867+
public fun updateProgress (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V
18681868
}
18691869

18701870
public final class com/facebook/react/devsupport/DefaultDevLoadingViewImplementation$Companion {
@@ -2108,15 +2108,15 @@ public abstract interface class com/facebook/react/devsupport/interfaces/BundleL
21082108

21092109
public abstract interface class com/facebook/react/devsupport/interfaces/DevBundleDownloadListener {
21102110
public abstract fun onFailure (Ljava/lang/Exception;)V
2111-
public abstract fun onProgress (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;)V
2111+
public abstract fun onProgress (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V
21122112
public abstract fun onSuccess ()V
21132113
}
21142114

21152115
public abstract interface class com/facebook/react/devsupport/interfaces/DevLoadingViewManager {
21162116
public abstract fun hide ()V
21172117
public abstract fun showMessage (Ljava/lang/String;)V
21182118
public abstract fun showMessage (Ljava/lang/String;Ljava/lang/Double;Ljava/lang/Double;Ljava/lang/Boolean;)V
2119-
public abstract fun updateProgress (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;)V
2119+
public abstract fun updateProgress (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V
21202120
}
21212121

21222122
public abstract interface class com/facebook/react/devsupport/interfaces/DevOptionHandler {

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ public class BundleDownloader public constructor(private val client: OkHttpClien
169169
DebugServerException(
170170
("""
171171
Error while reading multipart response.
172-
172+
173173
Response body was empty: ${response.code()}
174-
174+
175175
URL: $url
176-
177-
176+
177+
178178
"""
179179
.trimIndent())
180180
)
@@ -231,7 +231,11 @@ public class BundleDownloader public constructor(private val client: OkHttpClien
231231
if (progress.has("total")) {
232232
total = progress.getInt("total")
233233
}
234-
callback.onProgress(status, done, total)
234+
var percent: Int? = null
235+
if (progress.has("percent")) {
236+
percent = progress.getInt("percent")
237+
}
238+
callback.onProgress(status, done, total, percent)
235239
} catch (e: JSONException) {
236240
FLog.e(ReactConstants.TAG, "Error parsing progress JSON. $e")
237241
}
@@ -248,6 +252,7 @@ public class BundleDownloader public constructor(private val client: OkHttpClien
248252
"Downloading",
249253
(loaded / 1024).toInt(),
250254
(total / 1024).toInt(),
255+
null,
251256
)
252257
}
253258
}
@@ -258,12 +263,12 @@ public class BundleDownloader public constructor(private val client: OkHttpClien
258263
DebugServerException(
259264
("""
260265
Error while reading multipart response.
261-
266+
262267
Response code: ${response.code()}
263-
268+
264269
URL: $url
265-
266-
270+
271+
267272
"""
268273
.trimIndent())
269274
)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ public class DefaultDevLoadingViewImplementation(
5151
}
5252
}
5353

54-
override fun updateProgress(status: String?, done: Int?, total: Int?) {
54+
override fun updateProgress(status: String?, done: Int?, total: Int?, percent: Int?) {
5555
if (!isEnabled) {
5656
return
5757
}
5858
UiThreadUtil.runOnUiThread {
5959
val percentage =
60-
if (done != null && total != null && total > 0)
60+
if (percent != null) String.format(Locale.getDefault(), " %d%%", percent)
61+
else if (done != null && total != null && total > 0)
6162
String.format(Locale.getDefault(), " %.1f%%", done.toFloat() / total * 100)
6263
else ""
6364
devLoadingView?.text =

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,8 @@ public abstract class DevSupportManagerBase(
789789
callback.onSuccess(bundleLoader)
790790
}
791791

792-
override fun onProgress(status: String?, done: Int?, total: Int?) {
793-
devLoadingViewManager?.updateProgress(status, done, total)
792+
override fun onProgress(status: String?, done: Int?, total: Int?, percent: Int?) {
793+
devLoadingViewManager?.updateProgress(status, done, total, percent)
794794
}
795795

796796
override fun onFailure(cause: Exception) {
@@ -856,9 +856,9 @@ public abstract class DevSupportManagerBase(
856856
callback.onSuccess()
857857
}
858858

859-
override fun onProgress(status: String?, done: Int?, total: Int?) {
860-
devLoadingViewManager?.updateProgress(status, done, total)
861-
devBundleDownloadListener?.onProgress(status, done, total)
859+
override fun onProgress(status: String?, done: Int?, total: Int?, percent: Int?) {
860+
devLoadingViewManager?.updateProgress(status, done, total, percent)
861+
devBundleDownloadListener?.onProgress(status, done, total, percent)
862862
}
863863

864864
override fun onFailure(cause: Exception) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package com.facebook.react.devsupport.interfaces
1010
public interface DevBundleDownloadListener {
1111
public fun onSuccess()
1212

13-
public fun onProgress(status: String?, done: Int?, total: Int?)
13+
public fun onProgress(status: String?, done: Int?, total: Int?, percent: Int?)
1414

1515
public fun onFailure(cause: Exception)
1616
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface DevLoadingViewManager {
1818
dismissButton: Boolean?,
1919
)
2020

21-
public fun updateProgress(status: String?, done: Int?, total: Int?)
21+
public fun updateProgress(status: String?, done: Int?, total: Int?, percent: Int?)
2222

2323
public fun hide()
2424
}

0 commit comments

Comments
 (0)