|
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; |
|
16 | 15 | import com.facebook.react.bridge.LifecycleEventListener; |
17 | 16 | import com.facebook.react.bridge.Promise; |
18 | 17 | import com.facebook.react.bridge.ReactApplicationContext; |
19 | | -import com.facebook.react.bridge.ReactContextBaseJavaModule; |
20 | 18 | import com.facebook.react.bridge.ReactMethod; |
21 | 19 | import com.facebook.react.bridge.ReadableMap; |
22 | 20 | import com.facebook.react.bridge.WritableMap; |
| 21 | +import com.facebook.react.devsupport.interfaces.DevSupportManager; |
23 | 22 | import com.facebook.react.modules.core.ChoreographerCompat; |
24 | 23 | import com.facebook.react.modules.core.DeviceEventManagerModule; |
25 | 24 | import com.facebook.react.modules.core.ReactChoreographer; |
| 25 | +import com.facebook.react.modules.debug.interfaces.DeveloperSettings; |
26 | 26 |
|
27 | 27 | import org.json.JSONArray; |
28 | 28 | import org.json.JSONException; |
29 | 29 | import org.json.JSONObject; |
30 | 30 |
|
31 | 31 | import java.io.IOException; |
32 | 32 | import java.lang.reflect.Field; |
| 33 | +import java.lang.reflect.Method; |
33 | 34 | import java.util.ArrayList; |
34 | 35 | import java.util.Date; |
35 | 36 | import java.util.HashMap; |
@@ -132,10 +133,17 @@ private void setJSBundle(ReactInstanceManager instanceManager, String latestJSBu |
132 | 133 | private void loadBundle() { |
133 | 134 | clearLifecycleEventListener(); |
134 | 135 | try { |
135 | | - mCodePush.clearDebugCacheIfNeeded(resolveInstanceManager()); |
| 136 | + DevSupportManager devSupportManager = null; |
| 137 | + ReactInstanceManager reactInstanceManager = resolveInstanceManager(); |
| 138 | + if (reactInstanceManager != null) { |
| 139 | + devSupportManager = reactInstanceManager.getDevSupportManager(); |
| 140 | + } |
| 141 | + boolean isLiveReloadEnabled = isLiveReloadEnabled(devSupportManager); |
| 142 | + |
| 143 | + mCodePush.clearDebugCacheIfNeeded(isLiveReloadEnabled); |
136 | 144 | } catch(Exception e) { |
137 | 145 | // If we got error in out reflection we should clear debug cache anyway. |
138 | | - mCodePush.clearDebugCacheIfNeeded(null); |
| 146 | + mCodePush.clearDebugCacheIfNeeded(false); |
139 | 147 | } |
140 | 148 |
|
141 | 149 | try { |
@@ -179,6 +187,26 @@ public void run() { |
179 | 187 | } |
180 | 188 | } |
181 | 189 |
|
| 190 | + private boolean isLiveReloadEnabled(DevSupportManager devSupportManager) { |
| 191 | + if (devSupportManager == null) { |
| 192 | + return false; |
| 193 | + } |
| 194 | + |
| 195 | + DeveloperSettings devSettings = devSupportManager.getDevSettings(); |
| 196 | + Method[] methods = devSettings.getClass().getMethods(); |
| 197 | + for (Method m : methods) { |
| 198 | + if (m.getName().equals("isReloadOnJSChangeEnabled")) { |
| 199 | + try { |
| 200 | + return (boolean) m.invoke(devSettings); |
| 201 | + } catch (Exception x) { |
| 202 | + return false; |
| 203 | + } |
| 204 | + } |
| 205 | + } |
| 206 | + |
| 207 | + return false; |
| 208 | + } |
| 209 | + |
182 | 210 | // This workaround has been implemented in order to fix https://github.com/facebook/react-native/issues/14533 |
183 | 211 | // resetReactRootViews allows to call recreateReactContextInBackground without any exceptions |
184 | 212 | // This fix also relates to https://github.com/microsoft/react-native-code-push/issues/878 |
|
0 commit comments