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
|
@@ -2,10 +2,7 @@ package com.reactnative.hybridnavigation;
|
|
|
2
2
|
|
|
3
3
|
import android.content.Context;
|
|
4
4
|
import android.graphics.Color;
|
|
5
|
-
import android.graphics.Shader;
|
|
6
|
-
import android.graphics.drawable.BitmapDrawable;
|
|
7
5
|
import android.graphics.drawable.ColorDrawable;
|
|
8
|
-
import android.graphics.drawable.Drawable;
|
|
9
6
|
import android.os.Bundle;
|
|
10
7
|
|
|
11
8
|
import androidx.annotation.NonNull;
|
|
@@ -13,7 +10,6 @@ import androidx.annotation.Nullable;
|
|
|
13
10
|
|
|
14
11
|
import com.facebook.common.logging.FLog;
|
|
15
12
|
import com.navigation.androidx.BarStyle;
|
|
16
|
-
import com.navigation.androidx.DrawableUtils;
|
|
17
13
|
import com.navigation.androidx.Style;
|
|
18
14
|
|
|
19
15
|
import java.util.Objects;
|
|
@@ -21,28 +17,23 @@ import java.util.Objects;
|
|
|
21
17
|
public class GlobalStyle {
|
|
22
18
|
|
|
23
19
|
private static final String TAG = "Navigation";
|
|
20
|
+
private static final int DEFAULT_TAB_BAR_SHADOW_COLOR = Color.parseColor("#F0F0F0");
|
|
24
21
|
|
|
25
22
|
private final Bundle options;
|
|
26
23
|
private final ScreenOrientation defaultOrientation;
|
|
27
24
|
private final boolean injectInitialMetrics;
|
|
28
|
-
private final boolean prewarmPush;
|
|
29
25
|
|
|
30
26
|
public GlobalStyle(@Nullable Bundle options) {
|
|
31
27
|
this.options = options != null ? new Bundle(options) : new Bundle();
|
|
32
28
|
ScreenOrientation parsed = ScreenOrientation.fromString(this.options.getString("orientation"));
|
|
33
29
|
this.defaultOrientation = parsed != null ? parsed : ScreenOrientation.PORTRAIT;
|
|
34
30
|
this.injectInitialMetrics = this.options.getBoolean("injectInitialMetrics", false);
|
|
35
|
-
this.prewarmPush = this.options.getBoolean("prewarmPush", false);
|
|
36
31
|
}
|
|
37
32
|
|
|
38
33
|
public boolean isInjectInitialMetrics() {
|
|
39
34
|
return injectInitialMetrics;
|
|
40
35
|
}
|
|
41
36
|
|
|
42
|
-
public boolean isPrewarmPush() {
|
|
43
|
-
return prewarmPush;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
37
|
@NonNull
|
|
47
38
|
public Bundle getOptions() {
|
|
48
39
|
return new Bundle(options);
|
|
@@ -59,10 +50,8 @@ public class GlobalStyle {
|
|
|
59
50
|
return;
|
|
60
51
|
}
|
|
61
52
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
style.setScreenBackgroundColor(Color.parseColor(screenBackgroundColor));
|
|
65
|
-
}
|
|
53
|
+
Integer screenBackgroundColor = Utils.parseColorOrNull(options.getString("screenBackgroundColor"));
|
|
54
|
+
style.setScreenBackgroundColor(screenBackgroundColor != null ? screenBackgroundColor : Color.WHITE);
|
|
66
55
|
|
|
67
56
|
String statusBarStyle = options.getString("statusBarStyle");
|
|
68
57
|
if (statusBarStyle != null) {
|
|
@@ -74,16 +63,12 @@ public class GlobalStyle {
|
|
|
74
63
|
boolean displayCutout = options.getBoolean("displayCutoutWhenLandscapeAndroid", true);
|
|
75
64
|
style.setDisplayCutoutWhenLandscape(displayCutout);
|
|
76
65
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
style.setNavigationBarColor(Color.parseColor(navigationBarColor));
|
|
80
|
-
}
|
|
66
|
+
Integer navigationBarColor = Utils.parseColorOrNull(options.getString("navigationBarColorAndroid"));
|
|
67
|
+
style.setNavigationBarColor(navigationBarColor != null ? navigationBarColor : Style.INVALID_COLOR);
|
|
81
68
|
|
|
82
69
|
// --------- tabBar ------------
|
|
83
70
|
String tabBarBackgroundColor = options.getString("tabBarBackgroundColor");
|
|
84
|
-
|
|
85
|
-
style.setTabBarBackgroundColor(tabBarBackgroundColor);
|
|
86
|
-
}
|
|
71
|
+
style.setTabBarBackgroundColor(tabBarBackgroundColor != null ? tabBarBackgroundColor : "#FFFFFF");
|
|
87
72
|
|
|
88
73
|
String tabBarItemSelectedColor = options.getString("tabBarItemSelectedColor");
|
|
89
74
|
style.setTabBarItemColor(Objects.requireNonNullElse(tabBarItemSelectedColor, "#FF5722"));
|
|
@@ -94,38 +79,15 @@ public class GlobalStyle {
|
|
|
94
79
|
Bundle shadowImage = options.getBundle("tabBarShadowImage");
|
|
95
80
|
if (shadowImage != null) {
|
|
96
81
|
setTabBarShadowImage(context, style, shadowImage);
|
|
82
|
+
} else {
|
|
83
|
+
style.setTabBarShadow(new ColorDrawable(DEFAULT_TAB_BAR_SHADOW_COLOR));
|
|
97
84
|
}
|
|
98
85
|
|
|
99
86
|
String badgeColor = options.getString("tabBarBadgeColor");
|
|
100
|
-
|
|
101
|
-
style.setTabBarBadgeColor(badgeColor);
|
|
102
|
-
}
|
|
87
|
+
style.setTabBarBadgeColor(badgeColor != null ? badgeColor : "#FF3B30");
|
|
103
88
|
}
|
|
104
89
|
|
|
105
90
|
private void setTabBarShadowImage(@NonNull Context context, @NonNull Style style, @NonNull Bundle shadowImage) {
|
|
106
|
-
|
|
107
|
-
if (image != null) {
|
|
108
|
-
style.setTabBarShadow(buildDrawableFromImageBundle(context, image));
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
String color = shadowImage.getString("color");
|
|
113
|
-
if (color != null) {
|
|
114
|
-
style.setTabBarShadow(new ColorDrawable(Color.parseColor(color)));
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
@Nullable
|
|
119
|
-
private Drawable buildDrawableFromImageBundle(@NonNull Context context, @NonNull Bundle image) {
|
|
120
|
-
String uri = image.getString("uri");
|
|
121
|
-
if (uri == null) {
|
|
122
|
-
throw new IllegalArgumentException("必须指定 image 的 uri 字段");
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
Drawable drawable = DrawableUtils.fromUri(context, uri);
|
|
126
|
-
if (drawable instanceof BitmapDrawable bitmapDrawable) {
|
|
127
|
-
bitmapDrawable.setTileModeX(Shader.TileMode.REPEAT);
|
|
128
|
-
}
|
|
129
|
-
return drawable;
|
|
91
|
+
style.setTabBarShadow(Utils.createTabBarShadow(context, shadowImage));
|
|
130
92
|
}
|
|
131
93
|
}
|
|
@@ -23,6 +23,9 @@ public class HBDRootView extends FrameLayout {
|
|
|
23
23
|
@Nullable
|
|
24
24
|
private ReactSurface surface;
|
|
25
25
|
|
|
26
|
+
@Nullable
|
|
27
|
+
private View surfaceRootView;
|
|
28
|
+
|
|
26
29
|
@Nullable
|
|
27
30
|
private ReactSurfaceView reactSurfaceView;
|
|
28
31
|
|
|
@@ -45,18 +48,6 @@ public class HBDRootView extends FrameLayout {
|
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
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
|
-
) {
|
|
60
51
|
if (surface == reactSurface) {
|
|
61
52
|
return;
|
|
62
53
|
}
|
|
@@ -68,12 +59,12 @@ public class HBDRootView extends FrameLayout {
|
|
|
68
59
|
if (view == null) {
|
|
69
60
|
throw new IllegalStateException("[Navigation] ReactSurface.getView() 不能为空。");
|
|
70
61
|
}
|
|
71
|
-
if (view.getParent() instanceof ViewGroup oldParent && oldParent != this) {
|
|
72
|
-
oldParent.removeView(view);
|
|
73
|
-
}
|
|
74
62
|
|
|
75
63
|
addView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
|
76
|
-
|
|
64
|
+
surfaceRootView = view;
|
|
65
|
+
reactSurfaceView = view instanceof ReactSurfaceView sv
|
|
66
|
+
? sv
|
|
67
|
+
: (view instanceof ViewGroup vg ? findReactSurfaceView(vg) : null);
|
|
77
68
|
|
|
78
69
|
// Prevent double-dispatch of ACTION_DOWN to JSTouchDispatcher.
|
|
79
70
|
// ReactRootView dispatches touch events to JS in both onInterceptTouchEvent and onTouchEvent.
|
|
@@ -88,28 +79,36 @@ public class HBDRootView extends FrameLayout {
|
|
|
88
79
|
});
|
|
89
80
|
}
|
|
90
81
|
|
|
91
|
-
if (
|
|
82
|
+
if (appProperties != null) {
|
|
92
83
|
applyAppProperties(appProperties);
|
|
93
84
|
}
|
|
94
85
|
|
|
95
|
-
startTask =
|
|
86
|
+
startTask = reactSurface.start();
|
|
96
87
|
}
|
|
97
88
|
|
|
98
89
|
public void clearSurface() {
|
|
99
|
-
clearSurface(true);
|
|
90
|
+
clearSurface(true, false);
|
|
100
91
|
}
|
|
101
92
|
|
|
102
93
|
public void clearSurface(boolean stopSurface) {
|
|
94
|
+
clearSurface(stopSurface, false);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public void clearSurface(boolean stopSurface, boolean detachImmediately) {
|
|
103
98
|
ReactSurface oldSurface = surface;
|
|
104
99
|
ReactSurfaceView oldReactSurfaceView = reactSurfaceView;
|
|
105
100
|
TaskInterface<Void> oldStartTask = startTask;
|
|
106
|
-
View oldSurfaceRootView =
|
|
101
|
+
View oldSurfaceRootView = surfaceRootView;
|
|
107
102
|
|
|
103
|
+
if (oldSurfaceRootView == null) {
|
|
104
|
+
oldSurfaceRootView = oldReactSurfaceView;
|
|
105
|
+
}
|
|
108
106
|
if (oldSurfaceRootView == null && oldSurface != null) {
|
|
109
107
|
oldSurfaceRootView = oldSurface.getView();
|
|
110
108
|
}
|
|
111
109
|
|
|
112
110
|
surface = null;
|
|
111
|
+
surfaceRootView = null;
|
|
113
112
|
reactSurfaceView = null;
|
|
114
113
|
startTask = null;
|
|
115
114
|
|
|
@@ -117,13 +116,13 @@ public class HBDRootView extends FrameLayout {
|
|
|
117
116
|
oldReactSurfaceView.setOnTouchListener(null);
|
|
118
117
|
}
|
|
119
118
|
|
|
120
|
-
View
|
|
119
|
+
View rootViewToRemove = oldSurfaceRootView;
|
|
121
120
|
if (oldSurface != null && stopSurface) {
|
|
122
|
-
ReactSurfaceCleanup.stopThenRun(oldSurface, oldStartTask, () -> removeSurfaceRootView(
|
|
121
|
+
ReactSurfaceCleanup.stopThenRun(oldSurface, oldStartTask, detachImmediately, () -> removeSurfaceRootView(rootViewToRemove));
|
|
123
122
|
return;
|
|
124
123
|
}
|
|
125
124
|
|
|
126
|
-
removeSurfaceRootView(
|
|
125
|
+
removeSurfaceRootView(rootViewToRemove);
|
|
127
126
|
}
|
|
128
127
|
|
|
129
128
|
public void setAppProperties(@Nullable Bundle appProperties) {
|
|
@@ -36,7 +36,10 @@ public class HybridFragment extends AwesomeFragment {
|
|
|
36
36
|
private final ReactManager reactManager = ReactManager.get();
|
|
37
37
|
|
|
38
38
|
private Garden garden;
|
|
39
|
-
private final SceneLifecycleStateMachine lifecycleStateMachine = new SceneLifecycleStateMachine(
|
|
39
|
+
private final SceneLifecycleStateMachine lifecycleStateMachine = new SceneLifecycleStateMachine(
|
|
40
|
+
this::onSceneLifecycleStateChanged,
|
|
41
|
+
this::isReadyForVisible
|
|
42
|
+
);
|
|
40
43
|
|
|
41
44
|
@NonNull
|
|
42
45
|
public SceneLifecycleStateMachine getLifecycleStateMachine() {
|
|
@@ -74,12 +77,20 @@ public class HybridFragment extends AwesomeFragment {
|
|
|
74
77
|
return reactContext != null && reactContext.getLifecycleState() == LifecycleState.RESUMED;
|
|
75
78
|
}
|
|
76
79
|
|
|
80
|
+
protected boolean canEmitNativeVisibility() {
|
|
81
|
+
return isReactModuleRegisterCompleted() && isReactContextResumed();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
protected boolean isReadyForVisible() {
|
|
85
|
+
return isAdded() && isResumed() && !isResumingForRedirect() && canEmitNativeVisibility();
|
|
86
|
+
}
|
|
87
|
+
|
|
77
88
|
@Override
|
|
78
89
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
79
90
|
super.onViewCreated(view, savedInstanceState);
|
|
80
91
|
if (isNativeManagedLifecycle()) {
|
|
81
92
|
lifecycleStateMachine.onMount();
|
|
82
|
-
lifecycleStateMachine.onFirstRenderComplete(isResumed() && !isResumingForRedirect() &&
|
|
93
|
+
lifecycleStateMachine.onFirstRenderComplete(isResumed() && !isResumingForRedirect() && canEmitNativeVisibility());
|
|
83
94
|
}
|
|
84
95
|
}
|
|
85
96
|
|
|
@@ -91,7 +102,26 @@ public class HybridFragment extends AwesomeFragment {
|
|
|
91
102
|
}
|
|
92
103
|
applySceneOrientation();
|
|
93
104
|
if (isNativeManagedLifecycle()) {
|
|
94
|
-
lifecycleStateMachine.onHostResume(
|
|
105
|
+
lifecycleStateMachine.onHostResume(canEmitNativeVisibility());
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
void syncPausedVisibilityOnReactContextResumed() {
|
|
110
|
+
if ((isResumed() && !isResumingForRedirect())
|
|
111
|
+
|| (!lifecycleStateMachine.isVisible() && !lifecycleStateMachine.isVisibleScheduled())) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (isNativeManagedLifecycle()) {
|
|
115
|
+
lifecycleStateMachine.onHostPause(isReactContextResumed());
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
void syncVisibilityOnReactContextResumed() {
|
|
120
|
+
if (!isResumed() || isResumingForRedirect()) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (isNativeManagedLifecycle()) {
|
|
124
|
+
lifecycleStateMachine.onHostResume(canEmitNativeVisibility());
|
|
95
125
|
}
|
|
96
126
|
}
|
|
97
127
|
|
|
@@ -189,7 +219,7 @@ public class HybridFragment extends AwesomeFragment {
|
|
|
189
219
|
@NonNull
|
|
190
220
|
@Override
|
|
191
221
|
protected BarStyle preferredStatusBarStyle() {
|
|
192
|
-
if (getPresentationStyle() == PresentationStyle.OverFullScreen) {
|
|
222
|
+
if (getPresentationStyle() == PresentationStyle.OverFullScreen && getOptions().getString("statusBarStyle") == null) {
|
|
193
223
|
return SystemUI.activityStatusBarStyle(requireActivity());
|
|
194
224
|
}
|
|
195
225
|
|
|
@@ -198,7 +228,7 @@ public class HybridFragment extends AwesomeFragment {
|
|
|
198
228
|
|
|
199
229
|
@Override
|
|
200
230
|
protected boolean preferredStatusBarHidden() {
|
|
201
|
-
if (getPresentationStyle() == PresentationStyle.OverFullScreen) {
|
|
231
|
+
if (getPresentationStyle() == PresentationStyle.OverFullScreen && getOptions().get("statusBarHidden") == null) {
|
|
202
232
|
return SystemUI.isStatusBarHidden(requireActivity().getWindow());
|
|
203
233
|
}
|
|
204
234
|
|
|
@@ -207,7 +237,7 @@ public class HybridFragment extends AwesomeFragment {
|
|
|
207
237
|
|
|
208
238
|
@Override
|
|
209
239
|
protected boolean preferredNavigationBarHidden() {
|
|
210
|
-
if (getPresentationStyle() == PresentationStyle.OverFullScreen) {
|
|
240
|
+
if (getPresentationStyle() == PresentationStyle.OverFullScreen && getOptions().get("navigationBarHiddenAndroid") == null) {
|
|
211
241
|
return SystemUI.isNavigationBarHidden(requireActivity().getWindow());
|
|
212
242
|
}
|
|
213
243
|
return super.preferredNavigationBarHidden();
|
|
@@ -226,11 +256,6 @@ public class HybridFragment extends AwesomeFragment {
|
|
|
226
256
|
setOptions(Parameters.mergeOptions(getOptions(), patches));
|
|
227
257
|
}
|
|
228
258
|
|
|
229
|
-
@Override
|
|
230
|
-
protected boolean shouldHideBackButton() {
|
|
231
|
-
return false;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
259
|
@Override
|
|
235
260
|
protected boolean isBackInteractive() {
|
|
236
261
|
if (garden != null) {
|
|
@@ -239,7 +264,7 @@ public class HybridFragment extends AwesomeFragment {
|
|
|
239
264
|
return getOptions().getBoolean("backInteractive", true);
|
|
240
265
|
}
|
|
241
266
|
|
|
242
|
-
|
|
267
|
+
public boolean shouldAnimatedTransition() {
|
|
243
268
|
OrientationCoordinator coordinator = getOrientationCoordinator();
|
|
244
269
|
if (coordinator != null && coordinator.requiresOrientationChange(this)) {
|
|
245
270
|
return false;
|
|
@@ -345,39 +370,46 @@ public class HybridFragment extends AwesomeFragment {
|
|
|
345
370
|
}
|
|
346
371
|
|
|
347
372
|
private Bundle props;
|
|
373
|
+
private boolean tabBarInsetInjected;
|
|
348
374
|
|
|
349
375
|
@NonNull
|
|
350
376
|
public Bundle getProps() {
|
|
351
377
|
if (props == null) {
|
|
352
378
|
Bundle args = FragmentHelper.getArguments(this);
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
props = new Bundle();
|
|
356
|
-
}
|
|
379
|
+
Bundle rawProps = args.getBundle(ARG_PROPS);
|
|
380
|
+
props = rawProps != null ? new Bundle(rawProps) : new Bundle();
|
|
357
381
|
props.putString(ARG_SCENE_ID, getSceneId());
|
|
358
|
-
injectTabBarInset(props);
|
|
382
|
+
tabBarInsetInjected = injectTabBarInset(props);
|
|
383
|
+
} else if (!tabBarInsetInjected && isAdded()) {
|
|
384
|
+
tabBarInsetInjected = injectTabBarInset(props);
|
|
359
385
|
}
|
|
360
386
|
return props;
|
|
361
387
|
}
|
|
362
388
|
|
|
363
|
-
private
|
|
389
|
+
private boolean injectTabBarInset(@NonNull Bundle props) {
|
|
364
390
|
TabBarFragment tabBarFragment = getTabBarFragment();
|
|
365
|
-
if (tabBarFragment != null) {
|
|
391
|
+
if (tabBarFragment != null && isAdded()) {
|
|
366
392
|
float tabBarHeightDp = getResources().getDimension(R.dimen.nav_tab_bar_height)
|
|
367
393
|
/ getResources().getDisplayMetrics().density;
|
|
368
394
|
props.putDouble("tabBarInset", tabBarHeightDp);
|
|
395
|
+
return true;
|
|
369
396
|
}
|
|
397
|
+
return false;
|
|
370
398
|
}
|
|
371
399
|
|
|
372
400
|
@CallSuper
|
|
373
401
|
public void setAppProperties(@NonNull Bundle props) {
|
|
402
|
+
Bundle copy = new Bundle(props);
|
|
374
403
|
if (isAdded()) {
|
|
375
|
-
|
|
376
|
-
|
|
404
|
+
copy.putString(ARG_SCENE_ID, getSceneId());
|
|
405
|
+
tabBarInsetInjected = injectTabBarInset(copy);
|
|
406
|
+
this.props = copy;
|
|
377
407
|
} else {
|
|
378
408
|
Bundle args = FragmentHelper.getArguments(this);
|
|
379
|
-
args.putBundle(ARG_PROPS,
|
|
409
|
+
args.putBundle(ARG_PROPS, copy);
|
|
380
410
|
setArguments(args);
|
|
411
|
+
this.props = null;
|
|
412
|
+
this.tabBarInsetInjected = false;
|
|
381
413
|
}
|
|
382
414
|
}
|
|
383
415
|
|
|
@@ -3,6 +3,7 @@ package com.reactnative.hybridnavigation;
|
|
|
3
3
|
import androidx.annotation.NonNull;
|
|
4
4
|
import androidx.annotation.Nullable;
|
|
5
5
|
|
|
6
|
+
import com.facebook.react.bridge.NativeModule;
|
|
6
7
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
7
8
|
import com.facebook.react.bridge.ReactContext;
|
|
8
9
|
import com.facebook.react.module.annotations.ReactModule;
|
|
@@ -26,10 +27,11 @@ public class NativeEvent extends NativeEventSpec {
|
|
|
26
27
|
public static NativeEvent getInstance() {
|
|
27
28
|
ReactManager reactManager = ReactManager.get();
|
|
28
29
|
ReactContext reactContext = reactManager.getCurrentReactContext();
|
|
29
|
-
if (reactContext == null) {
|
|
30
|
+
if (reactContext == null || !reactContext.hasActiveReactInstance()) {
|
|
30
31
|
return null;
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
+
NativeModule module = reactContext.getNativeModule(NAME);
|
|
34
|
+
return module instanceof NativeEvent nativeEvent ? nativeEvent : null;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
}
|
|
@@ -46,6 +46,7 @@ public class NativeNavigation extends NativeNavigationSpec {
|
|
|
46
46
|
super(reactContext);
|
|
47
47
|
this.reactManager = reactManager;
|
|
48
48
|
FLog.i(TAG, "NavigationModule#onCreate");
|
|
49
|
+
UiThreadUtil.runOnUiThread(() -> reactManager.bindNavigationModule(this));
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
@Override
|
|
@@ -59,7 +60,9 @@ public class NativeNavigation extends NativeNavigationSpec {
|
|
|
59
60
|
FLog.i(TAG, "NavigationModule#invalidate");
|
|
60
61
|
UiThreadUtil.runOnUiThread(() -> {
|
|
61
62
|
ReactAppCompatActivity activity = reactManager.getActiveActivity();
|
|
62
|
-
reactManager.
|
|
63
|
+
if (!reactManager.invalidateForModule(this)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
63
66
|
if (activity != null && !activity.isFinishingOrDestroyed()) {
|
|
64
67
|
activity.clearFragments();
|
|
65
68
|
}
|
|
@@ -71,7 +74,6 @@ public class NativeNavigation extends NativeNavigationSpec {
|
|
|
71
74
|
HashMap<String, Object> constants = new HashMap<>();
|
|
72
75
|
constants.put("RESULT_OK", Activity.RESULT_OK);
|
|
73
76
|
constants.put("RESULT_CANCEL", Activity.RESULT_CANCELED);
|
|
74
|
-
constants.put("RESULT_BLOCK", -2);
|
|
75
77
|
return constants;
|
|
76
78
|
}
|
|
77
79
|
|
|
@@ -100,9 +102,6 @@ public class NativeNavigation extends NativeNavigationSpec {
|
|
|
100
102
|
|
|
101
103
|
activity.scheduleTaskAtStarted(() -> {
|
|
102
104
|
AwesomeFragment fragment = FragmentHelper.findAwesomeFragment(activity.getSupportFragmentManager(), sceneId);
|
|
103
|
-
if (fragment == null) {
|
|
104
|
-
fragment = reactManager.findPrewarmingFragmentBySceneId(sceneId);
|
|
105
|
-
}
|
|
106
105
|
if (fragment instanceof ReactFragment reactFragment) {
|
|
107
106
|
reactFragment.signalFirstRenderComplete();
|
|
108
107
|
}
|
|
@@ -144,10 +143,17 @@ public class NativeNavigation extends NativeNavigationSpec {
|
|
|
144
143
|
UiThreadUtil.runOnUiThread(() -> reactManager.enqueueNavigation(sceneId, action, params, callback));
|
|
145
144
|
}
|
|
146
145
|
|
|
146
|
+
@Override
|
|
147
|
+
public void planRemoval(String sceneId, String action, ReadableMap params, Promise promise) {
|
|
148
|
+
resolveWhenReady(promise, () -> RemovalPlan.noop().toWritableMap(), activity ->
|
|
149
|
+
reactManager.planRemoval(activity.getSupportFragmentManager(), sceneId, action, params).toWritableMap()
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
147
153
|
@Override
|
|
148
154
|
public void currentTab(String sceneId, Promise promise) {
|
|
149
|
-
|
|
150
|
-
AwesomeFragment fragment =
|
|
155
|
+
resolveWhenReady(promise, () -> -1, activity -> {
|
|
156
|
+
AwesomeFragment fragment = FragmentHelper.findAwesomeFragment(activity.getSupportFragmentManager(), sceneId);
|
|
151
157
|
if (fragment != null) {
|
|
152
158
|
TabBarFragment tabs = fragment.getTabBarFragment();
|
|
153
159
|
if (tabs != null) {
|
|
@@ -160,8 +166,8 @@ public class NativeNavigation extends NativeNavigationSpec {
|
|
|
160
166
|
|
|
161
167
|
@Override
|
|
162
168
|
public void isStackRoot(String sceneId, Promise promise) {
|
|
163
|
-
|
|
164
|
-
AwesomeFragment fragment =
|
|
169
|
+
resolveWhenReady(promise, () -> false, activity -> {
|
|
170
|
+
AwesomeFragment fragment = FragmentHelper.findAwesomeFragment(activity.getSupportFragmentManager(), sceneId);
|
|
165
171
|
return fragment != null && fragment.isStackRoot();
|
|
166
172
|
});
|
|
167
173
|
}
|
|
@@ -186,7 +192,6 @@ public class NativeNavigation extends NativeNavigationSpec {
|
|
|
186
192
|
bundle.putString("sceneId", current.getSceneId());
|
|
187
193
|
bundle.putString("mode", Navigator.Util.getMode(current));
|
|
188
194
|
bundle.putString("presentingId", resolvePresentingSceneId(current));
|
|
189
|
-
bundle.putInt("requestCode", resolveRequestCode(current));
|
|
190
195
|
return Arguments.fromBundle(bundle);
|
|
191
196
|
}
|
|
192
197
|
|
|
@@ -201,14 +206,6 @@ public class NativeNavigation extends NativeNavigationSpec {
|
|
|
201
206
|
});
|
|
202
207
|
}
|
|
203
208
|
|
|
204
|
-
@Override
|
|
205
|
-
public void routeGraph(Promise promise) {
|
|
206
|
-
resolveWhenReady(promise, Arguments::createArray, activity -> {
|
|
207
|
-
ArrayList<Bundle> graph = reactManager.buildRouteGraph(activity.getSupportFragmentManager());
|
|
208
|
-
return Arguments.fromList(graph);
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
|
|
212
209
|
@Override
|
|
213
210
|
public void navigationSnapshot(Promise promise) {
|
|
214
211
|
resolveWhenReady(promise, () -> {
|
|
@@ -253,11 +250,11 @@ public class NativeNavigation extends NativeNavigationSpec {
|
|
|
253
250
|
}
|
|
254
251
|
|
|
255
252
|
@Override
|
|
256
|
-
public void
|
|
253
|
+
public void setBeforeRemovePolicy(String sceneId, boolean interceptPop, boolean interceptDismiss) {
|
|
257
254
|
UiThreadUtil.runOnUiThread(() -> {
|
|
258
255
|
HybridFragment fragment = findHybridFragmentBySceneId(sceneId);
|
|
259
256
|
if (fragment != null) {
|
|
260
|
-
fragment.
|
|
257
|
+
fragment.setBeforeRemovePolicy(interceptPop, interceptDismiss);
|
|
261
258
|
}
|
|
262
259
|
});
|
|
263
260
|
}
|
|
@@ -287,15 +284,22 @@ public class NativeNavigation extends NativeNavigationSpec {
|
|
|
287
284
|
return;
|
|
288
285
|
}
|
|
289
286
|
|
|
290
|
-
ArrayList
|
|
287
|
+
ArrayList<?> rawList = toList(items);
|
|
291
288
|
ArrayList<Bundle> resolvedList = new ArrayList<>(rawList.size());
|
|
292
|
-
|
|
293
|
-
|
|
289
|
+
ArrayList<String> tabKeys = null;
|
|
290
|
+
for (Object rawItem : rawList) {
|
|
291
|
+
if (!(rawItem instanceof Bundle item)) {
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
if (!(item.get("index") instanceof Number)) {
|
|
294
295
|
String key = item.getString("key");
|
|
295
296
|
if (key == null) {
|
|
296
297
|
continue;
|
|
297
298
|
}
|
|
298
|
-
|
|
299
|
+
if (tabKeys == null) {
|
|
300
|
+
tabKeys = ReactTabBarFragment.tabKeys(tabBarFragment);
|
|
301
|
+
}
|
|
302
|
+
int resolvedIndex = tabKeys.indexOf(key);
|
|
299
303
|
if (resolvedIndex < 0) {
|
|
300
304
|
continue;
|
|
301
305
|
}
|
|
@@ -323,32 +327,6 @@ public class NativeNavigation extends NativeNavigationSpec {
|
|
|
323
327
|
};
|
|
324
328
|
}
|
|
325
329
|
|
|
326
|
-
private void resolveAtStarted(
|
|
327
|
-
@NonNull Promise promise,
|
|
328
|
-
@NonNull Supplier<Object> fallback,
|
|
329
|
-
@NonNull Function<ReactAppCompatActivity, Object> query
|
|
330
|
-
) {
|
|
331
|
-
AtomicBoolean settled = new AtomicBoolean(false);
|
|
332
|
-
Runnable settleFallback = () -> {
|
|
333
|
-
if (settled.compareAndSet(false, true)) {
|
|
334
|
-
promise.resolve(fallback.get());
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
UiThreadUtil.runOnUiThread(() -> {
|
|
338
|
-
ReactAppCompatActivity activity = reactManager.getActiveActivity();
|
|
339
|
-
if (activity == null) {
|
|
340
|
-
settleFallback.run();
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
activity.scheduleTaskAtStarted(() -> {
|
|
344
|
-
Object value = query.apply(activity);
|
|
345
|
-
if (settled.compareAndSet(false, true)) {
|
|
346
|
-
promise.resolve(value);
|
|
347
|
-
}
|
|
348
|
-
}, settleFallback);
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
|
|
352
330
|
private void resolveWhenReady(
|
|
353
331
|
@NonNull Promise promise,
|
|
354
332
|
@NonNull Supplier<Object> fallback,
|
|
@@ -395,18 +373,6 @@ public class NativeNavigation extends NativeNavigationSpec {
|
|
|
395
373
|
return null;
|
|
396
374
|
}
|
|
397
375
|
|
|
398
|
-
private int resolveRequestCode(@NonNull AwesomeFragment fragment) {
|
|
399
|
-
AwesomeFragment current = fragment;
|
|
400
|
-
while (current != null) {
|
|
401
|
-
int requestCode = current.getRequestCode();
|
|
402
|
-
if (requestCode != 0) {
|
|
403
|
-
return requestCode;
|
|
404
|
-
}
|
|
405
|
-
current = current.getParentAwesomeFragment();
|
|
406
|
-
}
|
|
407
|
-
return 0;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
376
|
@Nullable
|
|
411
377
|
private HybridFragment findHybridFragmentBySceneId(String sceneId) {
|
|
412
378
|
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
@@ -418,9 +384,14 @@ public class NativeNavigation extends NativeNavigationSpec {
|
|
|
418
384
|
|
|
419
385
|
@Nullable
|
|
420
386
|
private AwesomeFragment findFragmentBySceneId(String sceneId) {
|
|
421
|
-
|
|
387
|
+
ReactAppCompatActivity activity = reactManager.getActiveActivity();
|
|
388
|
+
if (activity == null || activity.isFinishingOrDestroyed()) {
|
|
389
|
+
FLog.w(TAG, "Activity is unavailable when looking up scene: " + sceneId);
|
|
390
|
+
return null;
|
|
391
|
+
}
|
|
392
|
+
AwesomeFragment fragment = FragmentHelper.findAwesomeFragment(activity.getSupportFragmentManager(), sceneId);
|
|
422
393
|
if (fragment == null) {
|
|
423
|
-
FLog.w(TAG, "
|
|
394
|
+
FLog.w(TAG, "Scene not found: " + sceneId);
|
|
424
395
|
}
|
|
425
396
|
return fragment;
|
|
426
397
|
}
|