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