hybrid-navigation 3.1.1 → 3.1.3
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/reactnative/hybridnavigation/HBDRootView.java +190 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +35 -14
- package/android/src/main/res/layout/nav_fragment_react.xml +2 -4
- package/ios/GlobalStyle.h +0 -6
- package/ios/HBDUtils.mm +24 -0
- package/ios/Navigator/HBDScreenNavigator.mm +2 -0
- package/ios/View/UIImage+WithBadge.mm +29 -3
- package/ios/ViewController/HBDNavigationController.mm +110 -3
- package/ios/ViewController/HBDReactViewController.mm +12 -1
- package/ios/ViewController/HBDViewController.mm +29 -22
- package/ios/ViewController/UINavigationController+HBD.mm +12 -0
- package/ios/ViewController/UIViewController+HBD.mm +8 -1
- package/package.json +1 -1
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
package com.reactnative.hybridnavigation;
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.os.Bundle;
|
|
6
|
+
import android.util.AttributeSet;
|
|
7
|
+
import android.view.MotionEvent;
|
|
8
|
+
import android.view.View;
|
|
9
|
+
import android.view.ViewGroup;
|
|
10
|
+
import android.widget.FrameLayout;
|
|
11
|
+
|
|
12
|
+
import androidx.annotation.NonNull;
|
|
13
|
+
import androidx.annotation.Nullable;
|
|
14
|
+
|
|
15
|
+
import com.facebook.react.bridge.UIManager;
|
|
16
|
+
import com.facebook.react.interfaces.fabric.ReactSurface;
|
|
17
|
+
import com.facebook.react.runtime.ReactSurfaceView;
|
|
18
|
+
import com.facebook.react.uimanager.TouchTargetHelper;
|
|
19
|
+
import com.facebook.react.uimanager.UIManagerHelper;
|
|
20
|
+
import com.facebook.react.uimanager.common.UIManagerType;
|
|
21
|
+
|
|
22
|
+
import java.lang.reflect.InvocationTargetException;
|
|
23
|
+
import java.lang.reflect.Method;
|
|
24
|
+
|
|
25
|
+
public class HBDRootView extends FrameLayout {
|
|
26
|
+
|
|
27
|
+
@Nullable
|
|
28
|
+
private ReactSurface surface;
|
|
29
|
+
|
|
30
|
+
@Nullable
|
|
31
|
+
private ReactSurfaceView reactSurfaceView;
|
|
32
|
+
|
|
33
|
+
private boolean passThroughTouches;
|
|
34
|
+
|
|
35
|
+
@Nullable
|
|
36
|
+
private Bundle appProperties;
|
|
37
|
+
|
|
38
|
+
public HBDRootView(@NonNull Context context) {
|
|
39
|
+
super(context);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public HBDRootView(@NonNull Context context, @Nullable AttributeSet attrs) {
|
|
43
|
+
super(context, attrs);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public HBDRootView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
|
47
|
+
super(context, attrs, defStyleAttr);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public void setPassThroughTouches(boolean passThroughTouches) {
|
|
51
|
+
this.passThroughTouches = passThroughTouches;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public void setSurface(@NonNull ReactSurface reactSurface) {
|
|
55
|
+
if (surface == reactSurface) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
clearSurface();
|
|
60
|
+
surface = reactSurface;
|
|
61
|
+
|
|
62
|
+
View view = reactSurface.getView();
|
|
63
|
+
if (view == null) {
|
|
64
|
+
throw new IllegalStateException("[Navigation] ReactSurface.getView() 不能为空。");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
addView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
|
68
|
+
reactSurfaceView = findReactSurfaceView(this);
|
|
69
|
+
|
|
70
|
+
if (appProperties != null) {
|
|
71
|
+
applyAppProperties(appProperties);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
reactSurface.start();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public void clearSurface() {
|
|
78
|
+
clearSurface(true);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public void clearSurface(boolean stopSurface) {
|
|
82
|
+
if (surface != null && stopSurface) {
|
|
83
|
+
surface.stop();
|
|
84
|
+
}
|
|
85
|
+
surface = null;
|
|
86
|
+
reactSurfaceView = null;
|
|
87
|
+
removeAllViews();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public void setAppProperties(@Nullable Bundle appProperties) {
|
|
91
|
+
this.appProperties = appProperties == null ? null : new Bundle(appProperties);
|
|
92
|
+
applyAppProperties(this.appProperties);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@Override
|
|
96
|
+
public boolean dispatchTouchEvent(MotionEvent ev) {
|
|
97
|
+
if (shouldPassTouches(ev)) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
return super.dispatchTouchEvent(ev);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@SuppressLint("ClickableViewAccessibility")
|
|
104
|
+
@Override
|
|
105
|
+
public boolean onTouchEvent(MotionEvent event) {
|
|
106
|
+
ReactSurfaceView surfaceView = getReactSurfaceView();
|
|
107
|
+
if (surfaceView != null) {
|
|
108
|
+
surfaceView.onChildStartedNativeGesture(surfaceView, event);
|
|
109
|
+
}
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private boolean shouldPassTouches(@NonNull MotionEvent ev) {
|
|
114
|
+
if (!passThroughTouches) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
int action = ev.getAction() & MotionEvent.ACTION_MASK;
|
|
119
|
+
if (action != MotionEvent.ACTION_DOWN) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
ReactSurfaceView surfaceView = getReactSurfaceView();
|
|
124
|
+
if (surfaceView == null) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
ViewGroup rootViewGroup = surfaceView.getRootViewGroup();
|
|
129
|
+
|
|
130
|
+
int tag = TouchTargetHelper.findTargetTagForTouch(ev.getX(), ev.getY(), rootViewGroup);
|
|
131
|
+
UIManager uiManager = UIManagerHelper.getUIManager(surfaceView.getCurrentReactContext(), UIManagerType.FABRIC);
|
|
132
|
+
if (uiManager == null) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
View view = uiManager.resolveView(tag);
|
|
137
|
+
if (view == null) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (view == surfaceView || view == surfaceView.getChildAt(0)) {
|
|
142
|
+
if (view.getWidth() == surfaceView.getWidth() && view.getHeight() == surfaceView.getHeight()) {
|
|
143
|
+
surfaceView.onChildStartedNativeGesture(surfaceView, ev);
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@Nullable
|
|
152
|
+
private ReactSurfaceView getReactSurfaceView() {
|
|
153
|
+
if (reactSurfaceView == null) {
|
|
154
|
+
reactSurfaceView = findReactSurfaceView(this);
|
|
155
|
+
}
|
|
156
|
+
return reactSurfaceView;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
@Nullable
|
|
160
|
+
private ReactSurfaceView findReactSurfaceView(@NonNull ViewGroup parent) {
|
|
161
|
+
for (int i = 0; i < parent.getChildCount(); i++) {
|
|
162
|
+
View child = parent.getChildAt(i);
|
|
163
|
+
if (child instanceof ReactSurfaceView surfaceView) {
|
|
164
|
+
return surfaceView;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (child instanceof ViewGroup childGroup) {
|
|
168
|
+
ReactSurfaceView result = findReactSurfaceView(childGroup);
|
|
169
|
+
if (result != null) {
|
|
170
|
+
return result;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private void applyAppProperties(@Nullable Bundle appProperties) {
|
|
179
|
+
if (appProperties == null || surface == null) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
Method updateInitProps = surface.getClass().getMethod("updateInitProps", Bundle.class);
|
|
185
|
+
updateInitProps.invoke(surface, new Bundle(appProperties));
|
|
186
|
+
} catch (NoSuchMethodException ignored) {
|
|
187
|
+
} catch (IllegalAccessException | InvocationTargetException ignored) {
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -28,9 +28,9 @@ public class ReactFragment extends HybridFragment implements ReactManager.ReactB
|
|
|
28
28
|
|
|
29
29
|
protected static final String TAG = "Navigation";
|
|
30
30
|
|
|
31
|
-
private
|
|
31
|
+
private HBDRootView reactRootView;
|
|
32
32
|
|
|
33
|
-
private ReactSurface
|
|
33
|
+
private ReactSurface reactSurface;
|
|
34
34
|
private ReactSurface reactTitleView;
|
|
35
35
|
private boolean firstRenderCompleted;
|
|
36
36
|
|
|
@@ -38,7 +38,7 @@ public class ReactFragment extends HybridFragment implements ReactManager.ReactB
|
|
|
38
38
|
@Override
|
|
39
39
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
40
40
|
View view = inflater.inflate(R.layout.nav_fragment_react, container, false);
|
|
41
|
-
|
|
41
|
+
reactRootView = view.findViewById(R.id.react_content);
|
|
42
42
|
if (isReactModuleRegisterCompleted()) {
|
|
43
43
|
mountReactView();
|
|
44
44
|
}
|
|
@@ -56,6 +56,7 @@ public class ReactFragment extends HybridFragment implements ReactManager.ReactB
|
|
|
56
56
|
public void onDestroyView() {
|
|
57
57
|
super.onDestroyView();
|
|
58
58
|
unmountReactView();
|
|
59
|
+
reactRootView = null;
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
@Override
|
|
@@ -111,7 +112,7 @@ public class ReactFragment extends HybridFragment implements ReactManager.ReactB
|
|
|
111
112
|
}
|
|
112
113
|
|
|
113
114
|
private boolean isViewReady() {
|
|
114
|
-
if (
|
|
115
|
+
if (reactSurface == null) {
|
|
115
116
|
return false;
|
|
116
117
|
}
|
|
117
118
|
return firstRenderCompleted;
|
|
@@ -159,19 +160,25 @@ public class ReactFragment extends HybridFragment implements ReactManager.ReactB
|
|
|
159
160
|
private void unmountReactView() {
|
|
160
161
|
getReactManager().removeReactBridgeReloadListener(this);
|
|
161
162
|
|
|
163
|
+
boolean canStopSurface = false;
|
|
162
164
|
ReactContext reactContext = getCurrentReactContext();
|
|
163
|
-
if (reactContext
|
|
164
|
-
|
|
165
|
+
if (reactContext != null && reactContext.hasActiveReactInstance()) {
|
|
166
|
+
canStopSurface = true;
|
|
165
167
|
}
|
|
166
168
|
|
|
167
|
-
if (
|
|
169
|
+
if (reactSurface != null) {
|
|
168
170
|
FLog.w(TAG, "销毁页面-:" + getModuleName());
|
|
169
|
-
|
|
170
|
-
|
|
171
|
+
reactSurface = null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (reactRootView != null) {
|
|
175
|
+
reactRootView.clearSurface(canStopSurface);
|
|
171
176
|
}
|
|
172
177
|
|
|
173
178
|
if (reactTitleView != null) {
|
|
174
|
-
|
|
179
|
+
if (canStopSurface) {
|
|
180
|
+
reactTitleView.stop();
|
|
181
|
+
}
|
|
175
182
|
reactTitleView = null;
|
|
176
183
|
}
|
|
177
184
|
}
|
|
@@ -215,10 +222,15 @@ public class ReactFragment extends HybridFragment implements ReactManager.ReactB
|
|
|
215
222
|
private void initReactRootView() {
|
|
216
223
|
ReactHost reactHost = getReactManager().getReactHost();
|
|
217
224
|
ReactSurface reactSurface = reactHost.createSurface(requireContext(), getModuleName(), getProps());
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
225
|
+
this.reactSurface = reactSurface;
|
|
226
|
+
|
|
227
|
+
HBDRootView rootView = reactRootView;
|
|
228
|
+
if (rootView == null) {
|
|
229
|
+
throw new IllegalStateException("[Navigation] HBDRootView 还没有创建。");
|
|
230
|
+
}
|
|
231
|
+
rootView.setPassThroughTouches(shouldPassThroughTouches());
|
|
232
|
+
rootView.setAppProperties(getProps());
|
|
233
|
+
rootView.setSurface(reactSurface);
|
|
222
234
|
}
|
|
223
235
|
|
|
224
236
|
private void initReactTitleView() {
|
|
@@ -244,12 +256,21 @@ public class ReactFragment extends HybridFragment implements ReactManager.ReactB
|
|
|
244
256
|
boolean expanded = "expanded".equals(fitting);
|
|
245
257
|
ReactHost reactHost = getReactManager().getReactHost();
|
|
246
258
|
ReactSurface reactSurface = reactHost.createSurface(requireContext(), moduleName, getProps());
|
|
259
|
+
reactTitleView = reactSurface;
|
|
247
260
|
Toolbar.LayoutParams layoutParams = createTitleLayoutParams(expanded);
|
|
248
261
|
Toolbar toolbar = getToolbar();
|
|
249
262
|
toolbar.addView(reactSurface.getView(), layoutParams);
|
|
250
263
|
reactSurface.start();
|
|
251
264
|
}
|
|
252
265
|
|
|
266
|
+
@Override
|
|
267
|
+
public void setAppProperties(@NonNull Bundle props) {
|
|
268
|
+
super.setAppProperties(props);
|
|
269
|
+
if (isReactModuleRegisterCompleted() && reactRootView != null) {
|
|
270
|
+
reactRootView.setAppProperties(getProps());
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
253
274
|
@NonNull
|
|
254
275
|
private Toolbar.LayoutParams createTitleLayoutParams(boolean expanded) {
|
|
255
276
|
if (expanded) {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
-
<
|
|
2
|
+
<com.reactnative.hybridnavigation.HBDRootView xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
3
|
android:id="@+id/react_content"
|
|
4
4
|
android:layout_width="match_parent"
|
|
5
|
-
android:layout_height="match_parent"
|
|
6
|
-
|
|
7
|
-
</FrameLayout>
|
|
5
|
+
android:layout_height="match_parent" />
|
package/ios/GlobalStyle.h
CHANGED
|
@@ -14,12 +14,6 @@
|
|
|
14
14
|
|
|
15
15
|
- (instancetype)initWithOptions:(NSDictionary *)options;
|
|
16
16
|
|
|
17
|
-
- (void)inflateNavigationBar:(UINavigationBar *)navigationBar;
|
|
18
|
-
|
|
19
|
-
- (void)inflateBarButtonItem:(UIBarButtonItem *)barButtonItem;
|
|
20
|
-
|
|
21
|
-
- (void)inflateTabBar:(UITabBar *)tabBar;
|
|
22
|
-
|
|
23
17
|
- (UIColor *)titleTextColorWithBarStyle:(UIBarStyle)barStyle;
|
|
24
18
|
|
|
25
19
|
- (UIColor *)tintColorWithBarStyle:(UIBarStyle)barStyle;
|
package/ios/HBDUtils.mm
CHANGED
|
@@ -2,8 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
#import <React/RCTConvert.h>
|
|
4
4
|
|
|
5
|
+
@implementation UIScrollView (HBDEdgeEffect)
|
|
6
|
+
|
|
7
|
+
- (void)hbd_didMoveToWindow {
|
|
8
|
+
[self hbd_didMoveToWindow];
|
|
9
|
+
|
|
10
|
+
if (@available(iOS 26.0, *)) {
|
|
11
|
+
self.topEdgeEffect.hidden = YES;
|
|
12
|
+
self.leftEdgeEffect.hidden = YES;
|
|
13
|
+
self.bottomEdgeEffect.hidden = YES;
|
|
14
|
+
self.rightEdgeEffect.hidden = YES;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@end
|
|
19
|
+
|
|
5
20
|
@implementation HBDUtils
|
|
6
21
|
|
|
22
|
+
+ (void)load {
|
|
23
|
+
if (@available(iOS 26.0, *)) {
|
|
24
|
+
static dispatch_once_t onceToken;
|
|
25
|
+
dispatch_once(&onceToken, ^{
|
|
26
|
+
hbd_exchangeImplementations([UIScrollView class], @selector(didMoveToWindow), @selector(hbd_didMoveToWindow));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
7
31
|
+ (NSDictionary *)mergeItem:(NSDictionary *)item withTarget:(NSDictionary *)target {
|
|
8
32
|
NSMutableDictionary *mutableTarget = [target mutableCopy];
|
|
9
33
|
for (NSString *key in [item allKeys]) {
|
|
@@ -140,6 +140,7 @@
|
|
|
140
140
|
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
141
141
|
UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:layout];
|
|
142
142
|
[vc setRequestCode:requestCode];
|
|
143
|
+
[vc setPresentingSceneId:presenting.sceneId];
|
|
143
144
|
vc.modalPresentationStyle = UIModalPresentationCurrentContext;
|
|
144
145
|
|
|
145
146
|
[presenting presentViewController:vc animated:YES completion:^{
|
|
@@ -154,6 +155,7 @@
|
|
|
154
155
|
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|
155
156
|
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
|
|
156
157
|
[vc setRequestCode:requestCode];
|
|
158
|
+
[vc setPresentingSceneId:presenting.sceneId];
|
|
157
159
|
|
|
158
160
|
[presenting presentViewController:vc animated:YES completion:^{
|
|
159
161
|
callback(@[NSNull.null, @YES]);
|
|
@@ -4,20 +4,46 @@
|
|
|
4
4
|
|
|
5
5
|
- (UIImage *)withIconColor:(UIColor *)iconColor badgeColor:(UIColor *)badgeColor {
|
|
6
6
|
CGSize imageSize = self.size;
|
|
7
|
+
if (badgeColor == nil || CGColorGetAlpha(badgeColor.CGColor) <= 0.0) {
|
|
8
|
+
UIGraphicsImageRenderer *render = [[UIGraphicsImageRenderer alloc] initWithSize:imageSize];
|
|
9
|
+
UIImage *resultImage = [render imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
|
|
10
|
+
UIImage *iconTintedImage = [self imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
|
|
11
|
+
[iconColor set];
|
|
12
|
+
[iconTintedImage drawAtPoint:CGPointZero];
|
|
13
|
+
}];
|
|
14
|
+
return [resultImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static CGFloat const HBDTabBarBadgeHorizontalPadding = 8.0;
|
|
18
|
+
static CGFloat const HBDTabBarBadgeVerticalPadding = 2.0;
|
|
19
|
+
static CGFloat const HBDTabBarBadgeOffsetX = 0.0;
|
|
20
|
+
static CGFloat const HBDTabBarBadgeOffsetY = 0.0;
|
|
21
|
+
CGSize canvasSize = CGSizeMake(
|
|
22
|
+
imageSize.width + HBDTabBarBadgeHorizontalPadding * 2,
|
|
23
|
+
imageSize.height + HBDTabBarBadgeVerticalPadding * 2
|
|
24
|
+
);
|
|
7
25
|
|
|
8
|
-
UIGraphicsImageRenderer *render = [[UIGraphicsImageRenderer alloc] initWithSize:
|
|
26
|
+
UIGraphicsImageRenderer *render = [[UIGraphicsImageRenderer alloc] initWithSize:canvasSize];
|
|
9
27
|
|
|
10
28
|
UIImage *resultImage = [render imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
|
|
11
29
|
// 创建 tint 后的图标图片
|
|
12
30
|
UIImage *iconTintedImage = [self imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
|
|
31
|
+
CGPoint iconOrigin = CGPointMake(
|
|
32
|
+
(canvasSize.width - imageSize.width) / 2.0,
|
|
33
|
+
(canvasSize.height - imageSize.height) / 2.0
|
|
34
|
+
);
|
|
35
|
+
CGRect iconFrame = CGRectMake(iconOrigin.x, iconOrigin.y, imageSize.width, imageSize.height);
|
|
13
36
|
|
|
14
37
|
// 设置图标颜色并绘制
|
|
15
38
|
[iconColor set];
|
|
16
|
-
[iconTintedImage drawAtPoint:
|
|
39
|
+
[iconTintedImage drawAtPoint:iconOrigin];
|
|
17
40
|
|
|
18
41
|
// 创建徽章
|
|
19
42
|
CGSize badgeSize = CGSizeMake(8, 8);
|
|
20
|
-
CGPoint badgeOrigin = CGPointMake(
|
|
43
|
+
CGPoint badgeOrigin = CGPointMake(
|
|
44
|
+
CGRectGetMaxX(iconFrame) + HBDTabBarBadgeOffsetX,
|
|
45
|
+
HBDTabBarBadgeOffsetY
|
|
46
|
+
);
|
|
21
47
|
CGRect badgeRect = CGRectMake(badgeOrigin.x, badgeOrigin.y, badgeSize.width, badgeSize.height);
|
|
22
48
|
|
|
23
49
|
UIBezierPath *badgePath = [UIBezierPath bezierPathWithOvalInRect:badgeRect];
|
|
@@ -25,6 +25,14 @@
|
|
|
25
25
|
- (instancetype)initWithNavigationController:(HBDNavigationController *)navigationController;
|
|
26
26
|
- (void)hbd_compensateSafeAreaForViewController:(UIViewController *)vc expectedTopInset:(CGFloat)expectedTopInset isToVC:(BOOL)isToVC;
|
|
27
27
|
- (void)hbd_restoreCompensatedSafeAreaForFrom:(UIViewController *)from to:(UIViewController *)to viewController:(UIViewController *)viewController;
|
|
28
|
+
- (BOOL)shouldAnimateTabBarFrom:(UIViewController *)from to:(UIViewController *)to;
|
|
29
|
+
- (void)prepareTabBarForTransitionFrom:(UIViewController *)from to:(UIViewController *)to;
|
|
30
|
+
- (void)animateTabBarForTransitionFrom:(UIViewController *)from to:(UIViewController *)to;
|
|
31
|
+
- (void)completeTabBarTransitionFrom:(UIViewController *)from
|
|
32
|
+
to:(UIViewController *)to
|
|
33
|
+
cancelled:(BOOL)cancelled;
|
|
34
|
+
- (BOOL)shouldUseFadeAnimationFrom:(UIViewController *)from to:(UIViewController *)to;
|
|
35
|
+
- (BOOL)shouldHandleInteractiveTransitionWithNavigationController:(HBDNavigationController *)nav;
|
|
28
36
|
|
|
29
37
|
@end
|
|
30
38
|
|
|
@@ -99,9 +107,12 @@
|
|
|
99
107
|
HBDNavigationController *nav = self.nav;
|
|
100
108
|
|
|
101
109
|
id <UIViewControllerTransitionCoordinator> coordinator = nav.transitionCoordinator;
|
|
110
|
+
BOOL shouldHandleInteractiveTransition =
|
|
111
|
+
[self shouldBetterTransitionWithViewController:nav.topViewController] ||
|
|
112
|
+
[self shouldHandleInteractiveTransitionWithNavigationController:nav];
|
|
102
113
|
|
|
103
114
|
if (![self.proxyDelegate respondsToSelector:@selector(navigationController:interactionControllerForAnimationController:)]) {
|
|
104
|
-
if (self.interactiveTransition || (!coordinator &&
|
|
115
|
+
if (self.interactiveTransition || (!coordinator && shouldHandleInteractiveTransition)) {
|
|
105
116
|
CGFloat process = [pan translationInView:nav.view].x / nav.view.bounds.size.width;
|
|
106
117
|
process = MIN(1.0, (MAX(0.0, process)));
|
|
107
118
|
if (pan.state == UIGestureRecognizerStateBegan) {
|
|
@@ -173,13 +184,20 @@
|
|
|
173
184
|
if (self.proxyDelegate && [self.proxyDelegate respondsToSelector:@selector(navigationControllerSupportedInterfaceOrientations:)]) {
|
|
174
185
|
return [self.proxyDelegate navigationControllerSupportedInterfaceOrientations:navigationController];
|
|
175
186
|
}
|
|
176
|
-
return
|
|
187
|
+
return [GlobalStyle globalStyle].interfaceOrientation;
|
|
177
188
|
}
|
|
178
189
|
|
|
179
190
|
- (UIInterfaceOrientation)navigationControllerPreferredInterfaceOrientationForPresentation:(UINavigationController *)navigationController {
|
|
180
191
|
if (self.proxyDelegate && [self.proxyDelegate respondsToSelector:@selector(navigationControllerPreferredInterfaceOrientationForPresentation:)]) {
|
|
181
192
|
return [self.proxyDelegate navigationControllerPreferredInterfaceOrientationForPresentation:navigationController];
|
|
182
193
|
}
|
|
194
|
+
UIInterfaceOrientationMask mask = [GlobalStyle globalStyle].interfaceOrientation;
|
|
195
|
+
if (mask & UIInterfaceOrientationMaskLandscapeRight) {
|
|
196
|
+
return UIInterfaceOrientationLandscapeRight;
|
|
197
|
+
}
|
|
198
|
+
if (mask & UIInterfaceOrientationMaskLandscapeLeft) {
|
|
199
|
+
return UIInterfaceOrientationLandscapeLeft;
|
|
200
|
+
}
|
|
183
201
|
return UIInterfaceOrientationPortrait;
|
|
184
202
|
}
|
|
185
203
|
|
|
@@ -189,7 +207,8 @@
|
|
|
189
207
|
return [self.proxyDelegate navigationController:navigationController interactionControllerForAnimationController:animationController];
|
|
190
208
|
}
|
|
191
209
|
|
|
192
|
-
if ([animationController isKindOfClass:[HBDPopAnimation class]]
|
|
210
|
+
if ([animationController isKindOfClass:[HBDPopAnimation class]] ||
|
|
211
|
+
[animationController isKindOfClass:[HBDFadeAnimation class]]) {
|
|
193
212
|
return self.interactiveTransition;
|
|
194
213
|
}
|
|
195
214
|
|
|
@@ -250,6 +269,34 @@
|
|
|
250
269
|
return shouldBetter;
|
|
251
270
|
}
|
|
252
271
|
|
|
272
|
+
- (BOOL)shouldUseFadeAnimationFrom:(UIViewController *)from to:(UIViewController *)to {
|
|
273
|
+
if ([from isKindOfClass:[HBDViewController class]]) {
|
|
274
|
+
HBDViewController *hbdFromVC = (HBDViewController *)from;
|
|
275
|
+
if (hbdFromVC.forceScreenLandscape) {
|
|
276
|
+
return YES;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if ([to isKindOfClass:[HBDViewController class]]) {
|
|
281
|
+
HBDViewController *hbdToVC = (HBDViewController *)to;
|
|
282
|
+
if (hbdToVC.forceScreenLandscape) {
|
|
283
|
+
return YES;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return NO;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
- (BOOL)shouldHandleInteractiveTransitionWithNavigationController:(HBDNavigationController *)nav {
|
|
291
|
+
if (nav.viewControllers.count < 2) {
|
|
292
|
+
return NO;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
UIViewController *from = nav.topViewController;
|
|
296
|
+
UIViewController *to = nav.viewControllers[nav.viewControllers.count - 2];
|
|
297
|
+
return [self shouldUseFadeAnimationFrom:from to:to];
|
|
298
|
+
}
|
|
299
|
+
|
|
253
300
|
- (void)hbd_compensateSafeAreaForViewController:(UIViewController *)vc expectedTopInset:(CGFloat)expectedTopInset isToVC:(BOOL)isToVC {
|
|
254
301
|
if (vc.isViewLoaded) {
|
|
255
302
|
[vc.view layoutIfNeeded];
|
|
@@ -304,6 +351,11 @@
|
|
|
304
351
|
|
|
305
352
|
[self.nav updateNavigationBarStyleForViewController:viewController];
|
|
306
353
|
|
|
354
|
+
BOOL shouldAnimateTabBar = [self shouldAnimateTabBarFrom:from to:to];
|
|
355
|
+
if (shouldAnimateTabBar) {
|
|
356
|
+
[self prepareTabBarForTransitionFrom:from to:to];
|
|
357
|
+
}
|
|
358
|
+
|
|
307
359
|
[coordinator animateAlongsideTransition:^(id <UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
308
360
|
BOOL shouldFake = [self shouldShowFakeBarFrom:from to:to viewController:viewController];
|
|
309
361
|
if (shouldFake) {
|
|
@@ -326,6 +378,10 @@
|
|
|
326
378
|
}
|
|
327
379
|
}
|
|
328
380
|
}
|
|
381
|
+
|
|
382
|
+
if (shouldAnimateTabBar) {
|
|
383
|
+
[self animateTabBarForTransitionFrom:from to:to];
|
|
384
|
+
}
|
|
329
385
|
} completion:^(id <UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
330
386
|
self.nav.poppingViewController = nil;
|
|
331
387
|
[self hbd_restoreCompensatedSafeAreaForFrom:from to:to viewController:viewController];
|
|
@@ -348,12 +404,63 @@
|
|
|
348
404
|
self.nav.navigationBar.standardAppearance.backgroundColor = UIColor.clearColor;
|
|
349
405
|
}
|
|
350
406
|
|
|
407
|
+
if (shouldAnimateTabBar) {
|
|
408
|
+
[self completeTabBarTransitionFrom:from to:to cancelled:context.isCancelled];
|
|
409
|
+
}
|
|
410
|
+
|
|
351
411
|
if (to == viewController) {
|
|
352
412
|
[self.nav clearFake];
|
|
353
413
|
}
|
|
354
414
|
}];
|
|
355
415
|
}
|
|
356
416
|
|
|
417
|
+
- (BOOL)shouldAnimateTabBarFrom:(UIViewController *)from to:(UIViewController *)to {
|
|
418
|
+
UITabBarController *tabBarController = self.nav.tabBarController;
|
|
419
|
+
if (!tabBarController) {
|
|
420
|
+
return NO;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
return from.hidesBottomBarWhenPushed != to.hidesBottomBarWhenPushed;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
- (void)prepareTabBarForTransitionFrom:(UIViewController *)from to:(UIViewController *)to {
|
|
427
|
+
UITabBar *tabBar = self.nav.tabBarController.tabBar;
|
|
428
|
+
[tabBar.layer removeAllAnimations];
|
|
429
|
+
tabBar.hidden = NO;
|
|
430
|
+
|
|
431
|
+
if (from.hidesBottomBarWhenPushed && !to.hidesBottomBarWhenPushed) {
|
|
432
|
+
// iOS 26 首次交互返回时,系统会过早让 TabBar 现身;先把初始 alpha 固定住,交给 coordinator 渐变。
|
|
433
|
+
tabBar.alpha = 0.0;
|
|
434
|
+
} else if (!from.hidesBottomBarWhenPushed && to.hidesBottomBarWhenPushed) {
|
|
435
|
+
tabBar.alpha = 1.0;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
- (void)animateTabBarForTransitionFrom:(UIViewController *)from to:(UIViewController *)to {
|
|
440
|
+
UITabBar *tabBar = self.nav.tabBarController.tabBar;
|
|
441
|
+
if (from.hidesBottomBarWhenPushed && !to.hidesBottomBarWhenPushed) {
|
|
442
|
+
tabBar.alpha = 1.0;
|
|
443
|
+
} else if (!from.hidesBottomBarWhenPushed && to.hidesBottomBarWhenPushed) {
|
|
444
|
+
tabBar.alpha = 0.0;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
- (void)completeTabBarTransitionFrom:(UIViewController *)from
|
|
449
|
+
to:(UIViewController *)to
|
|
450
|
+
cancelled:(BOOL)cancelled {
|
|
451
|
+
UITabBar *tabBar = self.nav.tabBarController.tabBar;
|
|
452
|
+
[tabBar.layer removeAllAnimations];
|
|
453
|
+
|
|
454
|
+
UIViewController *visibleViewController = cancelled ? from : to;
|
|
455
|
+
if (visibleViewController.hidesBottomBarWhenPushed) {
|
|
456
|
+
tabBar.alpha = 1.0;
|
|
457
|
+
tabBar.hidden = YES;
|
|
458
|
+
} else {
|
|
459
|
+
tabBar.hidden = NO;
|
|
460
|
+
tabBar.alpha = 1.0;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
357
464
|
- (void)resetButtonLabelInNavBar:(UINavigationBar *)navBar {
|
|
358
465
|
if (@available(iOS 12.0, *)) {
|
|
359
466
|
for (UIView *view in navBar.subviews) {
|
|
@@ -22,6 +22,15 @@
|
|
|
22
22
|
NSArray *_reactViewConstraints;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
- (void)syncRootViewBackgroundColor {
|
|
26
|
+
if (!self.rootView) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
UIColor *backgroundColor = self.view.backgroundColor ?: UIColor.clearColor;
|
|
31
|
+
self.rootView.backgroundColor = backgroundColor;
|
|
32
|
+
}
|
|
33
|
+
|
|
25
34
|
- (void)dealloc {
|
|
26
35
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:RCTBridgeWillReloadNotification object:nil];
|
|
27
36
|
RCTLogInfo(@"[Navigation] 销毁页面 %@", self.moduleName);
|
|
@@ -47,16 +56,18 @@
|
|
|
47
56
|
|
|
48
57
|
BOOL passThroughTouches = [self.options[@"passThroughTouches"] boolValue];
|
|
49
58
|
rootView.passThroughTouches = passThroughTouches;
|
|
50
|
-
rootView.backgroundColor = UIColor.clearColor;
|
|
51
59
|
rootView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
52
60
|
self.view = [[UIView alloc] init];
|
|
61
|
+
self.view.backgroundColor = [GlobalStyle globalStyle].screenBackgroundColor;
|
|
53
62
|
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
63
|
+
[self syncRootViewBackgroundColor];
|
|
54
64
|
[self.view addSubview:rootView];
|
|
55
65
|
RCTLogInfo(@"[Navigation] 加载页面 %@", self.moduleName);
|
|
56
66
|
}
|
|
57
67
|
|
|
58
68
|
- (void)viewDidLoad {
|
|
59
69
|
[super viewDidLoad];
|
|
70
|
+
[self syncRootViewBackgroundColor];
|
|
60
71
|
[self updateReactViewConstraints];
|
|
61
72
|
|
|
62
73
|
NSDictionary *titleItem = self.options[@"titleItem"];
|
|
@@ -94,15 +94,17 @@
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
- (void)adjustScreenOrientation {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
97
|
+
UIWindowScene *windowScene = nil;
|
|
98
|
+
if (@available(iOS 13.0, *)) {
|
|
99
|
+
windowScene = [self getWindowScene];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!self.forceScreenLandscape && windowScene != nil && windowScene.interfaceOrientation != UIInterfaceOrientationPortrait && ![[self hbd_mode] isEqual:@"modal"]) {
|
|
103
|
+
[self setScreenOrientation:UIInterfaceOrientationPortrait usingMask:UIInterfaceOrientationMaskPortrait];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (self.forceScreenLandscape) {
|
|
107
|
+
[self setScreenOrientation:UIInterfaceOrientationLandscapeRight usingMask:UIInterfaceOrientationMaskLandscape];
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
|
|
@@ -130,11 +132,19 @@
|
|
|
130
132
|
}
|
|
131
133
|
|
|
132
134
|
- (UIWindowScene *)getWindowScene API_AVAILABLE(ios(13.0)){
|
|
135
|
+
UIWindow *window = self.view.window ?: self.navigationController.view.window;
|
|
136
|
+
if ([window.windowScene isKindOfClass:[UIWindowScene class]]) {
|
|
137
|
+
return window.windowScene;
|
|
138
|
+
}
|
|
139
|
+
|
|
133
140
|
NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
|
|
134
141
|
for (id connectedScene in array) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
142
|
+
if ([connectedScene isKindOfClass:[UIWindowScene class]]) {
|
|
143
|
+
UIWindowScene *scene = (UIWindowScene *)connectedScene;
|
|
144
|
+
if (scene.activationState == UISceneActivationStateForegroundActive) {
|
|
145
|
+
return scene;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
138
148
|
}
|
|
139
149
|
return nil;
|
|
140
150
|
}
|
|
@@ -181,7 +191,7 @@
|
|
|
181
191
|
- (void)applyTabBarOptions:(NSDictionary *)options {
|
|
182
192
|
NSDictionary *tabItem = options[@"tabItem"];
|
|
183
193
|
if (tabItem) {
|
|
184
|
-
UITabBarItem *tabBarItem = self.tabBarItem;
|
|
194
|
+
UITabBarItem *tabBarItem = self.navigationController ? self.navigationController.tabBarItem : self.tabBarItem;
|
|
185
195
|
// title
|
|
186
196
|
tabBarItem.title = tabItem[@"title"];
|
|
187
197
|
|
|
@@ -192,19 +202,20 @@
|
|
|
192
202
|
|
|
193
203
|
NSDictionary *unselectedIcon = tabItem[@"unselectedIcon"];
|
|
194
204
|
NSDictionary *icon = tabItem[@"icon"];
|
|
195
|
-
UITabBar *appearance = [UITabBar appearance];
|
|
205
|
+
UITabBar *appearance = self.tabBarController.tabBar ?: [UITabBar appearance];
|
|
196
206
|
BOOL dot = [self showDotBadge:badge];
|
|
197
207
|
|
|
198
208
|
UITabBarItemAppearance *itemAppearance = appearance.standardAppearance.stackedLayoutAppearance;
|
|
199
209
|
if (unselectedIcon) {
|
|
200
|
-
tabBarItem.selectedImage = [[HBDUtils UIImage:icon] withIconColor:itemAppearance.selected.iconColor badgeColor:dot ? tabBarItem.badgeColor : UIColor.clearColor];
|
|
201
210
|
tabBarItem.image = [[HBDUtils UIImage:unselectedIcon] withIconColor:itemAppearance.normal.iconColor badgeColor:dot ? tabBarItem.badgeColor : UIColor.clearColor];
|
|
202
|
-
} else {
|
|
203
211
|
tabBarItem.selectedImage = [[HBDUtils UIImage:icon] withIconColor:itemAppearance.selected.iconColor badgeColor:dot ? tabBarItem.badgeColor : UIColor.clearColor];
|
|
212
|
+
} else {
|
|
204
213
|
tabBarItem.image = [[HBDUtils UIImage:icon] withIconColor:itemAppearance.normal.iconColor badgeColor:dot ? tabBarItem.badgeColor : UIColor.clearColor];
|
|
214
|
+
tabBarItem.selectedImage = [[HBDUtils UIImage:icon] withIconColor:itemAppearance.selected.iconColor badgeColor:dot ? tabBarItem.badgeColor : UIColor.clearColor];
|
|
215
|
+
}
|
|
216
|
+
if (!self.navigationController) {
|
|
217
|
+
self.tabBarItem = tabBarItem;
|
|
205
218
|
}
|
|
206
|
-
|
|
207
|
-
self.tabBarItem = tabBarItem;
|
|
208
219
|
}
|
|
209
220
|
}
|
|
210
221
|
|
|
@@ -229,10 +240,6 @@
|
|
|
229
240
|
}
|
|
230
241
|
|
|
231
242
|
[self applyTabBarOptions:self.options];
|
|
232
|
-
|
|
233
|
-
if (self.navigationController) {
|
|
234
|
-
self.navigationController.tabBarItem = self.tabBarItem;
|
|
235
|
-
}
|
|
236
243
|
}
|
|
237
244
|
|
|
238
245
|
- (BOOL)showDotBadge:(NSDictionary *)badge {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#import "UINavigationController+HBD.h"
|
|
2
2
|
|
|
3
|
+
#import <React/RCTLog.h>
|
|
4
|
+
|
|
3
5
|
@implementation UINavigationController (HBD)
|
|
4
6
|
|
|
5
7
|
- (void)redirectToViewController:(UIViewController *)controller animated:(BOOL)animated {
|
|
@@ -9,6 +11,16 @@
|
|
|
9
11
|
- (void)redirectToViewController:(UIViewController *)controller target:(UIViewController *)target animated:(BOOL)animated {
|
|
10
12
|
NSMutableArray *children = [self.childViewControllers mutableCopy];
|
|
11
13
|
NSUInteger index = [children indexOfObject:target];
|
|
14
|
+
if (index == NSNotFound) {
|
|
15
|
+
RCTLogWarn(@"[Navigation] redirectTo target is no longer in the navigation stack. Fallback to topViewController.");
|
|
16
|
+
index = [children indexOfObject:self.topViewController];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (index == NSNotFound) {
|
|
20
|
+
RCTLogWarn(@"[Navigation] redirectTo failed because the navigation stack is empty.");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
12
24
|
NSUInteger count = self.childViewControllers.count;
|
|
13
25
|
[children removeObjectsInRange:NSMakeRange(index, count - index)];
|
|
14
26
|
[children addObject:controller];
|
|
@@ -49,6 +49,14 @@
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
[self hbd_dismissViewControllerAnimated:animated completion:^{
|
|
52
|
+
if (!presented || !presenting) {
|
|
53
|
+
RCTLogWarn(@"[Navigation] dismiss completed without a valid presenting/presented controller pair.");
|
|
54
|
+
if (completion) {
|
|
55
|
+
completion();
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
52
60
|
if (![presented isKindOfClass:[UIAlertController class]]) {
|
|
53
61
|
BOOL consumed = presented.presentingSceneId && [UIViewController dispatchResult:presenting presented:presented sceneId:presented.presentingSceneId];
|
|
54
62
|
if (!consumed) {
|
|
@@ -355,4 +363,3 @@
|
|
|
355
363
|
}
|
|
356
364
|
|
|
357
365
|
@end
|
|
358
|
-
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hybrid-navigation",
|
|
3
3
|
"description": "React Native Navigation that supports seamless navigation between Native and React.",
|
|
4
|
-
"version": "3.1.
|
|
4
|
+
"version": "3.1.3",
|
|
5
5
|
"main": "./dist/index",
|
|
6
6
|
"module": "./dist/index",
|
|
7
7
|
"types": "./dist/index.d.ts",
|