11
11
import com .facebook .react .ReactInstanceManager ;
12
12
import com .facebook .react .ReactRootView ;
13
13
import com .facebook .react .bridge .Arguments ;
14
+ import com .facebook .react .bridge .JSBundleLoader ;
14
15
import com .facebook .react .bridge .LifecycleEventListener ;
15
16
import com .facebook .react .bridge .Promise ;
16
17
import com .facebook .react .bridge .ReactApplicationContext ;
28
29
29
30
import java .io .IOException ;
30
31
import java .lang .reflect .Field ;
31
- import java .lang .reflect .Method ;
32
32
import java .util .Date ;
33
33
import java .util .HashMap ;
34
34
import java .util .List ;
@@ -100,37 +100,14 @@ public void run() {
100
100
// to approach this.
101
101
private void setJSBundle (ReactInstanceManager instanceManager , String latestJSBundleFile ) throws IllegalAccessException {
102
102
try {
103
- Field bundleLoaderField = instanceManager .getClass ().getDeclaredField ("mBundleLoader" );
104
- Class <?> jsBundleLoaderClass = Class .forName ("com.facebook.react.cxxbridge.JSBundleLoader" );
105
- Method createFileLoaderMethod = null ;
106
- String createFileLoaderMethodName = latestJSBundleFile .toLowerCase ().startsWith ("assets://" )
107
- ? "createAssetLoader" : "createFileLoader" ;
108
-
109
- Method [] methods = jsBundleLoaderClass .getDeclaredMethods ();
110
- for (Method method : methods ) {
111
- if (method .getName ().equals (createFileLoaderMethodName )) {
112
- createFileLoaderMethod = method ;
113
- break ;
114
- }
115
- }
116
-
117
- if (createFileLoaderMethod == null ) {
118
- throw new NoSuchMethodException ("Could not find a recognized 'createFileLoader' method" );
119
- }
120
-
121
- int numParameters = createFileLoaderMethod .getGenericParameterTypes ().length ;
122
- Object latestJSBundleLoader ;
123
-
124
- if (numParameters == 1 ) {
125
- // RN >= v0.34
126
- latestJSBundleLoader = createFileLoaderMethod .invoke (jsBundleLoaderClass , latestJSBundleFile );
127
- } else if (numParameters == 2 ) {
128
- // AssetLoader instance
129
- latestJSBundleLoader = createFileLoaderMethod .invoke (jsBundleLoaderClass , getReactApplicationContext (), latestJSBundleFile );
103
+ JSBundleLoader latestJSBundleLoader ;
104
+ if (latestJSBundleFile .toLowerCase ().startsWith ("assets://" )) {
105
+ latestJSBundleLoader = JSBundleLoader .createAssetLoader (getReactApplicationContext (), latestJSBundleFile , false );
130
106
} else {
131
- throw new NoSuchMethodException ( "Could not find a recognized ' createFileLoader' method" );
107
+ latestJSBundleLoader = JSBundleLoader . createFileLoader ( latestJSBundleFile );
132
108
}
133
109
110
+ Field bundleLoaderField = instanceManager .getClass ().getDeclaredField ("mBundleLoader" );
134
111
bundleLoaderField .setAccessible (true );
135
112
bundleLoaderField .set (instanceManager , latestJSBundleLoader );
136
113
} catch (Exception e ) {
@@ -160,10 +137,10 @@ private void loadBundle() {
160
137
@ Override
161
138
public void run () {
162
139
try {
163
- // This workaround has been implemented in order to fix https://github.com/facebook/react-native/issues/14533
164
- // resetReactRootViews allows to call recreateReactContextInBackground without any exceptions
165
- // This fix also relates to https://github.com/Microsoft/react-native-code-push/issues/878
166
- resetReactRootViews (instanceManager );
140
+ // We don't need to resetReactRootViews anymore
141
+ // due the issue https://github.com/facebook/react-native/issues/14533
142
+ // has been fixed in RN 0.46.0
143
+ // resetReactRootViews(instanceManager);
167
144
168
145
instanceManager .recreateReactContextInBackground ();
169
146
mCodePush .initializeUpdateAfterRestart ();
@@ -182,6 +159,9 @@ public void run() {
182
159
}
183
160
}
184
161
162
+ // This workaround has been implemented in order to fix https://github.com/facebook/react-native/issues/14533
163
+ // resetReactRootViews allows to call recreateReactContextInBackground without any exceptions
164
+ // This fix also relates to https://github.com/Microsoft/react-native-code-push/issues/878
185
165
private void resetReactRootViews (ReactInstanceManager instanceManager ) throws NoSuchFieldException , IllegalAccessException {
186
166
Field mAttachedRootViewsField = instanceManager .getClass ().getDeclaredField ("mAttachedRootViews" );
187
167
mAttachedRootViewsField .setAccessible (true );
0 commit comments