hybrid-navigation 5.4.0 → 5.5.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 +1 -0
- package/android/proguard-rules.pro +5 -0
- package/android/src/main/java/com/navigation/androidx/AppUtils.java +8 -1
- package/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +115 -36
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +153 -100
- package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +1 -1
- package/android/src/main/java/com/navigation/androidx/DrawableUtils.java +5 -1
- package/android/src/main/java/com/navigation/androidx/DrawerFragment.java +95 -39
- package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +195 -29
- package/android/src/main/java/com/navigation/androidx/HybridDrawerLayout.java +225 -27
- package/android/src/main/java/com/navigation/androidx/LifecycleDelegate.java +33 -9
- package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +5 -107
- package/android/src/main/java/com/navigation/androidx/StackDelegate.java +37 -10
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +82 -19
- package/android/src/main/java/com/navigation/androidx/Style.java +8 -4
- package/android/src/main/java/com/navigation/androidx/SystemUI.java +17 -5
- package/android/src/main/java/com/navigation/androidx/TabBar.java +69 -29
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +48 -11
- package/android/src/main/java/com/navigation/androidx/TabBarItem.java +1 -2
- package/android/src/main/java/com/navigation/androidx/TabView.java +20 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/Constants.java +1 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +19 -15
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +10 -48
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +22 -23
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +54 -22
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +4 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +35 -64
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +185 -121
- package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +21 -5
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigatorRegistry.java +27 -30
- package/android/src/main/java/com/reactnative/hybridnavigation/OrientationCoordinator.java +41 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/Parameters.java +55 -154
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +30 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivityDelegate.java +12 -37
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +31 -190
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +115 -71
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +27 -16
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactSurfaceCleanup.java +50 -8
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +34 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +39 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/RemovalPlan.java +76 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleStateMachine.java +72 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +19 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +11 -5
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +217 -99
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +122 -59
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +87 -24
- package/dist/DeepLink.d.ts +3 -1
- package/dist/DeepLink.js +39 -19
- package/dist/NativeNavigation.d.ts +8 -5
- package/dist/Navigation.d.ts +9 -24
- package/dist/Navigation.js +32 -97
- package/dist/NavigationComponentWrap.d.ts +1 -2
- package/dist/NavigationComponentWrap.js +0 -15
- package/dist/Navigator.d.ts +7 -5
- package/dist/Navigator.js +38 -33
- package/dist/Options.d.ts +1 -7
- package/dist/Options.js +1 -2
- package/dist/Route.d.ts +24 -12
- package/dist/handler/DispatchCommandHandler.d.ts +4 -5
- package/dist/handler/DispatchCommandHandler.js +37 -16
- package/dist/handler/LayoutCommandHandler.js +18 -3
- package/dist/handler/LeaveGuardHandler.d.ts +12 -8
- package/dist/handler/LeaveGuardHandler.js +174 -281
- package/dist/handler/LifecycleEventHandler.d.ts +7 -4
- package/dist/handler/LifecycleEventHandler.js +119 -32
- package/dist/handler/ResultEventHandler.d.ts +2 -2
- package/dist/handler/ResultEventHandler.js +72 -36
- package/dist/handler/SceneExitHandler.d.ts +6 -0
- package/dist/handler/SceneExitHandler.js +48 -8
- package/dist/hooks.d.ts +1 -0
- package/dist/hooks.js +39 -23
- package/dist/index.d.ts +9 -8
- package/dist/index.js +5 -8
- package/dist/routeGraph.d.ts +5 -0
- package/dist/routeGraph.js +47 -0
- package/dist/router/drawer.d.ts +2 -2
- package/dist/router/drawer.js +19 -9
- package/dist/router/helpers.d.ts +17 -0
- package/dist/router/helpers.js +90 -0
- package/dist/router/index.d.ts +2 -2
- package/dist/router/index.js +169 -97
- package/dist/router/screen.d.ts +2 -2
- package/dist/router/screen.js +16 -7
- package/dist/router/stack.d.ts +2 -2
- package/dist/router/stack.js +24 -49
- package/dist/router/tabs.js +5 -1
- package/dist/store.d.ts +2 -0
- package/dist/store.js +4 -0
- package/ios/HBDGlobalStyle.h +0 -1
- package/ios/HBDGlobalStyle.mm +27 -39
- package/ios/HBDUtils.h +0 -2
- package/ios/HBDUtils.mm +81 -41
- package/ios/Navigator/HBDDrawerNavigator.mm +31 -26
- package/ios/Navigator/HBDNavigatorRegistry.mm +23 -26
- package/ios/Navigator/HBDScreenNavigator.mm +240 -137
- package/ios/Navigator/HBDStackNavigator.mm +147 -97
- package/ios/Navigator/HBDTabNavigator.mm +99 -46
- package/ios/React/HBDNativeEvent.mm +38 -5
- package/ios/React/HBDNativeNavigation.mm +49 -51
- package/ios/React/HBDNavigationCommandQueue.h +55 -0
- package/ios/React/HBDNavigationCommandQueue.mm +341 -0
- package/ios/React/HBDNavigator.h +20 -0
- package/ios/React/HBDOrientationCoordinator.mm +26 -3
- package/ios/React/HBDReactBridgeManager.h +18 -6
- package/ios/React/HBDReactBridgeManager.mm +536 -315
- package/ios/React/HBDSceneLifecycleStateMachine.h +2 -0
- package/ios/React/HBDSceneLifecycleStateMachine.mm +18 -0
- package/ios/View/HBDRootView.h +1 -0
- package/ios/View/HBDRootView.mm +112 -4
- package/ios/View/UIImage+WithBadge.mm +9 -7
- package/ios/ViewController/HBDDrawerController.h +10 -0
- package/ios/ViewController/HBDDrawerController.mm +103 -71
- package/ios/ViewController/HBDNavigationController.mm +166 -58
- package/ios/ViewController/HBDReactViewController.h +0 -4
- package/ios/ViewController/HBDReactViewController.mm +13 -110
- package/ios/ViewController/HBDTabBarController.mm +67 -33
- package/ios/ViewController/HBDViewController.h +6 -0
- package/ios/ViewController/HBDViewController.mm +94 -37
- package/ios/ViewController/UINavigationController+HBD.h +2 -2
- package/ios/ViewController/UINavigationController+HBD.mm +13 -13
- package/ios/ViewController/UIViewController+HBD.h +23 -1
- package/ios/ViewController/UIViewController+HBD.mm +298 -40
- package/package.json +1 -1
- package/src/DeepLink.ts +39 -19
- package/src/NativeNavigation.ts +17 -5
- package/src/Navigation.ts +49 -170
- package/src/NavigationComponentWrap.tsx +1 -16
- package/src/Navigator.ts +50 -52
- package/src/Options.ts +4 -10
- package/src/Route.ts +37 -19
- package/src/handler/DispatchCommandHandler.ts +42 -20
- package/src/handler/LayoutCommandHandler.ts +15 -3
- package/src/handler/LeaveGuardHandler.ts +224 -329
- package/src/handler/LifecycleEventHandler.ts +131 -37
- package/src/handler/ResultEventHandler.ts +71 -37
- package/src/handler/SceneExitHandler.ts +60 -9
- package/src/hooks.ts +54 -26
- package/src/index.ts +77 -8
- package/src/routeGraph.ts +50 -0
- package/src/router/drawer.ts +21 -10
- package/src/router/helpers.ts +113 -0
- package/src/router/index.ts +187 -112
- package/src/router/screen.ts +35 -8
- package/src/router/stack.ts +40 -53
- package/src/router/tabs.ts +5 -1
- package/src/store.ts +5 -0
- package/dist/sceneCoverage.d.ts +0 -2
- package/dist/sceneCoverage.js +0 -25
- package/src/sceneCoverage.ts +0 -30
|
@@ -6,6 +6,8 @@ import android.os.Looper;
|
|
|
6
6
|
import androidx.annotation.NonNull;
|
|
7
7
|
import androidx.annotation.Nullable;
|
|
8
8
|
import androidx.fragment.app.FragmentManager;
|
|
9
|
+
import androidx.lifecycle.Lifecycle;
|
|
10
|
+
import androidx.lifecycle.LifecycleEventObserver;
|
|
9
11
|
|
|
10
12
|
import com.facebook.common.logging.FLog;
|
|
11
13
|
import com.facebook.react.bridge.ReactContext;
|
|
@@ -15,7 +17,6 @@ import com.navigation.androidx.FragmentHelper;
|
|
|
15
17
|
|
|
16
18
|
import java.util.ArrayDeque;
|
|
17
19
|
import java.util.ArrayList;
|
|
18
|
-
import java.util.Iterator;
|
|
19
20
|
import java.util.List;
|
|
20
21
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
21
22
|
|
|
@@ -84,6 +85,7 @@ final class NavigationCommandQueue {
|
|
|
84
85
|
|
|
85
86
|
private static final String TAG = "Navigation";
|
|
86
87
|
private static final long COMMAND_TIMEOUT_MS = 3000L;
|
|
88
|
+
private static final long SET_ROOT_TIMEOUT_MS = 5000L;
|
|
87
89
|
|
|
88
90
|
private final ReactManager reactManager;
|
|
89
91
|
private final Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
@@ -102,21 +104,40 @@ final class NavigationCommandQueue {
|
|
|
102
104
|
@Nullable
|
|
103
105
|
private Runnable activeTimeoutRunnable;
|
|
104
106
|
@Nullable
|
|
105
|
-
private
|
|
107
|
+
private String pendingInstallRootSceneId;
|
|
106
108
|
@Nullable
|
|
107
|
-
private Navigator.Callback
|
|
109
|
+
private Navigator.Callback pendingInstallSetRootCallback;
|
|
110
|
+
|
|
111
|
+
private final LifecycleEventObserver activityLifecycleObserver = (source, event) -> {
|
|
112
|
+
if (event == Lifecycle.Event.ON_START && source == currentActivity) {
|
|
113
|
+
drain();
|
|
114
|
+
if (viewHierarchyReady || !hasQueuedSetRoot()) {
|
|
115
|
+
flushReadyTasks();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
108
119
|
|
|
109
120
|
NavigationCommandQueue(@NonNull ReactManager reactManager) {
|
|
110
121
|
this.reactManager = reactManager;
|
|
111
122
|
}
|
|
112
123
|
|
|
113
124
|
void attachActivity(@NonNull ReactAppCompatActivity activity) {
|
|
125
|
+
if (this.currentActivity == activity) {
|
|
126
|
+
this.viewHierarchyReady = false;
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (this.currentActivity != null) {
|
|
130
|
+
this.currentActivity.getLifecycle().removeObserver(activityLifecycleObserver);
|
|
131
|
+
invalidate("Navigation host was replaced.");
|
|
132
|
+
}
|
|
114
133
|
this.currentActivity = activity;
|
|
115
134
|
this.viewHierarchyReady = false;
|
|
135
|
+
activity.getLifecycle().addObserver(activityLifecycleObserver);
|
|
116
136
|
}
|
|
117
137
|
|
|
118
138
|
boolean detachActivity(@NonNull ReactAppCompatActivity activity) {
|
|
119
139
|
if (this.currentActivity == activity) {
|
|
140
|
+
activity.getLifecycle().removeObserver(activityLifecycleObserver);
|
|
120
141
|
this.currentActivity = null;
|
|
121
142
|
invalidate("Navigation host was destroyed.");
|
|
122
143
|
return true;
|
|
@@ -137,7 +158,7 @@ final class NavigationCommandQueue {
|
|
|
137
158
|
return;
|
|
138
159
|
}
|
|
139
160
|
drain();
|
|
140
|
-
if (viewHierarchyReady) {
|
|
161
|
+
if (viewHierarchyReady || !hasQueuedSetRoot()) {
|
|
141
162
|
flushReadyTasks();
|
|
142
163
|
}
|
|
143
164
|
}
|
|
@@ -150,10 +171,6 @@ final class NavigationCommandQueue {
|
|
|
150
171
|
return rootGeneration;
|
|
151
172
|
}
|
|
152
173
|
|
|
153
|
-
int getCommandGeneration() {
|
|
154
|
-
return commandGeneration;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
174
|
void setViewHierarchyReady(boolean ready) {
|
|
158
175
|
viewHierarchyReady = ready;
|
|
159
176
|
if (ready) {
|
|
@@ -174,21 +191,42 @@ final class NavigationCommandQueue {
|
|
|
174
191
|
}
|
|
175
192
|
|
|
176
193
|
void runWhenViewHierarchyReady(@NonNull ReadyTask task) {
|
|
194
|
+
ReactAppCompatActivity activity = getActiveActivity();
|
|
195
|
+
if (activity != null && (viewHierarchyReady || !hasQueuedSetRoot())) {
|
|
196
|
+
task.execute(activity);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (activity == null && !hasQueuedSetRoot()) {
|
|
200
|
+
task.onCancelled();
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
177
203
|
readyTasks.add(task);
|
|
178
|
-
|
|
179
|
-
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
private void cancelReadyTasks() {
|
|
207
|
+
List<ReadyTask> cancelledReadyTasks = new ArrayList<>(readyTasks);
|
|
208
|
+
readyTasks.clear();
|
|
209
|
+
for (ReadyTask task : cancelledReadyTasks) {
|
|
210
|
+
task.onCancelled();
|
|
180
211
|
}
|
|
181
212
|
}
|
|
182
213
|
|
|
214
|
+
private boolean hasInstalledRoot(@Nullable ReactAppCompatActivity activity) {
|
|
215
|
+
return activity != null && activity.getSupportFragmentManager().findFragmentById(android.R.id.content) != null;
|
|
216
|
+
}
|
|
217
|
+
|
|
183
218
|
private void flushReadyTasks() {
|
|
184
219
|
ReactAppCompatActivity activity = getActiveActivity();
|
|
185
|
-
if (
|
|
220
|
+
if (flushingReadyTasks || activity == null) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (!viewHierarchyReady && hasQueuedSetRoot()) {
|
|
186
224
|
return;
|
|
187
225
|
}
|
|
188
226
|
|
|
189
227
|
flushingReadyTasks = true;
|
|
190
228
|
try {
|
|
191
|
-
while (viewHierarchyReady && !readyTasks.isEmpty()) {
|
|
229
|
+
while ((viewHierarchyReady || !hasQueuedSetRoot()) && !readyTasks.isEmpty()) {
|
|
192
230
|
ReactAppCompatActivity current = getActiveActivity();
|
|
193
231
|
if (current == null) {
|
|
194
232
|
break;
|
|
@@ -222,7 +260,7 @@ final class NavigationCommandQueue {
|
|
|
222
260
|
boolean sticky,
|
|
223
261
|
@NonNull Navigator.Callback callback
|
|
224
262
|
) {
|
|
225
|
-
supersedeQueuedCommands(
|
|
263
|
+
supersedeQueuedCommands("Navigation command was superseded by a newer setRoot call.");
|
|
226
264
|
commands.add(Command.setRoot(layout, sticky, callback));
|
|
227
265
|
drain();
|
|
228
266
|
}
|
|
@@ -233,14 +271,17 @@ final class NavigationCommandQueue {
|
|
|
233
271
|
return;
|
|
234
272
|
}
|
|
235
273
|
|
|
274
|
+
if (!activity.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)
|
|
275
|
+
|| activity.getSupportFragmentManager().isStateSaved()) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
|
|
236
279
|
Command next = commands.peek();
|
|
237
280
|
if (next == null) {
|
|
238
281
|
return;
|
|
239
282
|
}
|
|
240
|
-
if (next.type == CommandType.SET_ROOT) {
|
|
241
|
-
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
283
|
+
if (next.type == CommandType.SET_ROOT && !reactManager.isReactModuleRegisterCompleted()) {
|
|
284
|
+
return;
|
|
244
285
|
}
|
|
245
286
|
|
|
246
287
|
Command command = commands.poll();
|
|
@@ -269,41 +310,61 @@ final class NavigationCommandQueue {
|
|
|
269
310
|
if (generation != commandGeneration) {
|
|
270
311
|
return;
|
|
271
312
|
}
|
|
313
|
+
if (command.type == CommandType.SET_ROOT && !result.ok) {
|
|
314
|
+
if (hasInstalledRoot(getActiveActivity())) {
|
|
315
|
+
if (!hasQueuedSetRoot()) {
|
|
316
|
+
setViewHierarchyReady(true);
|
|
317
|
+
}
|
|
318
|
+
} else {
|
|
319
|
+
cancelReadyTasks();
|
|
320
|
+
}
|
|
321
|
+
}
|
|
272
322
|
if (cb != null) {
|
|
273
323
|
cb.invoke(result);
|
|
274
324
|
}
|
|
275
325
|
executingCommand = false;
|
|
276
|
-
|
|
326
|
+
if (!commands.isEmpty()) {
|
|
327
|
+
mainHandler.post(this::drain);
|
|
328
|
+
}
|
|
277
329
|
};
|
|
278
330
|
|
|
331
|
+
if (command.type == CommandType.SET_ROOT) {
|
|
332
|
+
executeSetRoot(activity, command, generation, completed, finishCommand);
|
|
333
|
+
} else {
|
|
334
|
+
executeDispatch(activity, command, generation, completed, finishCommand);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
private void startCommandTimeout(
|
|
339
|
+
long timeoutMs,
|
|
340
|
+
@NonNull String label,
|
|
341
|
+
boolean bumpRootGeneration,
|
|
342
|
+
int generation,
|
|
343
|
+
@NonNull AtomicBoolean completed,
|
|
344
|
+
@NonNull Navigator.Callback finishCommand
|
|
345
|
+
) {
|
|
346
|
+
if (activeTimeoutRunnable != null) {
|
|
347
|
+
mainHandler.removeCallbacks(activeTimeoutRunnable);
|
|
348
|
+
activeTimeoutRunnable = null;
|
|
349
|
+
}
|
|
279
350
|
Runnable timeoutRunnable = () -> {
|
|
280
351
|
if (!completed.get() && generation == commandGeneration) {
|
|
281
|
-
FLog.w(TAG, "Navigation command timed out, unlocking command queue. action=" +
|
|
282
|
-
if (
|
|
352
|
+
FLog.w(TAG, "Navigation command timed out, unlocking command queue. action=" + label);
|
|
353
|
+
if (bumpRootGeneration) {
|
|
283
354
|
rootGeneration++;
|
|
284
355
|
}
|
|
285
|
-
if (pendingInstallSetRootCallback == finishCommand) {
|
|
286
|
-
pendingInstallSetRootCallback = null;
|
|
287
|
-
}
|
|
288
|
-
if (activeSetRootCallback == finishCommand) {
|
|
289
|
-
activeSetRootCallback = null;
|
|
290
|
-
}
|
|
291
356
|
finishCommand.invoke(DispatchResult.fail(DispatchResult.CODE_NOT_READY, "Navigation command timed out."));
|
|
292
357
|
}
|
|
293
358
|
};
|
|
294
359
|
activeTimeoutRunnable = timeoutRunnable;
|
|
295
|
-
mainHandler.postDelayed(timeoutRunnable,
|
|
296
|
-
|
|
297
|
-
if (command.type == CommandType.SET_ROOT) {
|
|
298
|
-
executeSetRoot(activity, command, finishCommand);
|
|
299
|
-
} else {
|
|
300
|
-
executeDispatch(activity, command, generation, completed, finishCommand);
|
|
301
|
-
}
|
|
360
|
+
mainHandler.postDelayed(timeoutRunnable, timeoutMs);
|
|
302
361
|
}
|
|
303
362
|
|
|
304
363
|
private void executeSetRoot(
|
|
305
364
|
@NonNull ReactAppCompatActivity activity,
|
|
306
365
|
@NonNull Command command,
|
|
366
|
+
int generation,
|
|
367
|
+
@NonNull AtomicBoolean completed,
|
|
307
368
|
@NonNull Navigator.Callback finishCommand
|
|
308
369
|
) {
|
|
309
370
|
ReactContext reactContext = reactManager.getCurrentReactContext();
|
|
@@ -329,9 +390,28 @@ final class NavigationCommandQueue {
|
|
|
329
390
|
if (command.layout != null) {
|
|
330
391
|
reactManager.recordRootLayout(command.layout, command.sticky);
|
|
331
392
|
}
|
|
332
|
-
pendingInstallSetRootCallback = finishCommand;
|
|
333
393
|
FLog.i(TAG, "Have active Activity and React module was registered, set root Fragment immediately.");
|
|
334
|
-
|
|
394
|
+
startCommandTimeout(SET_ROOT_TIMEOUT_MS, "setRoot", true, generation, completed, finishCommand);
|
|
395
|
+
String expectedSceneId = fragment.getSceneId();
|
|
396
|
+
pendingInstallRootSceneId = expectedSceneId;
|
|
397
|
+
pendingInstallSetRootCallback = finishCommand;
|
|
398
|
+
try {
|
|
399
|
+
activity.setActivityRootFragment(fragment);
|
|
400
|
+
} catch (RuntimeException e) {
|
|
401
|
+
FLog.e(TAG, "Failed to install root fragment", e);
|
|
402
|
+
if (expectedSceneId.equals(pendingInstallRootSceneId)) {
|
|
403
|
+
pendingInstallRootSceneId = null;
|
|
404
|
+
pendingInstallSetRootCallback = null;
|
|
405
|
+
}
|
|
406
|
+
finishCommand.invoke(DispatchResult.fail(DispatchResult.CODE_INVALID_ACTION, e.getMessage()));
|
|
407
|
+
return;
|
|
408
|
+
} finally {
|
|
409
|
+
if (expectedSceneId.equals(pendingInstallRootSceneId) && pendingInstallSetRootCallback == finishCommand) {
|
|
410
|
+
pendingInstallRootSceneId = null;
|
|
411
|
+
pendingInstallSetRootCallback = null;
|
|
412
|
+
finishCommand.invoke(DispatchResult.fail(DispatchResult.CODE_INVALID_ACTION, "setActivityRootFragment did not install root fragment."));
|
|
413
|
+
}
|
|
414
|
+
}
|
|
335
415
|
}
|
|
336
416
|
|
|
337
417
|
private void executeDispatch(
|
|
@@ -341,61 +421,60 @@ final class NavigationCommandQueue {
|
|
|
341
421
|
@NonNull AtomicBoolean completed,
|
|
342
422
|
@NonNull Navigator.Callback finishCommand
|
|
343
423
|
) {
|
|
344
|
-
activity.
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
if (!isViewHierarchyReady()) {
|
|
353
|
-
finishCommand.invoke(DispatchResult.fail(DispatchResult.CODE_NOT_READY, "View hierarchy is not ready."));
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
424
|
+
if (activity.isFinishingOrDestroyed()) {
|
|
425
|
+
finishCommand.invoke(DispatchResult.fail(DispatchResult.CODE_HOST_UNAVAILABLE, "Navigation host is unavailable."));
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
if (!isViewHierarchyReady()) {
|
|
429
|
+
finishCommand.invoke(DispatchResult.fail(DispatchResult.CODE_NOT_READY, "View hierarchy is not ready."));
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
356
432
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
433
|
+
String sceneId = command.sceneId;
|
|
434
|
+
String action = command.action;
|
|
435
|
+
ReadableMap extras = command.extras;
|
|
436
|
+
if (sceneId == null || action == null || extras == null) {
|
|
437
|
+
finishCommand.invoke(DispatchResult.fail(DispatchResult.CODE_INVALID_ACTION, "Invalid navigation command."));
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
364
440
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
441
|
+
AwesomeFragment target = FragmentHelper.findAwesomeFragment(activity.getSupportFragmentManager(), sceneId);
|
|
442
|
+
if (target == null) {
|
|
443
|
+
FLog.w(TAG, "Can't find target scene for action:" + action + ", maybe the scene is gone.\nparams: " + extras);
|
|
444
|
+
finishCommand.invoke(DispatchResult.fail(DispatchResult.CODE_SCENE_NOT_FOUND, "Can't find target scene for action: " + action));
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
371
447
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
448
|
+
if (!target.isAdded() || FragmentHelper.isRemoving(target)) {
|
|
449
|
+
finishCommand.invoke(DispatchResult.fail(DispatchResult.CODE_SCENE_NOT_FOUND, "Target scene is detached or being removed."));
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
376
452
|
|
|
453
|
+
startCommandTimeout(COMMAND_TIMEOUT_MS, action, false, generation, completed, finishCommand);
|
|
454
|
+
try {
|
|
377
455
|
reactManager.handleNavigation(target, action, extras, finishCommand);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
});
|
|
456
|
+
} catch (RuntimeException e) {
|
|
457
|
+
FLog.e(TAG, "Failed to handle navigation action: " + action, e);
|
|
458
|
+
finishCommand.invoke(DispatchResult.fail(DispatchResult.CODE_INVALID_ACTION, e.getMessage()));
|
|
459
|
+
}
|
|
383
460
|
}
|
|
384
461
|
|
|
385
462
|
void installRootFragment(
|
|
386
463
|
@NonNull ReactAppCompatActivity activity,
|
|
464
|
+
@NonNull AwesomeFragment fragment,
|
|
387
465
|
@NonNull Runnable installAction
|
|
388
466
|
) {
|
|
389
467
|
long generation = ++rootGeneration;
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
468
|
+
final Navigator.Callback setRootCallback;
|
|
469
|
+
if (fragment.getSceneId().equals(pendingInstallRootSceneId)) {
|
|
470
|
+
setRootCallback = pendingInstallSetRootCallback;
|
|
471
|
+
pendingInstallRootSceneId = null;
|
|
472
|
+
pendingInstallSetRootCallback = null;
|
|
473
|
+
} else {
|
|
474
|
+
setRootCallback = null;
|
|
396
475
|
}
|
|
397
|
-
if (
|
|
398
|
-
|
|
476
|
+
if (setRootCallback == null) {
|
|
477
|
+
supersedeAllCommands("Navigation command was superseded by a root replacement.");
|
|
399
478
|
}
|
|
400
479
|
|
|
401
480
|
setViewHierarchyReady(false);
|
|
@@ -406,7 +485,6 @@ final class NavigationCommandQueue {
|
|
|
406
485
|
|
|
407
486
|
installAction.run();
|
|
408
487
|
|
|
409
|
-
final Navigator.Callback capturedCallback = activeSetRootCallback;
|
|
410
488
|
activity.scheduleTaskAtStarted(() -> {
|
|
411
489
|
if (generation != rootGeneration || activity.isFinishingOrDestroyed()) {
|
|
412
490
|
return;
|
|
@@ -417,33 +495,39 @@ final class NavigationCommandQueue {
|
|
|
417
495
|
}
|
|
418
496
|
activity.updateBackPressedCallbackState();
|
|
419
497
|
setViewHierarchyReady(true);
|
|
420
|
-
if (
|
|
421
|
-
|
|
422
|
-
}
|
|
423
|
-
if (capturedCallback != null) {
|
|
424
|
-
capturedCallback.invoke(DispatchResult.ok());
|
|
498
|
+
if (setRootCallback != null) {
|
|
499
|
+
setRootCallback.invoke(DispatchResult.ok());
|
|
425
500
|
}
|
|
426
501
|
NativeEvent didEvent = NativeEvent.getInstance();
|
|
427
502
|
if (didEvent != null) {
|
|
428
503
|
didEvent.emitDidSetRoot();
|
|
429
504
|
}
|
|
430
505
|
}, () -> {
|
|
431
|
-
if (
|
|
432
|
-
|
|
433
|
-
}
|
|
434
|
-
if (capturedCallback != null) {
|
|
435
|
-
capturedCallback.invoke(DispatchResult.fail(DispatchResult.CODE_HOST_UNAVAILABLE, "Navigation host was destroyed."));
|
|
506
|
+
if (setRootCallback != null) {
|
|
507
|
+
setRootCallback.invoke(DispatchResult.fail(DispatchResult.CODE_HOST_UNAVAILABLE, "Navigation host was destroyed."));
|
|
436
508
|
}
|
|
437
509
|
});
|
|
438
510
|
}
|
|
439
511
|
|
|
440
512
|
void invalidate(@NonNull String reason) {
|
|
513
|
+
abortCommands(DispatchResult.fail(DispatchResult.CODE_HOST_UNAVAILABLE, reason), true, true);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
private void supersedeAllCommands(@NonNull String reason) {
|
|
517
|
+
abortCommands(DispatchResult.fail(DispatchResult.CODE_SUPERSEDED, reason), false, false);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
private void abortCommands(@NonNull DispatchResult failure, boolean cancelReady, boolean bumpRootGeneration) {
|
|
441
521
|
commandGeneration++;
|
|
442
|
-
|
|
522
|
+
if (bumpRootGeneration) {
|
|
523
|
+
rootGeneration++;
|
|
524
|
+
}
|
|
443
525
|
if (activeTimeoutRunnable != null) {
|
|
444
526
|
mainHandler.removeCallbacks(activeTimeoutRunnable);
|
|
445
527
|
activeTimeoutRunnable = null;
|
|
446
528
|
}
|
|
529
|
+
pendingInstallRootSceneId = null;
|
|
530
|
+
pendingInstallSetRootCallback = null;
|
|
447
531
|
executingCommand = false;
|
|
448
532
|
|
|
449
533
|
Command running = activeCommand;
|
|
@@ -451,57 +535,37 @@ final class NavigationCommandQueue {
|
|
|
451
535
|
List<Command> pendingCommands = new ArrayList<>(commands);
|
|
452
536
|
commands.clear();
|
|
453
537
|
|
|
454
|
-
Navigator.Callback pendingInstall = pendingInstallSetRootCallback;
|
|
455
|
-
pendingInstallSetRootCallback = null;
|
|
456
|
-
Navigator.Callback activeSetRoot = activeSetRootCallback;
|
|
457
|
-
activeSetRootCallback = null;
|
|
458
|
-
|
|
459
|
-
List<ReadyTask> cancelledReadyTasks = new ArrayList<>(readyTasks);
|
|
460
|
-
readyTasks.clear();
|
|
461
538
|
viewHierarchyReady = false;
|
|
462
539
|
|
|
463
|
-
DispatchResult unavailable = DispatchResult.fail(DispatchResult.CODE_HOST_UNAVAILABLE, reason);
|
|
464
540
|
if (running != null && running.callback != null) {
|
|
465
541
|
Navigator.Callback cb = running.callback;
|
|
466
542
|
running.callback = null;
|
|
467
|
-
cb.invoke(
|
|
468
|
-
}
|
|
469
|
-
if (pendingInstall != null) {
|
|
470
|
-
pendingInstall.invoke(unavailable);
|
|
471
|
-
}
|
|
472
|
-
if (activeSetRoot != null && activeSetRoot != pendingInstall) {
|
|
473
|
-
activeSetRoot.invoke(unavailable);
|
|
543
|
+
cb.invoke(failure);
|
|
474
544
|
}
|
|
475
545
|
for (Command command : pendingCommands) {
|
|
476
546
|
if (command.callback != null) {
|
|
477
547
|
Navigator.Callback cb = command.callback;
|
|
478
548
|
command.callback = null;
|
|
479
|
-
cb.invoke(
|
|
549
|
+
cb.invoke(failure);
|
|
480
550
|
}
|
|
481
551
|
}
|
|
482
|
-
|
|
483
|
-
|
|
552
|
+
if (cancelReady) {
|
|
553
|
+
cancelReadyTasks();
|
|
484
554
|
}
|
|
485
555
|
}
|
|
486
556
|
|
|
487
|
-
private void supersedeQueuedCommands(
|
|
557
|
+
private void supersedeQueuedCommands(@NonNull String message) {
|
|
488
558
|
if (commands.isEmpty()) {
|
|
489
559
|
return;
|
|
490
560
|
}
|
|
491
|
-
List<
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
queued.callback = null;
|
|
499
|
-
}
|
|
500
|
-
iterator.remove();
|
|
561
|
+
List<Command> pendingCommands = new ArrayList<>(commands);
|
|
562
|
+
commands.clear();
|
|
563
|
+
for (Command queued : pendingCommands) {
|
|
564
|
+
if (queued.callback != null) {
|
|
565
|
+
Navigator.Callback cb = queued.callback;
|
|
566
|
+
queued.callback = null;
|
|
567
|
+
cb.invoke(DispatchResult.fail(DispatchResult.CODE_SUPERSEDED, message));
|
|
501
568
|
}
|
|
502
569
|
}
|
|
503
|
-
for (Navigator.Callback superseded : supersededCallbacks) {
|
|
504
|
-
superseded.invoke(DispatchResult.fail(DispatchResult.CODE_SUPERSEDED, message));
|
|
505
|
-
}
|
|
506
570
|
}
|
|
507
571
|
}
|
|
@@ -23,13 +23,17 @@ public interface Navigator {
|
|
|
23
23
|
|
|
24
24
|
class Util {
|
|
25
25
|
public static String getMode(@NonNull AwesomeFragment fragment) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
AwesomeFragment current = fragment;
|
|
27
|
+
while (current != null) {
|
|
28
|
+
if (current.getPresentationStyle() == PresentationStyle.OverFullScreen) {
|
|
29
|
+
return MODE_MODAL;
|
|
30
|
+
}
|
|
31
|
+
current = current.getParentAwesomeFragment();
|
|
32
|
+
}
|
|
33
|
+
if (fragment.getPresentingFragment() != null) {
|
|
29
34
|
return MODE_PRESENT;
|
|
30
|
-
} else {
|
|
31
|
-
return MODE_NORMAL;
|
|
32
35
|
}
|
|
36
|
+
return MODE_NORMAL;
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
|
|
@@ -50,4 +54,16 @@ public interface Navigator {
|
|
|
50
54
|
|
|
51
55
|
void handleNavigation(@NonNull AwesomeFragment target, @NonNull String action, @NonNull ReadableMap extras, @NonNull Callback callback);
|
|
52
56
|
|
|
57
|
+
@NonNull
|
|
58
|
+
default RemovalPlan planRemoval(@NonNull AwesomeFragment target, @NonNull String action, @NonNull ReadableMap extras) {
|
|
59
|
+
return RemovalPlan.noop();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
default boolean handles(@NonNull AwesomeFragment fragment) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
default void invalidate() {
|
|
67
|
+
}
|
|
68
|
+
|
|
53
69
|
}
|
|
@@ -4,9 +4,7 @@ import androidx.annotation.NonNull;
|
|
|
4
4
|
import androidx.annotation.Nullable;
|
|
5
5
|
|
|
6
6
|
import com.navigation.androidx.AwesomeFragment;
|
|
7
|
-
import com.navigation.androidx.
|
|
8
|
-
import com.navigation.androidx.StackFragment;
|
|
9
|
-
import com.navigation.androidx.TabBarFragment;
|
|
7
|
+
import com.navigation.androidx.FragmentHelper;
|
|
10
8
|
import com.reactnative.hybridnavigation.navigator.DrawerNavigator;
|
|
11
9
|
import com.reactnative.hybridnavigation.navigator.ScreenNavigator;
|
|
12
10
|
import com.reactnative.hybridnavigation.navigator.StackNavigator;
|
|
@@ -19,9 +17,9 @@ import java.util.List;
|
|
|
19
17
|
public class NavigatorRegistry {
|
|
20
18
|
|
|
21
19
|
private final List<String> layouts = new ArrayList<>();
|
|
20
|
+
private final List<Navigator> navigators = new ArrayList<>();
|
|
22
21
|
private final HashMap<String, Navigator> actionNavigatorPairs = new HashMap<>();
|
|
23
22
|
private final HashMap<String, Navigator> layoutNavigatorPairs = new HashMap<>();
|
|
24
|
-
private final HashMap<Class<?>, String> classLayoutPairs = new HashMap<>();
|
|
25
23
|
|
|
26
24
|
public NavigatorRegistry() {
|
|
27
25
|
register(new ScreenNavigator());
|
|
@@ -31,7 +29,12 @@ public class NavigatorRegistry {
|
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
public void register(@NonNull Navigator navigator) {
|
|
34
|
-
|
|
32
|
+
String layout = navigator.name();
|
|
33
|
+
if (layoutNavigatorPairs.containsKey(layout)) {
|
|
34
|
+
Navigator duplicated = layoutNavigatorPairs.get(layout);
|
|
35
|
+
assert duplicated != null;
|
|
36
|
+
throw new IllegalArgumentException("Duplicated layout " + layout + ", which has registered through " + duplicated.getClass().getName());
|
|
37
|
+
}
|
|
35
38
|
|
|
36
39
|
for (String action : navigator.supportActions()) {
|
|
37
40
|
if (actionNavigatorPairs.containsKey(action)) {
|
|
@@ -39,16 +42,14 @@ public class NavigatorRegistry {
|
|
|
39
42
|
assert duplicated != null;
|
|
40
43
|
throw new IllegalArgumentException(navigator.getClass().getName() + " 想要注册的 action " + action + " 已经被 " + duplicated.getClass().getName() + " 所注册。");
|
|
41
44
|
}
|
|
42
|
-
actionNavigatorPairs.put(action, navigator);
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
Navigator duplicated = layoutNavigatorPairs.get(layout);
|
|
48
|
-
assert duplicated != null;
|
|
49
|
-
throw new IllegalArgumentException("Duplicated layout " + layout + ", which has registered through " + duplicated.getClass().getName());
|
|
50
|
-
}
|
|
47
|
+
layouts.add(layout);
|
|
48
|
+
navigators.add(navigator);
|
|
51
49
|
layoutNavigatorPairs.put(layout, navigator);
|
|
50
|
+
for (String action : navigator.supportActions()) {
|
|
51
|
+
actionNavigatorPairs.put(action, navigator);
|
|
52
|
+
}
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
@Nullable
|
|
@@ -63,35 +64,31 @@ public class NavigatorRegistry {
|
|
|
63
64
|
|
|
64
65
|
@Nullable
|
|
65
66
|
public String layoutForFragment(@NonNull AwesomeFragment fragment) {
|
|
66
|
-
String
|
|
67
|
-
if (
|
|
68
|
-
return
|
|
67
|
+
String tagged = FragmentHelper.getArguments(fragment).getString(Constants.ARG_LAYOUT);
|
|
68
|
+
if (tagged != null && layoutNavigatorPairs.containsKey(tagged)) {
|
|
69
|
+
return tagged;
|
|
69
70
|
}
|
|
70
71
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
if (fragment instanceof TabBarFragment) {
|
|
78
|
-
return "tabs";
|
|
79
|
-
}
|
|
80
|
-
if (fragment instanceof DrawerFragment) {
|
|
81
|
-
return "drawer";
|
|
72
|
+
for (int i = navigators.size() - 1; i >= 0; i--) {
|
|
73
|
+
Navigator navigator = navigators.get(i);
|
|
74
|
+
if (navigator.handles(fragment)) {
|
|
75
|
+
return navigator.name();
|
|
76
|
+
}
|
|
82
77
|
}
|
|
83
78
|
|
|
84
79
|
return null;
|
|
85
80
|
}
|
|
86
81
|
|
|
87
82
|
public void setLayoutForFragment(@NonNull String layout, @NonNull AwesomeFragment fragment) {
|
|
88
|
-
|
|
89
|
-
if (current == null || !current.equals(layout)) {
|
|
90
|
-
classLayoutPairs.put(fragment.getClass(), layout);
|
|
91
|
-
}
|
|
83
|
+
FragmentHelper.getArguments(fragment).putString(Constants.ARG_LAYOUT, layout);
|
|
92
84
|
}
|
|
93
85
|
|
|
94
86
|
public List<String> allLayouts() {
|
|
95
87
|
return layouts;
|
|
96
88
|
}
|
|
89
|
+
|
|
90
|
+
@NonNull
|
|
91
|
+
public List<Navigator> allNavigators() {
|
|
92
|
+
return new ArrayList<>(navigators);
|
|
93
|
+
}
|
|
97
94
|
}
|