hybrid-navigation 5.0.0 → 5.1.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/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +2 -4
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +48 -2
- package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +2 -2
- package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +7 -0
- package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +2 -4
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +3 -0
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +50 -0
- package/android/src/main/java/com/navigation/androidx/TabBarItem.java +4 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/DispatchResult.java +16 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +19 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +17 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +66 -7
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +116 -18
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +8 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +376 -8
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +72 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +26 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +134 -12
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +35 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +29 -4
- package/dist/NativeEvent.d.ts +15 -0
- package/dist/NativeNavigation.d.ts +8 -0
- package/dist/Navigation.d.ts +14 -1
- package/dist/Navigation.js +153 -12
- package/dist/NavigationComponentWrap.d.ts +3 -2
- package/dist/Navigator.d.ts +3 -2
- package/dist/Navigator.js +28 -9
- package/dist/Options.d.ts +12 -2
- package/dist/Route.d.ts +70 -5
- package/dist/defineRoutes.d.ts +19 -0
- package/dist/defineRoutes.js +6 -0
- package/dist/handler/DispatchCommandHandler.d.ts +16 -1
- package/dist/handler/DispatchCommandHandler.js +63 -5
- package/dist/handler/LayoutCommandHandler.d.ts +1 -0
- package/dist/handler/LayoutCommandHandler.js +3 -0
- package/dist/handler/LeaveGuardHandler.d.ts +17 -0
- package/dist/handler/LeaveGuardHandler.js +350 -0
- package/dist/handler/LifecycleEventHandler.d.ts +7 -3
- package/dist/handler/LifecycleEventHandler.js +36 -3
- package/dist/handler/PresentationCoordinator.d.ts +24 -0
- package/dist/handler/PresentationCoordinator.js +449 -0
- package/dist/handler/ResultEventHandler.d.ts +7 -0
- package/dist/handler/ResultEventHandler.js +13 -5
- package/dist/handler/TabEventHandler.d.ts +8 -0
- package/dist/handler/TabEventHandler.js +25 -0
- package/dist/hooks.d.ts +3 -1
- package/dist/hooks.js +20 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +3 -0
- package/dist/reveal.d.ts +46 -0
- package/dist/reveal.js +431 -0
- package/dist/routeGraph.d.ts +12 -0
- package/dist/routeGraph.js +68 -0
- package/dist/router/index.js +5 -41
- package/dist/router/tabs.d.ts +1 -0
- package/dist/store.d.ts +2 -0
- package/dist/store.js +4 -0
- package/dist/testing.d.ts +79 -0
- package/dist/testing.js +251 -0
- package/ios/HBDGlobalStyle.h +3 -0
- package/ios/HBDGlobalStyle.mm +13 -0
- package/ios/HybridNavigation.h +1 -0
- package/ios/Navigator/HBDScreenNavigator.mm +177 -11
- package/ios/Navigator/HBDStackNavigator.mm +50 -7
- package/ios/Navigator/HBDTabNavigator.mm +33 -5
- package/ios/React/HBDNativeNavigation.mm +73 -12
- package/ios/React/HBDNavigator.h +8 -0
- package/ios/React/HBDOrientationCoordinator.h +2 -0
- package/ios/React/HBDOrientationCoordinator.mm +27 -0
- package/ios/React/HBDReactBridgeManager.h +10 -0
- package/ios/React/HBDReactBridgeManager.mm +48 -2
- package/ios/ViewController/HBDNavigationController.mm +14 -0
- package/ios/ViewController/HBDReactViewController.h +6 -0
- package/ios/ViewController/HBDReactViewController.mm +177 -1
- package/ios/ViewController/HBDTabBarController.h +11 -0
- package/ios/ViewController/HBDTabBarController.mm +170 -3
- package/ios/ViewController/HBDTabBarRenderer.h +28 -0
- package/ios/ViewController/HBDViewController.h +1 -0
- package/ios/ViewController/HBDViewController.mm +57 -9
- package/ios/ViewController/UIViewController+HBD.h +1 -0
- package/ios/ViewController/UIViewController+HBD.mm +13 -4
- package/package.json +3 -1
- package/src/NativeEvent.ts +17 -0
- package/src/NativeNavigation.ts +9 -0
- package/src/Navigation.ts +228 -12
- package/src/NavigationComponentWrap.tsx +11 -2
- package/src/Navigator.ts +38 -9
- package/src/Options.ts +9 -2
- package/src/Route.ts +102 -6
- package/src/defineRoutes.ts +46 -0
- package/src/handler/DispatchCommandHandler.ts +110 -11
- package/src/handler/LayoutCommandHandler.ts +4 -0
- package/src/handler/LeaveGuardHandler.ts +436 -0
- package/src/handler/LifecycleEventHandler.ts +85 -38
- package/src/handler/PresentationCoordinator.ts +560 -0
- package/src/handler/ResultEventHandler.ts +23 -9
- package/src/handler/TabEventHandler.ts +31 -0
- package/src/hooks.ts +37 -1
- package/src/index.ts +11 -0
- package/src/reveal.ts +565 -0
- package/src/routeGraph.ts +87 -0
- package/src/router/index.ts +5 -40
- package/src/router/tabs.ts +1 -0
- package/src/store.ts +5 -0
- package/src/testing.ts +395 -0
- package/testing.d.ts +1 -0
- package/testing.js +3 -0
|
@@ -252,15 +252,13 @@ public abstract class AwesomeActivity extends AppCompatActivity implements Prese
|
|
|
252
252
|
|
|
253
253
|
AwesomeFragment presented = getPresentedFragment(fragment);
|
|
254
254
|
if (presented != null) {
|
|
255
|
-
FragmentHelper.handleDismissFragment(fragment, presented, null, animation);
|
|
256
|
-
completion.run();
|
|
255
|
+
FragmentHelper.handleDismissFragment(fragment, presented, null, animation, completion);
|
|
257
256
|
return;
|
|
258
257
|
}
|
|
259
258
|
|
|
260
259
|
AwesomeFragment presenting = getPresentingFragment(fragment);
|
|
261
260
|
if (presenting != null) {
|
|
262
|
-
FragmentHelper.handleDismissFragment(presenting, fragment, fragment, animation);
|
|
263
|
-
completion.run();
|
|
261
|
+
FragmentHelper.handleDismissFragment(presenting, fragment, fragment, animation, completion);
|
|
264
262
|
return;
|
|
265
263
|
}
|
|
266
264
|
|
|
@@ -60,6 +60,9 @@ public abstract class AwesomeFragment extends Fragment {
|
|
|
60
60
|
mPresentableActivity = presentableActivity;
|
|
61
61
|
mPresentationDelegate.setPresentableActivity(mPresentableActivity);
|
|
62
62
|
inflateStyle();
|
|
63
|
+
if (mBeforeRemoveEnabled) {
|
|
64
|
+
setNeedsBackPressedCallbackUpdate();
|
|
65
|
+
}
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
68
|
|
|
@@ -85,7 +88,11 @@ public abstract class AwesomeFragment extends Fragment {
|
|
|
85
88
|
|
|
86
89
|
mPresentationDelegate.onCreate(savedInstanceState);
|
|
87
90
|
|
|
88
|
-
|
|
91
|
+
if (mHasPendingResult) {
|
|
92
|
+
setResultInternal(mResultCode, mResult);
|
|
93
|
+
} else {
|
|
94
|
+
setResultInternal(0, null);
|
|
95
|
+
}
|
|
89
96
|
}
|
|
90
97
|
|
|
91
98
|
@Override
|
|
@@ -250,6 +257,7 @@ public abstract class AwesomeFragment extends Fragment {
|
|
|
250
257
|
}
|
|
251
258
|
|
|
252
259
|
private TransitionAnimation mAnimation = null;
|
|
260
|
+
private boolean mBeforeRemoveEnabled = false;
|
|
253
261
|
|
|
254
262
|
public void setAnimation(@Nullable TransitionAnimation animation) {
|
|
255
263
|
mAnimation = animation;
|
|
@@ -280,6 +288,19 @@ public abstract class AwesomeFragment extends Fragment {
|
|
|
280
288
|
return anim;
|
|
281
289
|
}
|
|
282
290
|
|
|
291
|
+
public boolean isBeforeRemoveEnabled() {
|
|
292
|
+
return mBeforeRemoveEnabled;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
public void setBeforeRemoveEnabled(boolean enabled) {
|
|
296
|
+
mBeforeRemoveEnabled = enabled;
|
|
297
|
+
setNeedsBackPressedCallbackUpdate();
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
protected boolean onBeforeRemoveBackPressed() {
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
|
|
283
304
|
@Nullable
|
|
284
305
|
private Animation createOurAnimation(int transit, boolean enter, int nextAnim) {
|
|
285
306
|
TransitionAnimation animation = getAnimation();
|
|
@@ -378,6 +399,21 @@ public abstract class AwesomeFragment extends Fragment {
|
|
|
378
399
|
return true;
|
|
379
400
|
}
|
|
380
401
|
|
|
402
|
+
public boolean canInterceptBeforeRemoveBack() {
|
|
403
|
+
if (!isBeforeRemoveEnabled()) {
|
|
404
|
+
return false;
|
|
405
|
+
}
|
|
406
|
+
StackFragment stackFragment = getStackFragment();
|
|
407
|
+
if (stackFragment != null && !isStackRoot()) {
|
|
408
|
+
return true;
|
|
409
|
+
}
|
|
410
|
+
AwesomeFragment host = this;
|
|
411
|
+
while (host.getParentAwesomeFragment() != null && !host.definesPresentationContext()) {
|
|
412
|
+
host = host.getParentAwesomeFragment();
|
|
413
|
+
}
|
|
414
|
+
return host.getPresentingFragment() != null;
|
|
415
|
+
}
|
|
416
|
+
|
|
381
417
|
protected boolean onBackPressed() {
|
|
382
418
|
View root = getView();
|
|
383
419
|
if (root != null && SystemUI.isImeVisible(root)) {
|
|
@@ -385,6 +421,10 @@ public abstract class AwesomeFragment extends Fragment {
|
|
|
385
421
|
return true;
|
|
386
422
|
}
|
|
387
423
|
|
|
424
|
+
if (canInterceptBeforeRemoveBack() && onBeforeRemoveBackPressed()) {
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
|
|
388
428
|
return false;
|
|
389
429
|
}
|
|
390
430
|
|
|
@@ -413,7 +453,7 @@ public abstract class AwesomeFragment extends Fragment {
|
|
|
413
453
|
}
|
|
414
454
|
}
|
|
415
455
|
|
|
416
|
-
return !isBackInteractive();
|
|
456
|
+
return !isBackInteractive() || canInterceptBeforeRemoveBack();
|
|
417
457
|
}
|
|
418
458
|
|
|
419
459
|
public void setNeedsBackPressedCallbackUpdate() {
|
|
@@ -432,8 +472,14 @@ public abstract class AwesomeFragment extends Fragment {
|
|
|
432
472
|
private int mRequestCode;
|
|
433
473
|
private int mResultCode;
|
|
434
474
|
private Bundle mResult;
|
|
475
|
+
private boolean mHasPendingResult;
|
|
435
476
|
|
|
436
477
|
public void setResult(int resultCode, Bundle data) {
|
|
478
|
+
mHasPendingResult = true;
|
|
479
|
+
setResultInternal(resultCode, data);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
private void setResultInternal(int resultCode, Bundle data) {
|
|
437
483
|
mResult = data;
|
|
438
484
|
mResultCode = resultCode;
|
|
439
485
|
if (definesPresentationContext()) {
|
|
@@ -60,7 +60,7 @@ public class DefaultTabBarProvider implements TabBarProvider {
|
|
|
60
60
|
mTabBar.setTabSelectedListener(new TabBar.OnTabSelectedListener() {
|
|
61
61
|
@Override
|
|
62
62
|
public void onTabSelected(int position) {
|
|
63
|
-
mTabBarFragment.
|
|
63
|
+
mTabBarFragment.selectTabByUser(position);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
@Override
|
|
@@ -70,7 +70,7 @@ public class DefaultTabBarProvider implements TabBarProvider {
|
|
|
70
70
|
|
|
71
71
|
@Override
|
|
72
72
|
public void onTabReselected(int position) {
|
|
73
|
-
mTabBarFragment.
|
|
73
|
+
mTabBarFragment.selectTabByUser(position);
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
76
|
|
|
@@ -252,6 +252,10 @@ public class FragmentHelper {
|
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
public static void handleDismissFragment(@NonNull AwesomeFragment presenting, @NonNull AwesomeFragment presented, @Nullable AwesomeFragment top, @NonNull TransitionAnimation animation) {
|
|
255
|
+
handleDismissFragment(presenting, presented, top, animation, null);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
public static void handleDismissFragment(@NonNull AwesomeFragment presenting, @NonNull AwesomeFragment presented, @Nullable AwesomeFragment top, @NonNull TransitionAnimation animation, @Nullable Runnable completion) {
|
|
255
259
|
AwesomeFragment result = getResultFragment(presenting, top);
|
|
256
260
|
result.setAnimation(animation);
|
|
257
261
|
presenting.setAnimation(animation);
|
|
@@ -259,6 +263,9 @@ public class FragmentHelper {
|
|
|
259
263
|
FragmentManager fragmentManager = presenting.getParentFragmentManager();
|
|
260
264
|
fragmentManager.beginTransaction().setMaxLifecycle(presented, Lifecycle.State.STARTED).commitNow();
|
|
261
265
|
fragmentManager.popBackStackImmediate(presented.getSceneId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
|
266
|
+
if (completion != null) {
|
|
267
|
+
completion.run();
|
|
268
|
+
}
|
|
262
269
|
|
|
263
270
|
Bundle args = getArguments(presented);
|
|
264
271
|
String presentingSceneId = args.getString(PresentableActivity.ARG_PRESENTING_SCENE_ID);
|
|
@@ -109,15 +109,13 @@ public class PresentationDelegate {
|
|
|
109
109
|
|
|
110
110
|
AwesomeFragment presented = getPresentedFragment();
|
|
111
111
|
if (presented != null) {
|
|
112
|
-
FragmentHelper.handleDismissFragment(mFragment, presented, null, animation);
|
|
113
|
-
completion.run();
|
|
112
|
+
FragmentHelper.handleDismissFragment(mFragment, presented, null, animation, completion);
|
|
114
113
|
return;
|
|
115
114
|
}
|
|
116
115
|
|
|
117
116
|
AwesomeFragment presenting = getPresentingFragment();
|
|
118
117
|
if (presenting != null) {
|
|
119
|
-
FragmentHelper.handleDismissFragment(presenting, mFragment, mFragment, animation);
|
|
120
|
-
completion.run();
|
|
118
|
+
FragmentHelper.handleDismissFragment(presenting, mFragment, mFragment, animation, completion);
|
|
121
119
|
return;
|
|
122
120
|
}
|
|
123
121
|
|
|
@@ -72,6 +72,9 @@ public class StackFragment extends AwesomeFragment {
|
|
|
72
72
|
@Override
|
|
73
73
|
protected boolean onBackPressed() {
|
|
74
74
|
AwesomeFragment topFragment = getTopFragment();
|
|
75
|
+
if (topFragment != null && topFragment.canInterceptBeforeRemoveBack() && topFragment.onBeforeRemoveBackPressed()) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
75
78
|
if (topFragment != null && !topFragment.isBackInteractive()) {
|
|
76
79
|
return true;
|
|
77
80
|
}
|
|
@@ -194,6 +194,44 @@ public class TabBarFragment extends AwesomeFragment {
|
|
|
194
194
|
return mFragments;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
@Nullable
|
|
198
|
+
private TabBarItem resolveTabBarItem(@NonNull AwesomeFragment fragment) {
|
|
199
|
+
TabBarItem item = fragment.getTabBarItem();
|
|
200
|
+
if (item != null) {
|
|
201
|
+
return item;
|
|
202
|
+
}
|
|
203
|
+
if (fragment instanceof StackFragment stack) {
|
|
204
|
+
AwesomeFragment root = stack.getRootFragment();
|
|
205
|
+
return root != null ? root.getTabBarItem() : null;
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
@NonNull
|
|
211
|
+
public ArrayList<String> getTabKeys() {
|
|
212
|
+
ArrayList<String> keys = new ArrayList<>();
|
|
213
|
+
if (mFragments != null) {
|
|
214
|
+
for (AwesomeFragment fragment : mFragments) {
|
|
215
|
+
TabBarItem item = resolveTabBarItem(fragment);
|
|
216
|
+
keys.add(item != null && item.key != null ? item.key : "");
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return keys;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
public int findIndexByTabKey(@Nullable String key) {
|
|
223
|
+
if (key == null || key.isEmpty() || mFragments == null) {
|
|
224
|
+
return -1;
|
|
225
|
+
}
|
|
226
|
+
for (int i = 0; i < mFragments.size(); i++) {
|
|
227
|
+
TabBarItem item = resolveTabBarItem(mFragments.get(i));
|
|
228
|
+
if (item != null && key.equals(item.key)) {
|
|
229
|
+
return i;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return -1;
|
|
233
|
+
}
|
|
234
|
+
|
|
197
235
|
public void setSelectedFragment(AwesomeFragment fragment) {
|
|
198
236
|
setSelectedFragment(fragment, () -> {
|
|
199
237
|
});
|
|
@@ -240,6 +278,18 @@ public class TabBarFragment extends AwesomeFragment {
|
|
|
240
278
|
});
|
|
241
279
|
}
|
|
242
280
|
|
|
281
|
+
public void selectTabByUser(int index) {
|
|
282
|
+
if (index < 0 || index >= mFragments.size()) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
final int previousIndex = mSelectedIndex;
|
|
286
|
+
final boolean reselected = previousIndex == index;
|
|
287
|
+
setSelectedIndex(index, () -> onTabPressed(index, previousIndex, reselected));
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
protected void onTabPressed(int index, int previousIndex, boolean reselected) {
|
|
291
|
+
}
|
|
292
|
+
|
|
243
293
|
public void setSelectedIndex(int index, @NonNull Runnable completion) {
|
|
244
294
|
if (index < 0 || index >= mFragments.size()) {
|
|
245
295
|
completion.run();
|
|
@@ -11,6 +11,8 @@ public class TabBarItem implements Parcelable {
|
|
|
11
11
|
|
|
12
12
|
@NonNull
|
|
13
13
|
public String title;
|
|
14
|
+
@Nullable
|
|
15
|
+
public String key;
|
|
14
16
|
public String iconUri;
|
|
15
17
|
public String unselectedIconUri;
|
|
16
18
|
@DrawableRes
|
|
@@ -68,6 +70,7 @@ public class TabBarItem implements Parcelable {
|
|
|
68
70
|
@Override
|
|
69
71
|
public void writeToParcel(Parcel dest, int flags) {
|
|
70
72
|
dest.writeString(this.title);
|
|
73
|
+
dest.writeString(this.key);
|
|
71
74
|
dest.writeString(this.iconUri);
|
|
72
75
|
dest.writeString(this.unselectedIconUri);
|
|
73
76
|
dest.writeInt(this.iconRes);
|
|
@@ -80,6 +83,7 @@ public class TabBarItem implements Parcelable {
|
|
|
80
83
|
String title = in.readString();
|
|
81
84
|
assert title != null;
|
|
82
85
|
this.title = title;
|
|
86
|
+
this.key = in.readString();
|
|
83
87
|
this.iconUri = in.readString();
|
|
84
88
|
this.unselectedIconUri = in.readString();
|
|
85
89
|
this.iconRes = in.readInt();
|
|
@@ -14,6 +14,7 @@ public final class DispatchResult {
|
|
|
14
14
|
public static final String CODE_INTERCEPTED = "intercepted";
|
|
15
15
|
public static final String CODE_SCENE_NOT_FOUND = "scene_not_found";
|
|
16
16
|
public static final String CODE_ALREADY_PRESENTING = "already_presenting";
|
|
17
|
+
public static final String CODE_COVERED = "covered";
|
|
17
18
|
public static final String CODE_NOT_READY = "not_ready";
|
|
18
19
|
public static final String CODE_SUPERSEDED = "superseded";
|
|
19
20
|
public static final String CODE_INVALID_ACTION = "invalid_action";
|
|
@@ -24,26 +25,34 @@ public final class DispatchResult {
|
|
|
24
25
|
public final String code;
|
|
25
26
|
@Nullable
|
|
26
27
|
public final String message;
|
|
28
|
+
@Nullable
|
|
29
|
+
public final String sceneId;
|
|
27
30
|
|
|
28
|
-
private DispatchResult(boolean ok, @NonNull String code, @Nullable String message) {
|
|
31
|
+
private DispatchResult(boolean ok, @NonNull String code, @Nullable String message, @Nullable String sceneId) {
|
|
29
32
|
this.ok = ok;
|
|
30
33
|
this.code = code;
|
|
31
34
|
this.message = message;
|
|
35
|
+
this.sceneId = sceneId;
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
@NonNull
|
|
35
39
|
public static DispatchResult ok() {
|
|
36
|
-
return new DispatchResult(true, CODE_OK, null);
|
|
40
|
+
return new DispatchResult(true, CODE_OK, null, null);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@NonNull
|
|
44
|
+
public static DispatchResult ok(@Nullable String sceneId) {
|
|
45
|
+
return new DispatchResult(true, CODE_OK, null, sceneId);
|
|
37
46
|
}
|
|
38
47
|
|
|
39
48
|
@NonNull
|
|
40
49
|
public static DispatchResult fail(@NonNull String code) {
|
|
41
|
-
return new DispatchResult(false, code, null);
|
|
50
|
+
return new DispatchResult(false, code, null, null);
|
|
42
51
|
}
|
|
43
52
|
|
|
44
53
|
@NonNull
|
|
45
54
|
public static DispatchResult fail(@NonNull String code, @Nullable String message) {
|
|
46
|
-
return new DispatchResult(false, code, message);
|
|
55
|
+
return new DispatchResult(false, code, message, null);
|
|
47
56
|
}
|
|
48
57
|
|
|
49
58
|
@NonNull
|
|
@@ -54,6 +63,9 @@ public final class DispatchResult {
|
|
|
54
63
|
if (!TextUtils.isEmpty(message)) {
|
|
55
64
|
map.putString("message", message);
|
|
56
65
|
}
|
|
66
|
+
if (!TextUtils.isEmpty(sceneId)) {
|
|
67
|
+
map.putString("sceneId", sceneId);
|
|
68
|
+
}
|
|
57
69
|
return map;
|
|
58
70
|
}
|
|
59
71
|
}
|
|
@@ -24,11 +24,30 @@ public class GlobalStyle {
|
|
|
24
24
|
|
|
25
25
|
private final Bundle options;
|
|
26
26
|
private final ScreenOrientation defaultOrientation;
|
|
27
|
+
private final int modalBackgroundColor;
|
|
28
|
+
private final boolean injectInitialMetrics;
|
|
29
|
+
private final boolean prewarmPush;
|
|
27
30
|
|
|
28
31
|
public GlobalStyle(@Nullable Bundle options) {
|
|
29
32
|
this.options = options != null ? new Bundle(options) : new Bundle();
|
|
30
33
|
ScreenOrientation parsed = ScreenOrientation.fromString(this.options.getString("orientation"));
|
|
31
34
|
this.defaultOrientation = parsed != null ? parsed : ScreenOrientation.PORTRAIT;
|
|
35
|
+
String modalColor = this.options.getString("modalBackgroundColor");
|
|
36
|
+
this.modalBackgroundColor = modalColor != null ? Color.parseColor(modalColor) : Color.TRANSPARENT;
|
|
37
|
+
this.injectInitialMetrics = this.options.getBoolean("injectInitialMetrics", false);
|
|
38
|
+
this.prewarmPush = this.options.getBoolean("prewarmPush", false);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public int getModalBackgroundColor() {
|
|
42
|
+
return modalBackgroundColor;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public boolean isInjectInitialMetrics() {
|
|
46
|
+
return injectInitialMetrics;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public boolean isPrewarmPush() {
|
|
50
|
+
return prewarmPush;
|
|
32
51
|
}
|
|
33
52
|
|
|
34
53
|
@NonNull
|
|
@@ -45,6 +45,18 @@ public class HBDRootView extends FrameLayout {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
public void setSurface(@NonNull ReactSurface reactSurface) {
|
|
48
|
+
attachSurfaceInternal(reactSurface, null, true);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public void attachPrewarmedSurface(@NonNull ReactSurface reactSurface, @Nullable TaskInterface<Void> existingStartTask) {
|
|
52
|
+
attachSurfaceInternal(reactSurface, existingStartTask, false);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private void attachSurfaceInternal(
|
|
56
|
+
@NonNull ReactSurface reactSurface,
|
|
57
|
+
@Nullable TaskInterface<Void> existingStartTask,
|
|
58
|
+
boolean shouldStart
|
|
59
|
+
) {
|
|
48
60
|
if (surface == reactSurface) {
|
|
49
61
|
return;
|
|
50
62
|
}
|
|
@@ -56,6 +68,9 @@ public class HBDRootView extends FrameLayout {
|
|
|
56
68
|
if (view == null) {
|
|
57
69
|
throw new IllegalStateException("[Navigation] ReactSurface.getView() 不能为空。");
|
|
58
70
|
}
|
|
71
|
+
if (view.getParent() instanceof ViewGroup oldParent && oldParent != this) {
|
|
72
|
+
oldParent.removeView(view);
|
|
73
|
+
}
|
|
59
74
|
|
|
60
75
|
addView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
|
61
76
|
reactSurfaceView = findReactSurfaceView(this);
|
|
@@ -73,11 +88,11 @@ public class HBDRootView extends FrameLayout {
|
|
|
73
88
|
});
|
|
74
89
|
}
|
|
75
90
|
|
|
76
|
-
if (appProperties != null) {
|
|
91
|
+
if (shouldStart && appProperties != null) {
|
|
77
92
|
applyAppProperties(appProperties);
|
|
78
93
|
}
|
|
79
94
|
|
|
80
|
-
startTask = reactSurface.start();
|
|
95
|
+
startTask = shouldStart ? reactSurface.start() : existingStartTask;
|
|
81
96
|
}
|
|
82
97
|
|
|
83
98
|
public void clearSurface() {
|
|
@@ -15,6 +15,7 @@ import androidx.annotation.Nullable;
|
|
|
15
15
|
|
|
16
16
|
import com.facebook.react.bridge.Arguments;
|
|
17
17
|
import com.facebook.react.bridge.ReactContext;
|
|
18
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
18
19
|
import com.facebook.react.bridge.WritableMap;
|
|
19
20
|
import com.facebook.react.common.LifecycleState;
|
|
20
21
|
import com.navigation.androidx.AwesomeFragment;
|
|
@@ -61,9 +62,34 @@ public class HybridFragment extends AwesomeFragment {
|
|
|
61
62
|
payload.putString("sceneId", getSceneId());
|
|
62
63
|
payload.putString("state", newState.getWireValue());
|
|
63
64
|
payload.putString("prevState", prevState.getWireValue());
|
|
65
|
+
String moduleName = getModuleName();
|
|
66
|
+
if (moduleName != null && !moduleName.isEmpty()) {
|
|
67
|
+
payload.putString("moduleName", moduleName);
|
|
68
|
+
}
|
|
69
|
+
String mode = Navigator.Util.getMode(this);
|
|
70
|
+
if (mode != null && !mode.isEmpty()) {
|
|
71
|
+
payload.putString("mode", mode);
|
|
72
|
+
}
|
|
73
|
+
String presentingId = resolvePresentingSceneIdChain();
|
|
74
|
+
if (presentingId != null && !presentingId.isEmpty()) {
|
|
75
|
+
payload.putString("presentingId", presentingId);
|
|
76
|
+
}
|
|
64
77
|
nativeEvent.emitOnSceneStateChange(payload);
|
|
65
78
|
}
|
|
66
79
|
|
|
80
|
+
@Nullable
|
|
81
|
+
private String resolvePresentingSceneIdChain() {
|
|
82
|
+
AwesomeFragment current = this;
|
|
83
|
+
while (current != null) {
|
|
84
|
+
String presentingId = FragmentHelper.getArguments(current).getString(PresentableActivity.ARG_PRESENTING_SCENE_ID);
|
|
85
|
+
if (presentingId != null && !presentingId.isEmpty()) {
|
|
86
|
+
return presentingId;
|
|
87
|
+
}
|
|
88
|
+
current = current.getParentAwesomeFragment();
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
|
|
67
93
|
protected boolean isNativeManagedLifecycle() {
|
|
68
94
|
return true;
|
|
69
95
|
}
|
|
@@ -103,6 +129,19 @@ public class HybridFragment extends AwesomeFragment {
|
|
|
103
129
|
}
|
|
104
130
|
}
|
|
105
131
|
|
|
132
|
+
@Override
|
|
133
|
+
protected boolean onBeforeRemoveBackPressed() {
|
|
134
|
+
NativeEvent event = NativeEvent.getInstance();
|
|
135
|
+
if (event != null) {
|
|
136
|
+
WritableMap data = Arguments.createMap();
|
|
137
|
+
data.putString("sceneId", getSceneId());
|
|
138
|
+
data.putString("action", "back");
|
|
139
|
+
event.emitOnBeforeRemoveRequest(data);
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
|
|
106
145
|
@Override
|
|
107
146
|
public void onDestroyView() {
|
|
108
147
|
super.onDestroyView();
|
|
@@ -167,8 +206,8 @@ public class HybridFragment extends AwesomeFragment {
|
|
|
167
206
|
|
|
168
207
|
private void setBackgroundForModal(@NonNull Style style) {
|
|
169
208
|
int color = mStyle.getScreenBackgroundColor();
|
|
170
|
-
if (Color.alpha(color) == 255) {
|
|
171
|
-
style.setScreenBackgroundColor(
|
|
209
|
+
if (getOptions().getString("screenBackgroundColor") == null || Color.alpha(color) == 255) {
|
|
210
|
+
style.setScreenBackgroundColor(reactManager.getGlobalStyle().getModalBackgroundColor());
|
|
172
211
|
}
|
|
173
212
|
}
|
|
174
213
|
|
|
@@ -203,6 +242,15 @@ public class HybridFragment extends AwesomeFragment {
|
|
|
203
242
|
return garden;
|
|
204
243
|
}
|
|
205
244
|
|
|
245
|
+
public void updateOptions(@NonNull ReadableMap options) {
|
|
246
|
+
if (garden != null) {
|
|
247
|
+
garden.updateOptions(options);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
Bundle patches = Parameters.toBundle(options);
|
|
251
|
+
setOptions(Parameters.mergeOptions(getOptions(), patches));
|
|
252
|
+
}
|
|
253
|
+
|
|
206
254
|
@Override
|
|
207
255
|
protected boolean shouldHideBackButton() {
|
|
208
256
|
return false;
|
|
@@ -293,32 +341,43 @@ public class HybridFragment extends AwesomeFragment {
|
|
|
293
341
|
if (title == null) {
|
|
294
342
|
return;
|
|
295
343
|
}
|
|
344
|
+
String key = tabItem.getString("key");
|
|
296
345
|
|
|
297
346
|
Bundle icon = tabItem.getBundle("icon");
|
|
298
347
|
if (icon == null) {
|
|
299
|
-
|
|
348
|
+
TabBarItem item = new TabBarItem(title);
|
|
349
|
+
item.key = key;
|
|
350
|
+
setTabBarItem(item);
|
|
300
351
|
return;
|
|
301
352
|
}
|
|
302
353
|
|
|
303
354
|
String uri = icon.getString("uri");
|
|
304
355
|
if (uri == null) {
|
|
305
|
-
|
|
356
|
+
TabBarItem item = new TabBarItem(title);
|
|
357
|
+
item.key = key;
|
|
358
|
+
setTabBarItem(item);
|
|
306
359
|
return;
|
|
307
360
|
}
|
|
308
361
|
|
|
309
362
|
Bundle unselectedIcon = tabItem.getBundle("unselectedIcon");
|
|
310
363
|
if (unselectedIcon == null) {
|
|
311
|
-
|
|
364
|
+
TabBarItem item = new TabBarItem(title, uri);
|
|
365
|
+
item.key = key;
|
|
366
|
+
setTabBarItem(item);
|
|
312
367
|
return;
|
|
313
368
|
}
|
|
314
369
|
|
|
315
370
|
String unselectedUri = unselectedIcon.getString("uri");
|
|
316
371
|
if (unselectedUri == null) {
|
|
317
|
-
|
|
372
|
+
TabBarItem item = new TabBarItem(title, uri);
|
|
373
|
+
item.key = key;
|
|
374
|
+
setTabBarItem(item);
|
|
318
375
|
return;
|
|
319
376
|
}
|
|
320
377
|
|
|
321
|
-
|
|
378
|
+
TabBarItem item = new TabBarItem(title, uri, unselectedUri);
|
|
379
|
+
item.key = key;
|
|
380
|
+
setTabBarItem(item);
|
|
322
381
|
}
|
|
323
382
|
|
|
324
383
|
private Bundle props;
|