hybrid-navigation 2.20.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HybridNavigation.podspec +7 -5
- package/README.md +17 -0
- package/android/build.gradle +56 -19
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +320 -326
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +13 -20
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +6 -11
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridNavigationPackage.java +55 -21
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +31 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeGarden.java +223 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +370 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +239 -224
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivityDelegate.java +177 -198
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactDrawerFragment.java +2 -9
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +41 -78
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +438 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +10 -19
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBar.java +7 -15
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +135 -173
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +54 -227
- package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +2 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +12 -14
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +18 -21
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +17 -20
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +13 -26
- package/dist/NativeEvent.d.ts +33 -0
- package/dist/NativeEvent.js +2 -0
- package/dist/NativeGarden.d.ts +18 -0
- package/dist/NativeGarden.js +2 -0
- package/dist/NativeNavigation.d.ts +47 -0
- package/dist/NativeNavigation.js +2 -0
- package/dist/Navigation.js +3 -3
- package/dist/NavigationModule.d.ts +3 -3
- package/dist/NavigationModule.js +18 -19
- package/dist/Navigator.js +1 -2
- package/dist/Options.d.ts +4 -7
- package/dist/Route.d.ts +0 -2
- package/dist/handler/BarButtonEventHandler.js +2 -2
- package/dist/handler/LayoutCommandHandler.js +3 -3
- package/dist/handler/ResultEventHandler.js +3 -3
- package/dist/handler/VisibilityEventHandler.js +11 -4
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/ios/HybridNavigation/GlobalStyle.h +0 -6
- package/ios/HybridNavigation/{GlobalStyle.m → GlobalStyle.mm} +54 -44
- package/ios/HybridNavigation/HBDUtils.h +0 -4
- package/ios/HybridNavigation/{HBDUtils.m → HBDUtils.mm} +0 -41
- package/ios/HybridNavigation/Navigator/{HBDScreenNavigator.m → HBDScreenNavigator.mm} +3 -9
- package/ios/HybridNavigation/Navigator/{HBDStackNavigator.m → HBDStackNavigator.mm} +0 -4
- package/ios/HybridNavigation/Navigator/{HBDTabNavigator.m → HBDTabNavigator.mm} +1 -55
- package/ios/HybridNavigation/React/HBDNativeEvent.h +13 -0
- package/ios/HybridNavigation/React/HBDNativeEvent.mm +31 -0
- package/ios/HybridNavigation/React/HBDNativeGarden.h +10 -0
- package/ios/HybridNavigation/React/HBDNativeGarden.mm +151 -0
- package/ios/HybridNavigation/React/HBDNativeNavigation.h +11 -0
- package/ios/HybridNavigation/React/HBDNativeNavigation.mm +263 -0
- package/ios/HybridNavigation/{ReactBridge → React}/HBDReactBridgeManager.h +3 -1
- package/ios/HybridNavigation/{ReactBridge/HBDReactBridgeManager.m → React/HBDReactBridgeManager.mm} +7 -30
- package/ios/HybridNavigation/View/HBDRootView.h +2 -2
- package/ios/HybridNavigation/View/{HBDRootView.m → HBDRootView.mm} +2 -2
- package/ios/HybridNavigation/View/HBDTitleView.h +2 -2
- package/ios/HybridNavigation/View/{HBDTitleView.m → HBDTitleView.mm} +3 -3
- package/ios/HybridNavigation/View/UIImage+WithBadge.h +13 -0
- package/ios/HybridNavigation/View/UIImage+WithBadge.mm +36 -0
- package/ios/HybridNavigation/ViewController/{HBDDrawerController.m → HBDDrawerController.mm} +2 -25
- package/ios/HybridNavigation/ViewController/HBDReactViewController.h +0 -4
- package/ios/HybridNavigation/ViewController/{HBDReactViewController.m → HBDReactViewController.mm} +40 -31
- package/ios/HybridNavigation/ViewController/HBDTabBarController.h +0 -2
- package/ios/HybridNavigation/ViewController/HBDTabBarController.mm +140 -0
- package/ios/HybridNavigation/ViewController/HBDViewController+Garden.h +0 -2
- package/ios/HybridNavigation/ViewController/{HBDViewController+Garden.m → HBDViewController+Garden.mm} +8 -26
- package/ios/HybridNavigation/ViewController/HBDViewController.h +2 -0
- package/ios/HybridNavigation/ViewController/{HBDViewController.m → HBDViewController.mm} +67 -57
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.h +0 -2
- package/ios/HybridNavigation/ViewController/{UIViewController+HBD.m → UIViewController+HBD.mm} +1 -42
- package/package.json +11 -2
- package/src/DeepLink.ts +3 -3
- package/src/NativeEvent.ts +40 -0
- package/src/NativeGarden.ts +27 -0
- package/src/NativeNavigation.ts +72 -0
- package/src/Navigation.ts +13 -13
- package/src/NavigationComponentWrap.tsx +4 -4
- package/src/NavigationModule.ts +21 -46
- package/src/Navigator.ts +13 -13
- package/src/Options.ts +9 -9
- package/src/Route.ts +0 -2
- package/src/handler/BarButtonEventHandler.ts +4 -8
- package/src/handler/DispatchCommandHandler.ts +4 -8
- package/src/handler/LayoutCommandHandler.ts +4 -5
- package/src/handler/ResultEventHandler.ts +11 -27
- package/src/handler/VisibilityEventHandler.ts +23 -32
- package/src/hooks.ts +2 -2
- package/src/index.ts +4 -5
- package/src/router/drawer.ts +5 -5
- package/src/router/index.ts +15 -15
- package/src/router/screen.ts +2 -2
- package/src/router/stack.ts +4 -4
- package/src/router/tabs.ts +3 -3
- package/src/store.ts +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/DefaultTabBarProvider.java +0 -143
- package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +0 -230
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDEventEmitter.java +0 -89
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +0 -71
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +0 -370
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +0 -445
- package/dist/Event.d.ts +0 -16
- package/dist/Event.js +0 -62
- package/dist/GardenModule.d.ts +0 -24
- package/dist/GardenModule.js +0 -21
- package/ios/HybridNavigation/HBDAnimationObserver.h +0 -24
- package/ios/HybridNavigation/HBDAnimationObserver.m +0 -45
- package/ios/HybridNavigation/ReactBridge/HBDEventEmitter.h +0 -28
- package/ios/HybridNavigation/ReactBridge/HBDEventEmitter.m +0 -72
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.h +0 -6
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +0 -157
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.h +0 -6
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +0 -249
- package/ios/HybridNavigation/View/HBDReactTabBar.h +0 -9
- package/ios/HybridNavigation/View/HBDReactTabBar.m +0 -36
- package/ios/HybridNavigation/View/UITabBar+Badge.h +0 -9
- package/ios/HybridNavigation/View/UITabBar+Badge.m +0 -46
- package/ios/HybridNavigation/ViewController/HBDTabBarController.m +0 -265
- package/src/Event.ts +0 -117
- package/src/GardenModule.ts +0 -50
- /package/ios/HybridNavigation/Navigator/{HBDDrawerNavigator.m → HBDDrawerNavigator.mm} +0 -0
- /package/ios/HybridNavigation/Navigator/{HBDNavigatorRegistry.m → HBDNavigatorRegistry.mm} +0 -0
- /package/ios/HybridNavigation/{ReactBridge → React}/HBDNavigator.h +0 -0
- /package/ios/HybridNavigation/View/{HBDBackBarButtonItem.m → HBDBackBarButtonItem.mm} +0 -0
- /package/ios/HybridNavigation/View/{HBDBarButtonItem.m → HBDBarButtonItem.mm} +0 -0
- /package/ios/HybridNavigation/View/{HBDNavigationBar.m → HBDNavigationBar.mm} +0 -0
- /package/ios/HybridNavigation/ViewController/{HBDFadeAnimation.m → HBDFadeAnimation.mm} +0 -0
- /package/ios/HybridNavigation/ViewController/{HBDNavigationController.m → HBDNavigationController.mm} +0 -0
- /package/ios/HybridNavigation/ViewController/{HBDPopAnimation.m → HBDPopAnimation.mm} +0 -0
- /package/ios/HybridNavigation/ViewController/{HBDPushAnimation.m → HBDPushAnimation.mm} +0 -0
- /package/ios/HybridNavigation/ViewController/{UINavigationController+HBD.m → UINavigationController+HBD.mm} +0 -0
package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivityDelegate.java
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
package com.reactnative.hybridnavigation;
|
|
2
2
|
|
|
3
|
-
import android.annotation.TargetApi;
|
|
4
3
|
import android.app.Activity;
|
|
5
4
|
import android.content.Context;
|
|
6
5
|
import android.content.Intent;
|
|
7
6
|
import android.content.res.Configuration;
|
|
8
7
|
import android.net.Uri;
|
|
9
|
-
import android.os.Build;
|
|
10
8
|
import android.os.Bundle;
|
|
11
9
|
import android.provider.Settings;
|
|
12
10
|
import android.view.KeyEvent;
|
|
@@ -18,210 +16,191 @@ import androidx.appcompat.app.AppCompatActivity;
|
|
|
18
16
|
|
|
19
17
|
import com.facebook.common.logging.FLog;
|
|
20
18
|
import com.facebook.infer.annotation.Assertions;
|
|
21
|
-
import com.facebook.react.
|
|
19
|
+
import com.facebook.react.ReactHost;
|
|
22
20
|
import com.facebook.react.bridge.Callback;
|
|
23
21
|
import com.facebook.react.bridge.ReactContext;
|
|
24
|
-
import com.facebook.react.bridge.UiThreadUtil;
|
|
25
22
|
import com.facebook.react.common.ReactConstants;
|
|
26
23
|
import com.facebook.react.devsupport.DoubleTapReloadRecognizer;
|
|
24
|
+
import com.facebook.react.devsupport.interfaces.DevSupportManager;
|
|
27
25
|
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
|
|
28
26
|
import com.facebook.react.modules.core.PermissionListener;
|
|
29
27
|
|
|
30
28
|
public class ReactAppCompatActivityDelegate {
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
mPermissionListener = listener;
|
|
208
|
-
getPlainActivity().requestPermissions(permissions, requestCode);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
public void onRequestPermissionsResult(final int requestCode, final String[] permissions, final int[] grantResults) {
|
|
212
|
-
mPermissionsCallback = args -> {
|
|
213
|
-
if (mPermissionListener != null && mPermissionListener.onRequestPermissionsResult(requestCode, permissions, grantResults)) {
|
|
214
|
-
mPermissionListener = null;
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
private Context getContext() {
|
|
220
|
-
return Assertions.assertNotNull(mActivity);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
private Activity getPlainActivity() {
|
|
224
|
-
return ((Activity) getContext());
|
|
225
|
-
}
|
|
30
|
+
private static final String TAG = "Navigation";
|
|
31
|
+
|
|
32
|
+
private final int REQUEST_OVERLAY_PERMISSION_CODE = 1111;
|
|
33
|
+
private static final String REDBOX_PERMISSION_GRANTED_MESSAGE =
|
|
34
|
+
"Overlay permissions have been granted.";
|
|
35
|
+
private static final String REDBOX_PERMISSION_MESSAGE =
|
|
36
|
+
"Overlay permissions needs to be granted in order for react native apps to run in dev mode";
|
|
37
|
+
|
|
38
|
+
private final AppCompatActivity mActivity;
|
|
39
|
+
private final ReactManager mReactManager;
|
|
40
|
+
|
|
41
|
+
private @Nullable
|
|
42
|
+
DoubleTapReloadRecognizer mDoubleTapReloadRecognizer;
|
|
43
|
+
private @Nullable
|
|
44
|
+
PermissionListener mPermissionListener;
|
|
45
|
+
private @Nullable
|
|
46
|
+
Callback mPermissionsCallback;
|
|
47
|
+
|
|
48
|
+
public ReactAppCompatActivityDelegate(@NonNull AppCompatActivity activity, ReactManager reactManager) {
|
|
49
|
+
mActivity = activity;
|
|
50
|
+
mReactManager = reactManager;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private void askPermission() {
|
|
54
|
+
ReactManager reactManager = getReactManager();
|
|
55
|
+
DevSupportManager devSupportManager = reactManager.getDevSupportManager();
|
|
56
|
+
if (devSupportManager != null) {
|
|
57
|
+
FLog.i(TAG, "Check overlay permission");
|
|
58
|
+
// Get permission to show redbox in dev builds.
|
|
59
|
+
if (!Settings.canDrawOverlays(getContext())) {
|
|
60
|
+
FLog.i(TAG, "Request overlay permission");
|
|
61
|
+
Intent serviceIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getContext().getPackageName()));
|
|
62
|
+
FLog.w(ReactConstants.TAG, REDBOX_PERMISSION_MESSAGE);
|
|
63
|
+
Toast.makeText(getContext(), REDBOX_PERMISSION_MESSAGE, Toast.LENGTH_LONG).show();
|
|
64
|
+
((Activity) getContext()).startActivityForResult(serviceIntent, REQUEST_OVERLAY_PERMISSION_CODE);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
protected ReactManager getReactManager() {
|
|
70
|
+
return mReactManager;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public ReactContext getCurrentReactContext() {
|
|
74
|
+
return mReactManager.getCurrentReactContext();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
ReactManager.ReactModuleRegisterListener mReactModuleRegisterListener = this::askPermission;
|
|
78
|
+
|
|
79
|
+
protected void onCreate(Bundle savedInstanceState) {
|
|
80
|
+
mDoubleTapReloadRecognizer = new DoubleTapReloadRecognizer();
|
|
81
|
+
if (mReactManager.isReactModuleRegisterCompleted()) {
|
|
82
|
+
askPermission();
|
|
83
|
+
} else {
|
|
84
|
+
mReactManager.addReactModuleRegisterListener(mReactModuleRegisterListener);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
protected void onDestroy() {
|
|
89
|
+
mReactManager.removeReactModuleRegisterListener(mReactModuleRegisterListener);
|
|
90
|
+
ReactHost reactHost = mReactManager.getReactHost();
|
|
91
|
+
reactHost.onHostDestroy(getPlainActivity());
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
protected void onResume() {
|
|
95
|
+
ReactHost reactHost = mReactManager.getReactHost();
|
|
96
|
+
reactHost.onHostResume(getPlainActivity(), (DefaultHardwareBackBtnHandler) getPlainActivity());
|
|
97
|
+
if (mPermissionsCallback != null) {
|
|
98
|
+
mPermissionsCallback.invoke();
|
|
99
|
+
mPermissionsCallback = null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
protected void onPause() {
|
|
104
|
+
ReactHost reactHost = mReactManager.getReactHost();
|
|
105
|
+
reactHost.onHostPause(getPlainActivity());
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public boolean onBackPressed() {
|
|
109
|
+
ReactHost reactHost = mReactManager.getReactHost();
|
|
110
|
+
return reactHost.onBackPressed();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public boolean onNewIntent(Intent intent) {
|
|
114
|
+
ReactHost reactHost = mReactManager.getReactHost();
|
|
115
|
+
reactHost.onNewIntent(intent);
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public void onUserLeaveHint() {
|
|
120
|
+
ReactHost reactHost = mReactManager.getReactHost();
|
|
121
|
+
reactHost.onHostLeaveHint(getPlainActivity());
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
125
|
+
ReactHost reactHost = mReactManager.getReactHost();
|
|
126
|
+
reactHost.onActivityResult(getPlainActivity(), requestCode, resultCode, data);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
public void onWindowFocusChanged(boolean hasFocus) {
|
|
130
|
+
ReactHost reactHost = mReactManager.getReactHost();
|
|
131
|
+
reactHost.onWindowFocusChange(hasFocus);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public void onConfigurationChanged(Configuration newConfig) {
|
|
135
|
+
ReactHost reactHost = mReactManager.getReactHost();
|
|
136
|
+
reactHost.onConfigurationChanged(getPlainActivity());
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
140
|
+
DevSupportManager devSupportManager = mReactManager.getDevSupportManager();
|
|
141
|
+
if (devSupportManager != null && keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD) {
|
|
142
|
+
event.startTracking();
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
|
149
|
+
return shouldShowDevMenuOrReload(keyCode, event);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
|
|
153
|
+
if (keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD || keyCode == KeyEvent.KEYCODE_BACK) {
|
|
154
|
+
DevSupportManager devSupportManager = mReactManager.getDevSupportManager();
|
|
155
|
+
if (devSupportManager != null) {
|
|
156
|
+
devSupportManager.showDevOptionsDialog();
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
public boolean shouldShowDevMenuOrReload(int keyCode, KeyEvent event) {
|
|
164
|
+
DevSupportManager devSupportManager = mReactManager.getDevSupportManager();
|
|
165
|
+
if (devSupportManager == null) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (keyCode == KeyEvent.KEYCODE_MENU) {
|
|
170
|
+
devSupportManager.showDevOptionsDialog();
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (mDoubleTapReloadRecognizer != null &&
|
|
175
|
+
mDoubleTapReloadRecognizer.didDoubleTapR(keyCode, getPlainActivity().getCurrentFocus())) {
|
|
176
|
+
devSupportManager.handleReloadJS();
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
public void requestPermissions(String[] permissions, int requestCode, PermissionListener listener) {
|
|
184
|
+
mPermissionListener = listener;
|
|
185
|
+
getPlainActivity().requestPermissions(permissions, requestCode);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
public void onRequestPermissionsResult(final int requestCode, final String[] permissions, final int[] grantResults) {
|
|
189
|
+
mPermissionsCallback = args -> {
|
|
190
|
+
if (mPermissionListener != null
|
|
191
|
+
&& mPermissionListener.onRequestPermissionsResult(
|
|
192
|
+
requestCode, permissions, grantResults)) {
|
|
193
|
+
mPermissionListener = null;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
private Context getContext() {
|
|
199
|
+
return Assertions.assertNotNull(mActivity);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private Activity getPlainActivity() {
|
|
203
|
+
return ((Activity) getContext());
|
|
204
|
+
}
|
|
226
205
|
|
|
227
206
|
}
|
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
package com.reactnative.hybridnavigation;
|
|
2
2
|
|
|
3
|
-
import androidx.annotation.NonNull;
|
|
4
|
-
|
|
5
3
|
import com.navigation.androidx.DrawerFragment;
|
|
6
4
|
|
|
7
5
|
public class ReactDrawerFragment extends DrawerFragment {
|
|
8
6
|
|
|
9
|
-
private final
|
|
10
|
-
|
|
11
|
-
public @NonNull
|
|
12
|
-
ReactBridgeManager getReactBridgeManager() {
|
|
13
|
-
return bridgeManager;
|
|
14
|
-
}
|
|
7
|
+
private final ReactManager reactManager = ReactManager.get();
|
|
15
8
|
|
|
16
9
|
@Override
|
|
17
10
|
public void onDestroy() {
|
|
18
11
|
super.onDestroy();
|
|
19
|
-
|
|
12
|
+
reactManager.watchMemory(this);
|
|
20
13
|
}
|
|
21
14
|
}
|
|
@@ -2,19 +2,9 @@ package com.reactnative.hybridnavigation;
|
|
|
2
2
|
|
|
3
3
|
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
|
4
4
|
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
|
5
|
-
import static com.reactnative.hybridnavigation.HBDEventEmitter.EVENT_NAVIGATION;
|
|
6
|
-
import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_ON;
|
|
7
|
-
import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_REQUEST_CODE;
|
|
8
|
-
import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_RESULT_CODE;
|
|
9
|
-
import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_RESULT_DATA;
|
|
10
|
-
import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_SCENE_ID;
|
|
11
|
-
import static com.reactnative.hybridnavigation.HBDEventEmitter.ON_COMPONENT_APPEAR;
|
|
12
|
-
import static com.reactnative.hybridnavigation.HBDEventEmitter.ON_COMPONENT_DISAPPEAR;
|
|
13
|
-
import static com.reactnative.hybridnavigation.HBDEventEmitter.ON_COMPONENT_RESULT;
|
|
14
5
|
|
|
15
6
|
import android.annotation.SuppressLint;
|
|
16
7
|
import android.content.pm.ActivityInfo;
|
|
17
|
-
import android.content.res.Configuration;
|
|
18
8
|
import android.graphics.Color;
|
|
19
9
|
import android.os.Bundle;
|
|
20
10
|
import android.view.Gravity;
|
|
@@ -27,20 +17,21 @@ import androidx.annotation.Nullable;
|
|
|
27
17
|
import androidx.appcompat.widget.Toolbar;
|
|
28
18
|
|
|
29
19
|
import com.facebook.common.logging.FLog;
|
|
30
|
-
import com.facebook.react.
|
|
20
|
+
import com.facebook.react.ReactHost;
|
|
31
21
|
import com.facebook.react.bridge.Arguments;
|
|
32
22
|
import com.facebook.react.bridge.ReactContext;
|
|
33
23
|
import com.facebook.react.common.LifecycleState;
|
|
24
|
+
import com.facebook.react.interfaces.fabric.ReactSurface;
|
|
34
25
|
import com.navigation.androidx.Style;
|
|
35
26
|
|
|
36
|
-
public class ReactFragment extends HybridFragment implements
|
|
27
|
+
public class ReactFragment extends HybridFragment implements ReactManager.ReactBridgeReloadListener {
|
|
37
28
|
|
|
38
29
|
protected static final String TAG = "Navigation";
|
|
39
30
|
|
|
40
31
|
private ViewGroup reactViewHolder;
|
|
41
32
|
|
|
42
|
-
private
|
|
43
|
-
private
|
|
33
|
+
private ReactSurface reactRootView;
|
|
34
|
+
private ReactSurface reactTitleView;
|
|
44
35
|
private boolean firstRenderCompleted;
|
|
45
36
|
|
|
46
37
|
@Nullable
|
|
@@ -61,6 +52,12 @@ public class ReactFragment extends HybridFragment implements ReactBridgeManager.
|
|
|
61
52
|
initReactTitleView();
|
|
62
53
|
}
|
|
63
54
|
|
|
55
|
+
@Override
|
|
56
|
+
public void onDestroyView() {
|
|
57
|
+
super.onDestroyView();
|
|
58
|
+
unmountReactView();
|
|
59
|
+
}
|
|
60
|
+
|
|
64
61
|
@Override
|
|
65
62
|
public void onStop() {
|
|
66
63
|
super.onStop();
|
|
@@ -113,13 +110,6 @@ public class ReactFragment extends HybridFragment implements ReactBridgeManager.
|
|
|
113
110
|
}
|
|
114
111
|
}
|
|
115
112
|
|
|
116
|
-
@Override
|
|
117
|
-
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
|
118
|
-
super.onConfigurationChanged(newConfig);
|
|
119
|
-
// 避免屏幕旋转时状态栏样式不更新的问题
|
|
120
|
-
setNeedsStatusBarAppearanceUpdate();
|
|
121
|
-
}
|
|
122
|
-
|
|
123
113
|
private boolean isViewReady() {
|
|
124
114
|
if (reactRootView == null) {
|
|
125
115
|
return false;
|
|
@@ -147,15 +137,13 @@ public class ReactFragment extends HybridFragment implements ReactBridgeManager.
|
|
|
147
137
|
reactViewAppeared = appear;
|
|
148
138
|
|
|
149
139
|
Bundle bundle = new Bundle();
|
|
150
|
-
bundle.putString(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
super.onDestroyView();
|
|
158
|
-
unmountReactView();
|
|
140
|
+
bundle.putString("sceneId", getSceneId());
|
|
141
|
+
NativeEvent nativeEvent = NativeEvent.getInstance();
|
|
142
|
+
if (appear) {
|
|
143
|
+
nativeEvent.emitOnComponentAppear(Arguments.fromBundle(bundle));
|
|
144
|
+
} else {
|
|
145
|
+
nativeEvent.emitOnComponentDisappear(Arguments.fromBundle(bundle));
|
|
146
|
+
}
|
|
159
147
|
}
|
|
160
148
|
|
|
161
149
|
@Override
|
|
@@ -165,38 +153,34 @@ public class ReactFragment extends HybridFragment implements ReactBridgeManager.
|
|
|
165
153
|
|
|
166
154
|
private void mountReactView() {
|
|
167
155
|
initReactRootView();
|
|
168
|
-
|
|
156
|
+
getReactManager().addReactBridgeReloadListener(this);
|
|
169
157
|
}
|
|
170
158
|
|
|
171
159
|
private void unmountReactView() {
|
|
172
|
-
|
|
160
|
+
getReactManager().removeReactBridgeReloadListener(this);
|
|
173
161
|
|
|
174
162
|
ReactContext reactContext = getCurrentReactContext();
|
|
175
|
-
if (reactContext == null || !reactContext.
|
|
163
|
+
if (reactContext == null || !reactContext.hasActiveReactInstance()) {
|
|
176
164
|
return;
|
|
177
165
|
}
|
|
178
166
|
|
|
179
167
|
if (reactRootView != null) {
|
|
180
168
|
FLog.w(TAG, "销毁页面-:" + getModuleName());
|
|
181
|
-
reactRootView.
|
|
182
|
-
ViewGroup parent = (ViewGroup) reactRootView.getParent();
|
|
183
|
-
parent.removeView(reactRootView);
|
|
169
|
+
reactRootView.stop();
|
|
184
170
|
reactRootView = null;
|
|
185
171
|
}
|
|
186
172
|
|
|
187
173
|
if (reactTitleView != null) {
|
|
188
|
-
reactTitleView.
|
|
189
|
-
ViewGroup parent = (ViewGroup) reactTitleView.getParent();
|
|
190
|
-
parent.removeView(reactTitleView);
|
|
174
|
+
reactTitleView.stop();
|
|
191
175
|
reactTitleView = null;
|
|
192
176
|
}
|
|
193
177
|
}
|
|
194
178
|
|
|
195
179
|
@Override
|
|
196
180
|
protected boolean onBackPressed() {
|
|
197
|
-
|
|
198
|
-
if (getShowsDialog()
|
|
199
|
-
|
|
181
|
+
ReactHost reactHost = getReactManager().getReactHost();
|
|
182
|
+
if (getShowsDialog()) {
|
|
183
|
+
reactHost.onBackPressed();
|
|
200
184
|
return true;
|
|
201
185
|
}
|
|
202
186
|
return super.onBackPressed();
|
|
@@ -221,38 +205,20 @@ public class ReactFragment extends HybridFragment implements ReactBridgeManager.
|
|
|
221
205
|
public void onFragmentResult(int requestCode, int resultCode, Bundle data) {
|
|
222
206
|
super.onFragmentResult(requestCode, resultCode, data);
|
|
223
207
|
Bundle result = new Bundle();
|
|
224
|
-
result.putInt(
|
|
225
|
-
result.putInt(
|
|
226
|
-
result.putBundle(
|
|
227
|
-
result.putString(
|
|
228
|
-
|
|
229
|
-
HBDEventEmitter.sendEvent(EVENT_NAVIGATION, Arguments.fromBundle(result));
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
@Override
|
|
233
|
-
public void setAppProperties(@NonNull Bundle props) {
|
|
234
|
-
super.setAppProperties(props);
|
|
235
|
-
if (reactRootView == null) {
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
if (isReactModuleRegisterCompleted()) {
|
|
240
|
-
reactRootView.setAppProperties(getProps());
|
|
241
|
-
}
|
|
208
|
+
result.putInt("requestCode", requestCode);
|
|
209
|
+
result.putInt("resultCode", resultCode);
|
|
210
|
+
result.putBundle("resultData", data);
|
|
211
|
+
result.putString("sceneId", getSceneId());
|
|
212
|
+
NativeEvent.getInstance().emitOnResult(Arguments.fromBundle(result));
|
|
242
213
|
}
|
|
243
214
|
|
|
244
215
|
private void initReactRootView() {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
@NonNull
|
|
250
|
-
private HBDReactRootView createReactRootView() {
|
|
251
|
-
HBDReactRootView reactRootView = new HBDReactRootView(getContext());
|
|
252
|
-
reactRootView.setShouldConsumeTouchEvent(!shouldPassThroughTouches());
|
|
216
|
+
ReactHost reactHost = getReactManager().getReactHost();
|
|
217
|
+
ReactSurface reactSurface = reactHost.createSurface(requireContext(), getModuleName(), getProps());
|
|
218
|
+
reactRootView = reactSurface;
|
|
253
219
|
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT);
|
|
254
|
-
reactViewHolder.addView(
|
|
255
|
-
|
|
220
|
+
reactViewHolder.addView(reactSurface.getView(), layoutParams);
|
|
221
|
+
reactSurface.start();
|
|
256
222
|
}
|
|
257
223
|
|
|
258
224
|
private void initReactTitleView() {
|
|
@@ -276,16 +242,12 @@ public class ReactFragment extends HybridFragment implements ReactBridgeManager.
|
|
|
276
242
|
|
|
277
243
|
String fitting = titleItem.getString("layoutFitting");
|
|
278
244
|
boolean expanded = "expanded".equals(fitting);
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
private HBDReactRootView createReactTitleView(boolean expanded) {
|
|
245
|
+
ReactHost reactHost = getReactManager().getReactHost();
|
|
246
|
+
ReactSurface reactSurface = reactHost.createSurface(requireContext(), moduleName, getProps());
|
|
284
247
|
Toolbar.LayoutParams layoutParams = createTitleLayoutParams(expanded);
|
|
285
|
-
HBDReactRootView reactTitleView = new HBDReactRootView(getContext());
|
|
286
248
|
Toolbar toolbar = getToolbar();
|
|
287
|
-
toolbar.addView(
|
|
288
|
-
|
|
249
|
+
toolbar.addView(reactSurface.getView(), layoutParams);
|
|
250
|
+
reactSurface.start();
|
|
289
251
|
}
|
|
290
252
|
|
|
291
253
|
@NonNull
|
|
@@ -300,4 +262,5 @@ public class ReactFragment extends HybridFragment implements ReactBridgeManager.
|
|
|
300
262
|
public String getDebugTag() {
|
|
301
263
|
return "[" + getModuleName() + "]";
|
|
302
264
|
}
|
|
265
|
+
|
|
303
266
|
}
|