|
@@ -1,10 +1,21 @@
|
1
|
1
|
package com.reactnativenavigation.react;
|
2
|
2
|
|
|
3
|
+import android.app.Activity;
|
|
4
|
+import android.content.BroadcastReceiver;
|
|
5
|
+import android.content.Context;
|
|
6
|
+import android.content.Intent;
|
|
7
|
+import android.content.IntentFilter;
|
3
|
8
|
import android.view.KeyEvent;
|
4
|
9
|
|
5
|
10
|
import com.facebook.react.ReactInstanceManager;
|
6
|
11
|
|
7
|
12
|
public class JsDevReloadHandler {
|
|
13
|
+ private final BroadcastReceiver reloadReceiver = new BroadcastReceiver() {
|
|
14
|
+ @Override
|
|
15
|
+ public void onReceive(final Context context, final Intent intent) {
|
|
16
|
+ reloadReactNative();
|
|
17
|
+ }
|
|
18
|
+ };
|
8
|
19
|
private final ReactInstanceManager reactInstanceManager;
|
9
|
20
|
private long firstRTimestamp = 0;
|
10
|
21
|
|
|
@@ -12,6 +23,14 @@ public class JsDevReloadHandler {
|
12
|
23
|
this.reactInstanceManager = reactInstanceManager;
|
13
|
24
|
}
|
14
|
25
|
|
|
26
|
+ public void onActivityResumed(Activity activity) {
|
|
27
|
+ activity.registerReceiver(reloadReceiver, new IntentFilter("com.reactnativenavigation.broadcast.RELOAD"));
|
|
28
|
+ }
|
|
29
|
+
|
|
30
|
+ public void onActivityPaused(Activity activity) {
|
|
31
|
+ activity.unregisterReceiver(reloadReceiver);
|
|
32
|
+ }
|
|
33
|
+
|
15
|
34
|
public boolean onKeyUp(int keyCode) {
|
16
|
35
|
if (!reactInstanceManager.getDevSupportManager().getDevSupportEnabled()) {
|
17
|
36
|
return false;
|
|
@@ -24,7 +43,7 @@ public class JsDevReloadHandler {
|
24
|
43
|
|
25
|
44
|
if (keyCode == KeyEvent.KEYCODE_R) {
|
26
|
45
|
if (lessThan500MillisSinceLastR()) {
|
27
|
|
- reactInstanceManager.getDevSupportManager().handleReloadJS();
|
|
46
|
+ reloadReactNative();
|
28
|
47
|
return true;
|
29
|
48
|
}
|
30
|
49
|
firstRTimestamp = System.currentTimeMillis();
|
|
@@ -35,4 +54,8 @@ public class JsDevReloadHandler {
|
35
|
54
|
private boolean lessThan500MillisSinceLastR() {
|
36
|
55
|
return firstRTimestamp != 0 && System.currentTimeMillis() - firstRTimestamp < 1000;
|
37
|
56
|
}
|
|
57
|
+
|
|
58
|
+ private void reloadReactNative() {
|
|
59
|
+ reactInstanceManager.getDevSupportManager().handleReloadJS();
|
|
60
|
+ }
|
38
|
61
|
}
|