5
5
import android .os .AsyncTask ;
6
6
import android .os .Handler ;
7
7
import android .os .Looper ;
8
- import android .provider .Settings ;
9
8
import android .view .View ;
10
9
11
10
import com .facebook .react .ReactApplication ;
22
21
import com .facebook .react .bridge .ReactMethod ;
23
22
import com .facebook .react .bridge .ReadableMap ;
24
23
import com .facebook .react .bridge .WritableMap ;
24
+ import com .facebook .react .devsupport .interfaces .DevSupportManager ;
25
25
import com .facebook .react .modules .core .ChoreographerCompat ;
26
26
import com .facebook .react .modules .core .DeviceEventManagerModule ;
27
27
import com .facebook .react .modules .core .ReactChoreographer ;
36
36
import java .util .ArrayList ;
37
37
import java .util .Date ;
38
38
import java .util .HashMap ;
39
- import java .util .List ;
40
39
import java .util .Map ;
41
40
import java .util .UUID ;
42
41
@@ -166,6 +165,9 @@ public void run() {
166
165
if (reactDelegate == null ) {
167
166
throw new NoSuchMethodException ("ReactDelegate doesn't have reload method in RN < 0.74" );
168
167
}
168
+
169
+ resetReactRootViewsIfDebug (instanceManager , reactDelegate );
170
+
169
171
Method reloadMethod = reactDelegate .getClass ().getMethod ("reload" );
170
172
reloadMethod .invoke (reactDelegate );
171
173
} catch (NoSuchMethodException e ) {
@@ -189,18 +191,22 @@ public void run() {
189
191
}
190
192
}
191
193
192
- // This workaround has been implemented in order to fix https://github.com/facebook/react-native/issues/14533
193
- // resetReactRootViews allows to call recreateReactContextInBackground without any exceptions
194
- // This fix also relates to https://github.com/microsoft/react-native-code-push/issues/878
195
- private void resetReactRootViews (ReactInstanceManager instanceManager ) throws NoSuchFieldException , IllegalAccessException {
196
- Field mAttachedRootViewsField = instanceManager .getClass ().getDeclaredField ("mAttachedRootViews" );
197
- mAttachedRootViewsField .setAccessible (true );
198
- List <ReactRootView > mAttachedRootViews = (List <ReactRootView >)mAttachedRootViewsField .get (instanceManager );
199
- for (ReactRootView reactRootView : mAttachedRootViews ) {
200
- reactRootView .removeAllViews ();
201
- reactRootView .setId (View .NO_ID );
194
+ // Fix freezing that occurs when reloading the app in debug mode (RN >= 0.77.1 Old Architecture)
195
+ // - "Trying to add a root view with an explicit id (11) already set.
196
+ // React Native uses the id field to track react tags and will overwrite this field.
197
+ // If that is fine, explicitly overwrite the id field to View.NO_ID before calling addRootView."
198
+ private void resetReactRootViewsIfDebug (ReactInstanceManager instanceManager , ReactDelegate reactDelegate ) {
199
+ DevSupportManager devSupportManager = instanceManager .getDevSupportManager ();
200
+ if (devSupportManager .getDevSupportEnabled ()) {
201
+ ReactActivity currentActivity = (ReactActivity ) getCurrentActivity ();
202
+ if (currentActivity != null ) {
203
+ ReactRootView reactRootView = reactDelegate .getReactRootView ();
204
+ if (reactRootView != null ) {
205
+ reactRootView .removeAllViews ();
206
+ reactRootView .setId (View .NO_ID );
207
+ }
208
+ }
202
209
}
203
- mAttachedRootViewsField .set (instanceManager , mAttachedRootViews );
204
210
}
205
211
206
212
private void clearLifecycleEventListener () {
0 commit comments