hybrid-navigation 2.20.1 → 3.0.1
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/{HBDNavigationBar.m → HBDNavigationBar.mm} +8 -28
- 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} +10 -44
- 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/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
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
package com.reactnative.hybridnavigation;
|
|
2
|
+
|
|
3
|
+
import android.os.Bundle;
|
|
4
|
+
|
|
5
|
+
import androidx.annotation.NonNull;
|
|
6
|
+
import androidx.annotation.Nullable;
|
|
7
|
+
import androidx.annotation.UiThread;
|
|
8
|
+
import androidx.fragment.app.Fragment;
|
|
9
|
+
import androidx.fragment.app.FragmentManager;
|
|
10
|
+
|
|
11
|
+
import com.facebook.common.logging.FLog;
|
|
12
|
+
import com.facebook.react.ReactHost;
|
|
13
|
+
import com.facebook.react.ReactInstanceEventListener;
|
|
14
|
+
import com.facebook.react.bridge.Arguments;
|
|
15
|
+
import com.facebook.react.bridge.Callback;
|
|
16
|
+
import com.facebook.react.bridge.ReactContext;
|
|
17
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
18
|
+
import com.facebook.react.bridge.WritableMap;
|
|
19
|
+
import com.facebook.react.devsupport.interfaces.DevSupportManager;
|
|
20
|
+
import com.navigation.androidx.AwesomeFragment;
|
|
21
|
+
import com.navigation.androidx.FragmentHelper;
|
|
22
|
+
|
|
23
|
+
import java.util.ArrayList;
|
|
24
|
+
import java.util.HashMap;
|
|
25
|
+
import java.util.List;
|
|
26
|
+
import java.util.concurrent.CopyOnWriteArrayList;
|
|
27
|
+
|
|
28
|
+
@UiThread
|
|
29
|
+
public class ReactManager {
|
|
30
|
+
|
|
31
|
+
public interface ReactModuleRegisterListener {
|
|
32
|
+
void onReactModuleRegisterCompleted();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public interface ReactBridgeReloadListener {
|
|
36
|
+
void onReload();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private static final String TAG = "Navigation";
|
|
40
|
+
|
|
41
|
+
private final static ReactManager instance = new ReactManager();
|
|
42
|
+
|
|
43
|
+
public static ReactManager get() {
|
|
44
|
+
return instance;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private ReactManager() {
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private final HashMap<String, Class<? extends HybridFragment>> nativeModules = new HashMap<>();
|
|
51
|
+
private final HashMap<String, ReadableMap> reactModules = new HashMap<>();
|
|
52
|
+
private final CopyOnWriteArrayList<ReactModuleRegisterListener> reactModuleRegisterListeners = new CopyOnWriteArrayList<>();
|
|
53
|
+
private final CopyOnWriteArrayList<ReactBridgeReloadListener> reactBridgeReloadListeners = new CopyOnWriteArrayList<>();
|
|
54
|
+
|
|
55
|
+
private ReadableMap rootLayout;
|
|
56
|
+
private Callback pendingCallback;
|
|
57
|
+
private ReadableMap stickyLayout;
|
|
58
|
+
private ReadableMap pendingLayout;
|
|
59
|
+
private boolean viewHierarchyReady;
|
|
60
|
+
|
|
61
|
+
private ReactHost reactHost;
|
|
62
|
+
|
|
63
|
+
public void install(@NonNull ReactHost reactNativeHost) {
|
|
64
|
+
this.setReactHost(reactNativeHost);
|
|
65
|
+
this.initialize();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public void setReactHost(@NonNull ReactHost reactHost) {
|
|
69
|
+
this.reactHost = reactHost;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@NonNull
|
|
73
|
+
public ReactHost getReactHost() {
|
|
74
|
+
checkReactHost();
|
|
75
|
+
return reactHost;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public void initialize() {
|
|
79
|
+
checkReactHost();
|
|
80
|
+
reactHost.addReactInstanceEventListener(new ReactInstanceEventListener() {
|
|
81
|
+
@Override
|
|
82
|
+
public void onReactContextInitialized(@NonNull ReactContext reactContext) {
|
|
83
|
+
FLog.i(TAG, "React instance context initialized.");
|
|
84
|
+
reactHost.removeReactInstanceEventListener(this);
|
|
85
|
+
rootLayout = null;
|
|
86
|
+
pendingCallback = null;
|
|
87
|
+
stickyLayout = null;
|
|
88
|
+
pendingLayout = null;
|
|
89
|
+
reactBridgeReloadListeners.clear();
|
|
90
|
+
|
|
91
|
+
setViewHierarchyReady(false);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
reactHost.start();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private void checkReactHost() {
|
|
98
|
+
if (reactHost == null) {
|
|
99
|
+
throw new IllegalStateException("Must call ReactManager#install first");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@Nullable
|
|
104
|
+
public ReactContext getCurrentReactContext() {
|
|
105
|
+
return reactHost.getCurrentReactContext();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
@Nullable
|
|
109
|
+
public DevSupportManager getDevSupportManager() {
|
|
110
|
+
checkReactHost();
|
|
111
|
+
return reactHost.getDevSupportManager();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public void registerNativeModule(@NonNull String moduleName, @NonNull Class<? extends HybridFragment> clazz) {
|
|
115
|
+
nativeModules.put(moduleName, clazz);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public boolean hasNativeModule(@NonNull String moduleName) {
|
|
119
|
+
return nativeModules.containsKey(moduleName);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@Nullable
|
|
123
|
+
public Class<? extends HybridFragment> nativeModuleClassForName(@NonNull String moduleName) {
|
|
124
|
+
return nativeModules.get(moduleName);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
public void registerReactModule(@NonNull String moduleName, @Nullable ReadableMap options) {
|
|
128
|
+
reactModules.put(moduleName, options);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public boolean hasReactModule(@NonNull String moduleName) {
|
|
132
|
+
return reactModules.containsKey(moduleName);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
@NonNull
|
|
136
|
+
public ReadableMap reactModuleOptionsForKey(@NonNull String moduleName) {
|
|
137
|
+
ReadableMap map = reactModules.get(moduleName);
|
|
138
|
+
if (map != null) {
|
|
139
|
+
return map;
|
|
140
|
+
}
|
|
141
|
+
return Arguments.createMap();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private boolean reactModuleRegisterCompleted = false;
|
|
145
|
+
|
|
146
|
+
public boolean isReactModuleRegisterCompleted() {
|
|
147
|
+
return reactModuleRegisterCompleted;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
public void setReactModuleRegisterCompleted(boolean reactModuleRegisterCompleted) {
|
|
151
|
+
this.reactModuleRegisterCompleted = reactModuleRegisterCompleted;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
public void startRegisterReactModule() {
|
|
155
|
+
FLog.i(TAG, "ReactManager#startRegisterReactModule");
|
|
156
|
+
reactModules.clear();
|
|
157
|
+
setReactModuleRegisterCompleted(false);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
public void endRegisterReactModule() {
|
|
161
|
+
setReactModuleRegisterCompleted(true);
|
|
162
|
+
FLog.i(TAG, "ReactManager#endRegisterReactModule");
|
|
163
|
+
for (ReactModuleRegisterListener listener : reactModuleRegisterListeners) {
|
|
164
|
+
listener.onReactModuleRegisterCompleted();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
public void addReactModuleRegisterListener(@NonNull ReactModuleRegisterListener listener) {
|
|
169
|
+
reactModuleRegisterListeners.add(listener);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
public void removeReactModuleRegisterListener(@NonNull ReactModuleRegisterListener listener) {
|
|
173
|
+
reactModuleRegisterListeners.remove(listener);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
public void addReactBridgeReloadListener(@NonNull ReactBridgeReloadListener listener) {
|
|
177
|
+
reactBridgeReloadListeners.add(listener);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
public void removeReactBridgeReloadListener(@NonNull ReactBridgeReloadListener listener) {
|
|
181
|
+
reactBridgeReloadListeners.remove(listener);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
public void invalidate() {
|
|
185
|
+
invokeReloadListeners();
|
|
186
|
+
setPendingLayout(null, null);
|
|
187
|
+
setReactModuleRegisterCompleted(false);
|
|
188
|
+
setViewHierarchyReady(false);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
private void invokeReloadListeners() {
|
|
192
|
+
for (ReactManager.ReactBridgeReloadListener listener : reactBridgeReloadListeners) {
|
|
193
|
+
listener.onReload();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
public void setRootLayout(@NonNull ReadableMap root, boolean sticky) {
|
|
198
|
+
if (sticky && !hasStickyLayout()) {
|
|
199
|
+
stickyLayout = root;
|
|
200
|
+
}
|
|
201
|
+
rootLayout = root;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
@Nullable
|
|
205
|
+
public ReadableMap getRootLayout() {
|
|
206
|
+
return rootLayout;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
public boolean hasRootLayout() {
|
|
210
|
+
return rootLayout != null;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
@Nullable
|
|
214
|
+
public ReadableMap getStickyLayout() {
|
|
215
|
+
return stickyLayout;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
public boolean hasStickyLayout() {
|
|
219
|
+
return stickyLayout != null;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
public void setPendingLayout(@Nullable ReadableMap pendingLayout, Callback callback) {
|
|
223
|
+
this.pendingLayout = pendingLayout;
|
|
224
|
+
this.pendingCallback = callback;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
@Nullable
|
|
228
|
+
public ReadableMap getPendingLayout() {
|
|
229
|
+
return pendingLayout;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
public Callback getPendingCallback() {
|
|
233
|
+
return pendingCallback;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
public boolean hasPendingLayout() {
|
|
237
|
+
return pendingLayout != null;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
public boolean isViewHierarchyReady() {
|
|
241
|
+
return viewHierarchyReady;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
public void setViewHierarchyReady(boolean ready) {
|
|
245
|
+
viewHierarchyReady = ready;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
@NonNull
|
|
249
|
+
public ArrayList<Bundle> buildRouteGraph(@NonNull FragmentManager fragmentManager) {
|
|
250
|
+
ArrayList<Bundle> root = new ArrayList<>();
|
|
251
|
+
List<AwesomeFragment> fragments = FragmentHelper.getFragments(fragmentManager);
|
|
252
|
+
for (int i = 0; i < fragments.size(); i++) {
|
|
253
|
+
AwesomeFragment fragment = fragments.get(i);
|
|
254
|
+
Bundle bundle = buildRouteGraph(fragment);
|
|
255
|
+
if (bundle == null) {
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
root.add(bundle);
|
|
259
|
+
}
|
|
260
|
+
return root;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
@Nullable
|
|
264
|
+
public Bundle buildRouteGraph(@NonNull AwesomeFragment fragment) {
|
|
265
|
+
String layout = navigatorRegistry.layoutForFragment(fragment);
|
|
266
|
+
if (layout == null) {
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
Navigator navigator = navigatorRegistry.navigatorForLayout(layout);
|
|
271
|
+
if (navigator != null) {
|
|
272
|
+
return navigator.buildRouteGraph(fragment);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
@Nullable
|
|
279
|
+
public HybridFragment primaryFragment(@NonNull FragmentManager fragmentManager) {
|
|
280
|
+
AwesomeFragment dialog = FragmentHelper.getAwesomeDialogFragment(fragmentManager);
|
|
281
|
+
if (dialog != null) {
|
|
282
|
+
return primaryFragment(dialog);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
Fragment fragment = fragmentManager.findFragmentById(android.R.id.content);
|
|
286
|
+
if (fragment instanceof AwesomeFragment) {
|
|
287
|
+
return primaryFragment((AwesomeFragment) fragment);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
@Nullable
|
|
294
|
+
public HybridFragment primaryFragment(@Nullable AwesomeFragment fragment) {
|
|
295
|
+
if (fragment == null) {
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (fragment.definesPresentationContext()) {
|
|
300
|
+
AwesomeFragment presented = fragment.getPresentedFragment();
|
|
301
|
+
if (presented != null) {
|
|
302
|
+
return primaryFragment(presented);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
String layout = navigatorRegistry.layoutForFragment(fragment);
|
|
307
|
+
if (layout == null) {
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
Navigator navigator = navigatorRegistry.navigatorForLayout(layout);
|
|
312
|
+
if (navigator != null) {
|
|
313
|
+
return navigator.primaryFragment(fragment);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
public void handleNavigation(@NonNull AwesomeFragment target, @NonNull String action, @NonNull ReadableMap extras, @NonNull Callback callback) {
|
|
320
|
+
Navigator navigator = navigatorRegistry.navigatorForAction(action);
|
|
321
|
+
if (navigator != null) {
|
|
322
|
+
navigator.handleNavigation(target, action, extras, callback);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
@Nullable
|
|
327
|
+
public AwesomeFragment createFragment(@Nullable ReadableMap layout) {
|
|
328
|
+
if (layout == null) {
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
List<String> layouts = navigatorRegistry.allLayouts();
|
|
333
|
+
for (String name : layouts) {
|
|
334
|
+
if (!layout.hasKey(name)) {
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
Navigator navigator = navigatorRegistry.navigatorForLayout(name);
|
|
339
|
+
if (navigator == null) {
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
AwesomeFragment fragment = navigator.createFragment(layout);
|
|
344
|
+
if (fragment != null) {
|
|
345
|
+
navigatorRegistry.setLayoutForFragment(name, fragment);
|
|
346
|
+
}
|
|
347
|
+
return fragment;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
throw new IllegalArgumentException("找不到可以处理 " + layout + " 的 navigator, 你是否忘了注册?");
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
@NonNull
|
|
354
|
+
public HybridFragment createFragment(@NonNull String moduleName) {
|
|
355
|
+
return createFragment(moduleName, null, null);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
@NonNull
|
|
359
|
+
public HybridFragment createFragment(@NonNull String moduleName, @Nullable Bundle props, @Nullable Bundle options) {
|
|
360
|
+
if (getCurrentReactContext() == null) {
|
|
361
|
+
throw new IllegalStateException("current react context is null.");
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (!isReactModuleRegisterCompleted()) {
|
|
365
|
+
throw new IllegalStateException("模块还没有注册完,不能执行此操作");
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
HybridFragment fragment = newFragment(moduleName);
|
|
369
|
+
|
|
370
|
+
Bundle args = FragmentHelper.getArguments(fragment);
|
|
371
|
+
args.putBundle(Constants.ARG_PROPS, notNull(props));
|
|
372
|
+
args.putBundle(Constants.ARG_OPTIONS, mergeOptions(moduleName, notNull(options)));
|
|
373
|
+
args.putString(Constants.ARG_MODULE_NAME, moduleName);
|
|
374
|
+
|
|
375
|
+
fragment.setArguments(args);
|
|
376
|
+
|
|
377
|
+
return fragment;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
private Bundle notNull(@Nullable Bundle bundle) {
|
|
381
|
+
if (bundle == null) {
|
|
382
|
+
return new Bundle();
|
|
383
|
+
}
|
|
384
|
+
return bundle;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
private Bundle mergeOptions(@NonNull String moduleName, @NonNull Bundle options) {
|
|
388
|
+
if (!hasReactModule(moduleName)) {
|
|
389
|
+
return options;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
ReadableMap readableMap = reactModuleOptionsForKey(moduleName);
|
|
393
|
+
WritableMap writableMap = Arguments.createMap();
|
|
394
|
+
writableMap.merge(readableMap);
|
|
395
|
+
writableMap.merge(Arguments.fromBundle(options));
|
|
396
|
+
return Arguments.toBundle(writableMap);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
@NonNull
|
|
400
|
+
private HybridFragment newFragment(@NonNull String moduleName) {
|
|
401
|
+
if (hasReactModule(moduleName)) {
|
|
402
|
+
return new ReactFragment();
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
Class<? extends HybridFragment> fragmentClass = nativeModuleClassForName(moduleName);
|
|
406
|
+
if (fragmentClass == null) {
|
|
407
|
+
throw new IllegalArgumentException("未能找到名为 " + moduleName + " 的模块,你是否忘了注册?");
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
try {
|
|
411
|
+
return fragmentClass.newInstance();
|
|
412
|
+
} catch (Exception e) {
|
|
413
|
+
throw new IllegalArgumentException("无法创建名为 " + moduleName + " 的模块。");
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
private final NavigatorRegistry navigatorRegistry = new NavigatorRegistry();
|
|
418
|
+
|
|
419
|
+
public void registerNavigator(@NonNull Navigator navigator) {
|
|
420
|
+
navigatorRegistry.register(navigator);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
public interface MemoryWatcher {
|
|
424
|
+
void watch(Object object);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
private MemoryWatcher memoryWatcher = null;
|
|
428
|
+
|
|
429
|
+
public void setMemoryWatcher(MemoryWatcher memoryWatcher) {
|
|
430
|
+
this.memoryWatcher = memoryWatcher;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
public void watchMemory(Object object) {
|
|
434
|
+
if (memoryWatcher != null) {
|
|
435
|
+
memoryWatcher.watch(object);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
@@ -10,19 +10,13 @@ import com.navigation.androidx.TransitionAnimation;
|
|
|
10
10
|
|
|
11
11
|
public class ReactStackFragment extends StackFragment {
|
|
12
12
|
|
|
13
|
-
private final
|
|
14
|
-
|
|
15
|
-
@NonNull
|
|
16
|
-
public ReactBridgeManager getReactBridgeManager() {
|
|
17
|
-
return bridgeManager;
|
|
18
|
-
}
|
|
13
|
+
private final ReactManager reactManager = ReactManager.get();
|
|
19
14
|
|
|
20
15
|
@Override
|
|
21
16
|
public void setRootFragment(@NonNull AwesomeFragment fragment) {
|
|
22
17
|
super.setRootFragment(fragment);
|
|
23
|
-
if (fragment instanceof HybridFragment) {
|
|
24
|
-
|
|
25
|
-
TabBarItem tabBarItem = hybridFragment.getTabBarItem();
|
|
18
|
+
if (fragment instanceof HybridFragment hybridFragment) {
|
|
19
|
+
TabBarItem tabBarItem = hybridFragment.getTabBarItem();
|
|
26
20
|
if (tabBarItem != null) {
|
|
27
21
|
setTabBarItem(tabBarItem);
|
|
28
22
|
}
|
|
@@ -32,7 +26,7 @@ public class ReactStackFragment extends StackFragment {
|
|
|
32
26
|
@Override
|
|
33
27
|
public void onDestroy() {
|
|
34
28
|
super.onDestroy();
|
|
35
|
-
|
|
29
|
+
reactManager.watchMemory(this);
|
|
36
30
|
}
|
|
37
31
|
|
|
38
32
|
private final static TransitionAnimation BetterPush = new TransitionAnimation(R.anim.nav_push_translucent_enter, R.anim.nav_push_translucent_exit, R.anim.nav_pop_translucent_enter, R.anim.nav_pop_translucent_exit);
|
|
@@ -40,9 +34,8 @@ public class ReactStackFragment extends StackFragment {
|
|
|
40
34
|
|
|
41
35
|
@Override
|
|
42
36
|
protected void pushFragmentSync(AwesomeFragment fragment, @NonNull Runnable completion, @NonNull TransitionAnimation animation) {
|
|
43
|
-
if (fragment instanceof ReactFragment) {
|
|
44
|
-
|
|
45
|
-
if (!reactFragment.shouldAnimatedTransition()) {
|
|
37
|
+
if (fragment instanceof ReactFragment reactFragment) {
|
|
38
|
+
if (!reactFragment.shouldAnimatedTransition()) {
|
|
46
39
|
super.pushFragmentSync(fragment, completion, TransitionAnimation.None);
|
|
47
40
|
return;
|
|
48
41
|
}
|
|
@@ -58,9 +51,8 @@ public class ReactStackFragment extends StackFragment {
|
|
|
58
51
|
@Override
|
|
59
52
|
protected void popToFragmentSync(AwesomeFragment fragment, @NonNull Runnable completion, @NonNull TransitionAnimation animation) {
|
|
60
53
|
AwesomeFragment topFragment = getTopFragment();
|
|
61
|
-
if (topFragment instanceof ReactFragment) {
|
|
62
|
-
|
|
63
|
-
if (!reactFragment.shouldAnimatedTransition()) {
|
|
54
|
+
if (topFragment instanceof ReactFragment reactFragment) {
|
|
55
|
+
if (!reactFragment.shouldAnimatedTransition()) {
|
|
64
56
|
super.popToFragmentSync(fragment, completion, TransitionAnimation.None);
|
|
65
57
|
return;
|
|
66
58
|
}
|
|
@@ -75,9 +67,8 @@ public class ReactStackFragment extends StackFragment {
|
|
|
75
67
|
|
|
76
68
|
@Override
|
|
77
69
|
protected void redirectToFragmentSync(@NonNull AwesomeFragment fragment, @NonNull Runnable completion, @NonNull TransitionAnimation animation, @Nullable AwesomeFragment from) {
|
|
78
|
-
if (fragment instanceof ReactFragment) {
|
|
79
|
-
|
|
80
|
-
if (!reactFragment.shouldAnimatedTransition()) {
|
|
70
|
+
if (fragment instanceof ReactFragment reactFragment) {
|
|
71
|
+
if (!reactFragment.shouldAnimatedTransition()) {
|
|
81
72
|
super.redirectToFragmentSync(fragment, completion, TransitionAnimation.None, from);
|
|
82
73
|
return;
|
|
83
74
|
}
|
|
@@ -19,13 +19,13 @@ public class ReactTabBar extends FrameLayout {
|
|
|
19
19
|
protected static final String TAG = "Navigation";
|
|
20
20
|
|
|
21
21
|
private Drawable shadow = new ColorDrawable(Color.parseColor("#EEEEEE"));
|
|
22
|
-
private Drawable background = new ColorDrawable(Color.WHITE);
|
|
22
|
+
private final Drawable background = new ColorDrawable(Color.WHITE);
|
|
23
23
|
|
|
24
24
|
private FrameLayout mReactHolderView;
|
|
25
25
|
private View mDivider;
|
|
26
26
|
private boolean mSizeIndeterminate;
|
|
27
27
|
private FrameLayout mBackgroundView;
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
private ViewGroup mReactRootView;
|
|
30
30
|
|
|
31
31
|
public ReactTabBar(Context context) {
|
|
@@ -60,7 +60,6 @@ public class ReactTabBar extends FrameLayout {
|
|
|
60
60
|
int layout = mSizeIndeterminate ? R.layout.nav_tab_bar_react_indeterminate : R.layout.nav_tab_bar_react;
|
|
61
61
|
View parentView = inflater.inflate(layout, this, true);
|
|
62
62
|
mBackgroundView = parentView.findViewById(R.id.bottom_navigation_bar_background);
|
|
63
|
-
mBackgroundView.setBackground(background);
|
|
64
63
|
mReactHolderView = parentView.findViewById(R.id.bottom_navigation_bar_react_holder);
|
|
65
64
|
mDivider = parentView.findViewById(R.id.bottom_navigation_bar_divider);
|
|
66
65
|
mDivider.setBackground(shadow);
|
|
@@ -92,22 +91,15 @@ public class ReactTabBar extends FrameLayout {
|
|
|
92
91
|
mReactHolderView.removeAllViews();
|
|
93
92
|
}
|
|
94
93
|
|
|
95
|
-
public void setTabBarBackground(Drawable drawable) {
|
|
96
|
-
background = drawable;
|
|
97
|
-
if (mBackgroundView != null) {
|
|
98
|
-
mBackgroundView.setBackground(drawable);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
94
|
@Override
|
|
103
95
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
104
96
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
105
|
-
|
|
97
|
+
|
|
106
98
|
ViewGroup.LayoutParams params = mReactRootView.getLayoutParams();
|
|
107
99
|
if (params.height > 0) {
|
|
108
100
|
return;
|
|
109
101
|
}
|
|
110
|
-
|
|
102
|
+
|
|
111
103
|
int height = getReactIntrinsicHeight();
|
|
112
104
|
FLog.i(TAG, "[ReactTabBar] intrinsic height:" + height);
|
|
113
105
|
if (height > 0) {
|
|
@@ -115,13 +107,13 @@ public class ReactTabBar extends FrameLayout {
|
|
|
115
107
|
post(mReactRootView::requestLayout);
|
|
116
108
|
}
|
|
117
109
|
}
|
|
118
|
-
|
|
110
|
+
|
|
119
111
|
private int getReactIntrinsicHeight() {
|
|
120
112
|
int rootViewHeight = mReactRootView.getMeasuredHeight();
|
|
121
113
|
if (mReactRootView.getChildCount() > 1 || mReactHolderView.getLayoutParams().height > 0) {
|
|
122
114
|
return rootViewHeight;
|
|
123
115
|
}
|
|
124
|
-
|
|
116
|
+
|
|
125
117
|
ViewGroup group = mReactRootView;
|
|
126
118
|
while (group.getMeasuredHeight() == rootViewHeight) {
|
|
127
119
|
if (group.getChildCount() == 0) {
|
|
@@ -134,5 +126,5 @@ public class ReactTabBar extends FrameLayout {
|
|
|
134
126
|
}
|
|
135
127
|
return rootViewHeight;
|
|
136
128
|
}
|
|
137
|
-
|
|
129
|
+
|
|
138
130
|
}
|