SIGN IN SIGN UP
facebook / react-native UNCLAIMED

A framework for building native applications using React

0 0 151 C++

fix ReactActivity.getReactDelegate().reload() (#44223)

Summary:
fixing some problem for `ReactActivity.getReactDelegate().reload()` from https://github.com/facebook/react-native/issues/43521:
- the `reload()` does not work for bridge mode on release build

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

Pull Request resolved: https://github.com/facebook/react-native/pull/44223

Test Plan:
tried to temporary change toast.show as reload and test from rn-tester
```diff
 --- 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

Reviewed By: fkgozali

Differential Revision: D56795975

Pulled By: arushikesarwani94

fbshipit-source-id: 895eab1927ba6db748ebb32c0fd5313f19cf9d1b
K
Kudo Chien committed
56631cd471008c39fe6f771052c3f1af7085bd63
Parent: cc1c697
Committed by Riccardo Cipolleschi <riccardo.cipolleschi@gmail.com> on 5/2/2024, 9:15:59 AM