1111import com .facebook .react .ReactInstanceManager ;
1212import com .facebook .react .ReactRootView ;
1313import com .facebook .react .bridge .Arguments ;
14+ import com .facebook .react .bridge .JSBundleLoader ;
1415import com .facebook .react .bridge .LifecycleEventListener ;
1516import com .facebook .react .bridge .Promise ;
1617import com .facebook .react .bridge .ReactApplicationContext ;
2829
2930import java .io .IOException ;
3031import java .lang .reflect .Field ;
31- import java .lang .reflect .Method ;
3232import java .util .Date ;
3333import java .util .HashMap ;
3434import java .util .List ;
@@ -100,37 +100,14 @@ public void run() {
100100 // to approach this.
101101 private void setJSBundle (ReactInstanceManager instanceManager , String latestJSBundleFile ) throws IllegalAccessException {
102102 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 );
130106 } else {
131- throw new NoSuchMethodException ( "Could not find a recognized ' createFileLoader' method" );
107+ latestJSBundleLoader = JSBundleLoader . createFileLoader ( latestJSBundleFile );
132108 }
133109
110+ Field bundleLoaderField = instanceManager .getClass ().getDeclaredField ("mBundleLoader" );
134111 bundleLoaderField .setAccessible (true );
135112 bundleLoaderField .set (instanceManager , latestJSBundleLoader );
136113 } catch (Exception e ) {
@@ -160,10 +137,10 @@ private void loadBundle() {
160137 @ Override
161138 public void run () {
162139 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);
167144
168145 instanceManager .recreateReactContextInBackground ();
169146 mCodePush .initializeUpdateAfterRestart ();
@@ -182,6 +159,9 @@ public void run() {
182159 }
183160 }
184161
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
185165 private void resetReactRootViews (ReactInstanceManager instanceManager ) throws NoSuchFieldException , IllegalAccessException {
186166 Field mAttachedRootViewsField = instanceManager .getClass ().getDeclaredField ("mAttachedRootViews" );
187167 mAttachedRootViewsField .setAccessible (true );
0 commit comments