Skip to content
Closed
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
1 change: 1 addition & 0 deletions packages/react-native/React/Base/RCTJavaScriptLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ NS_ENUM(NSInteger){
@property (nonatomic, copy) NSString *status;
@property (strong, nonatomic) NSNumber *done;
@property (strong, nonatomic) NSNumber *total;
@property (strong, nonatomic) NSNumber *percent;

@end

Expand Down
8 changes: 6 additions & 2 deletions packages/react-native/React/Base/RCTJavaScriptLoader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ - (NSString *)description
{
NSMutableString *desc = [NSMutableString new];
[desc appendString:_status ?: @"Bundling"];

if ([_total integerValue] > 0 && [_done integerValue] > [_total integerValue]) {
if (_percent != nil) {
[desc appendFormat:@" %ld%%", (long)[_percent integerValue]];
} else if ([_total integerValue] > 0 && [_done integerValue] > [_total integerValue]) {
[desc appendFormat:@" %ld%%", (long)100];
} else if ([_total integerValue] > 0) {
[desc appendFormat:@" %ld%%", (long)(100 * [_done integerValue] / [_total integerValue])];
Expand Down Expand Up @@ -348,6 +349,9 @@ static void attemptAsynchronousLoadOfBundleAtURL(
progress.status = info[@"status"];
progress.done = info[@"done"];
progress.total = info[@"total"];
if (info[@"percent"] != nil) {
progress.percent = info[@"percent"];
}
return progress;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -1864,7 +1864,7 @@ public final class com/facebook/react/devsupport/DefaultDevLoadingViewImplementa
public fun hide ()V
public fun showMessage (Ljava/lang/String;)V
public fun showMessage (Ljava/lang/String;Ljava/lang/Double;Ljava/lang/Double;Ljava/lang/Boolean;)V
public fun updateProgress (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;)V
public fun updateProgress (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V
}

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

public abstract interface class com/facebook/react/devsupport/interfaces/DevBundleDownloadListener {
public abstract fun onFailure (Ljava/lang/Exception;)V
public abstract fun onProgress (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;)V
public abstract fun onProgress (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V
public abstract fun onSuccess ()V
}

public abstract interface class com/facebook/react/devsupport/interfaces/DevLoadingViewManager {
public abstract fun hide ()V
public abstract fun showMessage (Ljava/lang/String;)V
public abstract fun showMessage (Ljava/lang/String;Ljava/lang/Double;Ljava/lang/Double;Ljava/lang/Boolean;)V
public abstract fun updateProgress (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;)V
public abstract fun updateProgress (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V
}

public abstract interface class com/facebook/react/devsupport/interfaces/DevOptionHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ public class BundleDownloader public constructor(private val client: OkHttpClien
DebugServerException(
("""
Error while reading multipart response.

Response body was empty: ${response.code()}

URL: $url


"""
.trimIndent())
)
Expand Down Expand Up @@ -231,7 +231,11 @@ public class BundleDownloader public constructor(private val client: OkHttpClien
if (progress.has("total")) {
total = progress.getInt("total")
}
callback.onProgress(status, done, total)
var percent: Int? = null
if (progress.has("percent")) {
percent = progress.getInt("percent")
}
callback.onProgress(status, done, total, percent)
} catch (e: JSONException) {
FLog.e(ReactConstants.TAG, "Error parsing progress JSON. $e")
}
Expand All @@ -248,6 +252,7 @@ public class BundleDownloader public constructor(private val client: OkHttpClien
"Downloading",
(loaded / 1024).toInt(),
(total / 1024).toInt(),
null,
)
}
}
Expand All @@ -258,12 +263,12 @@ public class BundleDownloader public constructor(private val client: OkHttpClien
DebugServerException(
("""
Error while reading multipart response.

Response code: ${response.code()}

URL: $url


"""
.trimIndent())
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ public class DefaultDevLoadingViewImplementation(
}
}

override fun updateProgress(status: String?, done: Int?, total: Int?) {
override fun updateProgress(status: String?, done: Int?, total: Int?, percent: Int?) {
if (!isEnabled) {
return
}
UiThreadUtil.runOnUiThread {
val percentage =
if (done != null && total != null && total > 0)
if (percent != null) String.format(Locale.getDefault(), " %d%%", percent)
else if (done != null && total != null && total > 0)
String.format(Locale.getDefault(), " %.1f%%", done.toFloat() / total * 100)
else ""
devLoadingView?.text =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,8 +789,8 @@ public abstract class DevSupportManagerBase(
callback.onSuccess(bundleLoader)
}

override fun onProgress(status: String?, done: Int?, total: Int?) {
devLoadingViewManager?.updateProgress(status, done, total)
override fun onProgress(status: String?, done: Int?, total: Int?, percent: Int?) {
devLoadingViewManager?.updateProgress(status, done, total, percent)
}

override fun onFailure(cause: Exception) {
Expand Down Expand Up @@ -856,9 +856,9 @@ public abstract class DevSupportManagerBase(
callback.onSuccess()
}

override fun onProgress(status: String?, done: Int?, total: Int?) {
devLoadingViewManager?.updateProgress(status, done, total)
devBundleDownloadListener?.onProgress(status, done, total)
override fun onProgress(status: String?, done: Int?, total: Int?, percent: Int?) {
devLoadingViewManager?.updateProgress(status, done, total, percent)
devBundleDownloadListener?.onProgress(status, done, total, percent)
}

override fun onFailure(cause: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package com.facebook.react.devsupport.interfaces
public interface DevBundleDownloadListener {
public fun onSuccess()

public fun onProgress(status: String?, done: Int?, total: Int?)
public fun onProgress(status: String?, done: Int?, total: Int?, percent: Int?)

public fun onFailure(cause: Exception)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface DevLoadingViewManager {
dismissButton: Boolean?,
)

public fun updateProgress(status: String?, done: Int?, total: Int?)
public fun updateProgress(status: String?, done: Int?, total: Int?, percent: Int?)

public fun hide()
}
Loading