react-native icon indicating copy to clipboard operation
react-native copied to clipboard

fix ReactActivity.getReactDelegate().reload()

Open Kudo opened this issue 1 year ago • 3 comments

Summary:

fixing some problem for ReactActivity.getReactDelegate().reload() from #43521:

  • the reload() does not work for bridge mode on release build

Changelog:

[ANDROID] [FIXED] - Fixed app reloading for ReactActivity.getReactDelegate().reload().

Test Plan:

tried to temporary change toast.show as reload and test from rn-tester

--- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/toast/ToastModule.kt
+++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/toast/ToastModule.kt
@@ -10,6 +10,7 @@ package com.facebook.react.modules.toast
 import android.view.Gravity
 import android.widget.Toast
 import com.facebook.fbreact.specs.NativeToastAndroidSpec
+import com.facebook.react.ReactActivity
 import com.facebook.react.bridge.NativeModule
 import com.facebook.react.bridge.ReactApplicationContext
 import com.facebook.react.bridge.UiThreadUtil
@@ -30,9 +31,11 @@ public class ToastModule(reactContext: ReactApplicationContext) :
       )

   override public fun show(message: String?, durationDouble: Double) {
-    val duration = durationDouble.toInt()
-    UiThreadUtil.runOnUiThread(
-        Runnable { Toast.makeText(getReactApplicationContext(), message, duration).show() })
+//    val duration = durationDouble.toInt()
+//    UiThreadUtil.runOnUiThread(
+//        Runnable { Toast.makeText(getReactApplicationContext(), message, duration).show() })
+    val activity = reactApplicationContext.currentActivity as? ReactActivity
+    activity?.reactDelegate?.reload()
   }

   override public fun showWithGravity(

tried for different mode

  • [x] bridge mode + debug build
  • [x] bridgeless mode + debug build
  • [x] bridge mode + release build
  • [x] bridgeless mode + release build

Kudo avatar Apr 23 '24 18:04 Kudo

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 19,411,011 -11
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 22,784,348 +4
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: 849da2146ca27b7512f2f3ea0f8af8aa001e807a Branch: main

analysis-bot avatar Apr 23 '24 19:04 analysis-bot

rebase main since #44227 was landed

Kudo avatar Apr 24 '24 13:04 Kudo

@arushikesarwani94 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Apr 30 '24 22:04 facebook-github-bot

This pull request was successfully merged by @Kudo in 539922339b5ca1937ce3207038199a27566914fe.

When will my fix make it into a release? | How to file a pick request?

github-actions[bot] avatar May 01 '24 22:05 github-actions[bot]

@arushikesarwani94 merged this pull request in facebook/react-native@539922339b5ca1937ce3207038199a27566914fe.

facebook-github-bot avatar May 01 '24 22:05 facebook-github-bot