hybrid-navigation 3.1.2 → 3.1.4

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.
@@ -0,0 +1,200 @@
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.ReactContext;
16
+ import com.facebook.react.bridge.UIManager;
17
+ import com.facebook.react.interfaces.fabric.ReactSurface;
18
+ import com.facebook.react.runtime.ReactSurfaceView;
19
+ import com.facebook.react.uimanager.TouchTargetHelper;
20
+ import com.facebook.react.uimanager.UIManagerHelper;
21
+ import com.facebook.react.uimanager.common.UIManagerType;
22
+
23
+ import java.lang.reflect.InvocationTargetException;
24
+ import java.lang.reflect.Method;
25
+
26
+ @SuppressLint("ClickableViewAccessibility")
27
+ public class HBDRootView extends FrameLayout {
28
+
29
+ @Nullable
30
+ private ReactSurface surface;
31
+
32
+ @Nullable
33
+ private ReactSurfaceView reactSurfaceView;
34
+
35
+ private boolean passThroughTouches;
36
+
37
+ @Nullable
38
+ private Bundle appProperties;
39
+
40
+ public HBDRootView(@NonNull Context context) {
41
+ super(context);
42
+ }
43
+
44
+ public HBDRootView(@NonNull Context context, @Nullable AttributeSet attrs) {
45
+ super(context, attrs);
46
+ }
47
+
48
+ public HBDRootView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
49
+ super(context, attrs, defStyleAttr);
50
+ }
51
+
52
+ public void setPassThroughTouches(boolean passThroughTouches) {
53
+ this.passThroughTouches = passThroughTouches;
54
+ }
55
+
56
+ public void setSurface(@NonNull ReactSurface reactSurface) {
57
+ if (surface == reactSurface) {
58
+ return;
59
+ }
60
+
61
+ clearSurface();
62
+ surface = reactSurface;
63
+
64
+ View view = reactSurface.getView();
65
+ if (view == null) {
66
+ throw new IllegalStateException("[Navigation] ReactSurface.getView() 不能为空。");
67
+ }
68
+
69
+ addView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
70
+ reactSurfaceView = findReactSurfaceView(this);
71
+
72
+ // Prevent double-dispatch of ACTION_DOWN to JSTouchDispatcher.
73
+ // ReactRootView dispatches touch events to JS in both onInterceptTouchEvent and onTouchEvent.
74
+ // When no Fabric child view handles the DOWN (e.g. during initial render), onTouchEvent is
75
+ // also called, causing JSTouchDispatcher to receive a duplicate DOWN before UP/CANCEL.
76
+ // Returning true from the listener for ACTION_DOWN prevents onTouchEvent from firing,
77
+ // while still allowing MOVE/UP/CANCEL to reach onTouchEvent normally.
78
+ if (reactSurfaceView != null) {
79
+ reactSurfaceView.setOnTouchListener((v, event) -> {
80
+ int action = event.getAction() & MotionEvent.ACTION_MASK;
81
+ return action == MotionEvent.ACTION_DOWN;
82
+ });
83
+ }
84
+
85
+ if (appProperties != null) {
86
+ applyAppProperties(appProperties);
87
+ }
88
+
89
+ reactSurface.start();
90
+ }
91
+
92
+ public void clearSurface() {
93
+ clearSurface(true);
94
+ }
95
+
96
+ public void clearSurface(boolean stopSurface) {
97
+ if (surface != null && stopSurface) {
98
+ surface.stop();
99
+ }
100
+ if (reactSurfaceView != null) {
101
+ reactSurfaceView.setOnTouchListener(null);
102
+ }
103
+ surface = null;
104
+ reactSurfaceView = null;
105
+ removeAllViews();
106
+ }
107
+
108
+ public void setAppProperties(@Nullable Bundle appProperties) {
109
+ this.appProperties = appProperties == null ? null : new Bundle(appProperties);
110
+ applyAppProperties(this.appProperties);
111
+ }
112
+
113
+ @Override
114
+ public boolean dispatchTouchEvent(MotionEvent ev) {
115
+ if (shouldPassTouches(ev)) {
116
+ return false;
117
+ }
118
+ return super.dispatchTouchEvent(ev);
119
+ }
120
+
121
+ private boolean shouldPassTouches(@NonNull MotionEvent ev) {
122
+ if (!passThroughTouches) {
123
+ return false;
124
+ }
125
+
126
+ int action = ev.getAction() & MotionEvent.ACTION_MASK;
127
+ if (action != MotionEvent.ACTION_DOWN) {
128
+ return false;
129
+ }
130
+
131
+ ReactSurfaceView surfaceView = getReactSurfaceView();
132
+ if (surfaceView == null) {
133
+ return false;
134
+ }
135
+
136
+ ViewGroup rootViewGroup = surfaceView.getRootViewGroup();
137
+
138
+ int tag = TouchTargetHelper.findTargetTagForTouch(ev.getX(), ev.getY(), rootViewGroup);
139
+ ReactContext reactContext = surfaceView.getCurrentReactContext();
140
+ if (reactContext == null) {
141
+ return false;
142
+ }
143
+
144
+ UIManager uiManager = UIManagerHelper.getUIManager(reactContext, UIManagerType.FABRIC);
145
+ if (uiManager == null) {
146
+ return false;
147
+ }
148
+
149
+ View view = uiManager.resolveView(tag);
150
+ if (view == null) {
151
+ return false;
152
+ }
153
+
154
+ if (view == surfaceView || view == surfaceView.getChildAt(0)) {
155
+ return view.getWidth() == surfaceView.getWidth() && view.getHeight() == surfaceView.getHeight();
156
+ }
157
+
158
+ return false;
159
+ }
160
+
161
+ @Nullable
162
+ private ReactSurfaceView getReactSurfaceView() {
163
+ if (reactSurfaceView == null) {
164
+ reactSurfaceView = findReactSurfaceView(this);
165
+ }
166
+ return reactSurfaceView;
167
+ }
168
+
169
+ @Nullable
170
+ private ReactSurfaceView findReactSurfaceView(@NonNull ViewGroup parent) {
171
+ for (int i = 0; i < parent.getChildCount(); i++) {
172
+ View child = parent.getChildAt(i);
173
+ if (child instanceof ReactSurfaceView surfaceView) {
174
+ return surfaceView;
175
+ }
176
+
177
+ if (child instanceof ViewGroup childGroup) {
178
+ ReactSurfaceView result = findReactSurfaceView(childGroup);
179
+ if (result != null) {
180
+ return result;
181
+ }
182
+ }
183
+ }
184
+
185
+ return null;
186
+ }
187
+
188
+ private void applyAppProperties(@Nullable Bundle appProperties) {
189
+ if (appProperties == null || surface == null) {
190
+ return;
191
+ }
192
+
193
+ try {
194
+ Method updateInitProps = surface.getClass().getMethod("updateInitProps", Bundle.class);
195
+ updateInitProps.invoke(surface, new Bundle(appProperties));
196
+ } catch (NoSuchMethodException | IllegalAccessException |
197
+ InvocationTargetException ignored) {
198
+ }
199
+ }
200
+ }
@@ -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 ViewGroup reactViewHolder;
31
+ private HBDRootView reactRootView;
32
32
 
33
- private ReactSurface reactRootView;
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
- reactViewHolder = view.findViewById(R.id.react_content);
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 (reactRootView == null) {
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 == null || !reactContext.hasActiveReactInstance()) {
164
- return;
165
+ if (reactContext != null && reactContext.hasActiveReactInstance()) {
166
+ canStopSurface = true;
165
167
  }
166
168
 
167
- if (reactRootView != null) {
169
+ if (reactSurface != null) {
168
170
  FLog.w(TAG, "销毁页面-:" + getModuleName());
169
- reactRootView.stop();
170
- reactRootView = null;
171
+ reactSurface = null;
172
+ }
173
+
174
+ if (reactRootView != null) {
175
+ reactRootView.clearSurface(canStopSurface);
171
176
  }
172
177
 
173
178
  if (reactTitleView != null) {
174
- reactTitleView.stop();
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
- reactRootView = reactSurface;
219
- ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT);
220
- reactViewHolder.addView(reactSurface.getView(), layoutParams);
221
- reactSurface.start();
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
- <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
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" />
@@ -260,34 +260,30 @@ static GlobalStyle *globalStyle;
260
260
  }
261
261
 
262
262
  - (void)inflateTabBar:(UITabBar *)tabBar {
263
- if (@available(iOS 15.0, *)) {
264
- UITabBarItemAppearance *tabBarItem = [UITabBarItemAppearance new];
265
- tabBarItem.normal.titleTextAttributes = @{
266
- NSForegroundColorAttributeName: self.tabBarItemNormalColor,
267
- };
268
- tabBarItem.normal.iconColor = self.tabBarItemNormalColor;
269
- tabBarItem.selected.titleTextAttributes = @{
270
- NSForegroundColorAttributeName: self.tabBarItemSelectedColor,
271
- };
272
- tabBarItem.selected.iconColor = self.tabBarItemSelectedColor;
273
-
274
- UITabBarAppearance *tabBarAppearance = [UITabBarAppearance new];
275
- [tabBarAppearance configureWithDefaultBackground];
276
-
277
- tabBarAppearance.shadowImage = self.tabBarShadowImage;
278
- tabBarAppearance.stackedLayoutAppearance = tabBarItem;
279
-
280
- tabBar.scrollEdgeAppearance = tabBarAppearance;
281
- tabBar.standardAppearance = tabBarAppearance;
282
- }
263
+ UITabBarItemAppearance *tabBarItem = [UITabBarItemAppearance new];
264
+ tabBarItem.normal.titleTextAttributes = @{
265
+ NSForegroundColorAttributeName: self.tabBarItemNormalColor,
266
+ };
267
+ tabBarItem.normal.iconColor = self.tabBarItemNormalColor;
268
+ tabBarItem.selected.titleTextAttributes = @{
269
+ NSForegroundColorAttributeName: self.tabBarItemSelectedColor,
270
+ };
271
+ tabBarItem.selected.iconColor = self.tabBarItemSelectedColor;
272
+
273
+ UITabBarAppearance *tabBarAppearance = [UITabBarAppearance new];
274
+ [tabBarAppearance configureWithDefaultBackground];
275
+
276
+ tabBarAppearance.shadowImage = self.tabBarShadowImage;
277
+ tabBarAppearance.stackedLayoutAppearance = tabBarItem;
278
+
279
+ tabBar.scrollEdgeAppearance = tabBarAppearance;
280
+ tabBar.standardAppearance = tabBarAppearance;
283
281
 
284
282
  if (self.tabBarBackgroundColor) {
285
283
  if (@available(iOS 26.0, *)) {
286
284
  //
287
- } else if (@available(iOS 15.0, *)) {
288
- tabBar.standardAppearance.backgroundImage = [HBDUtils imageWithColor:self.tabBarBackgroundColor];
289
285
  } else {
290
- [tabBar setBackgroundImage:[HBDUtils imageWithColor:self.tabBarBackgroundColor]];
286
+ tabBar.standardAppearance.backgroundImage = [HBDUtils imageWithColor:self.tabBarBackgroundColor];
291
287
  }
292
288
  }
293
289
 
@@ -331,10 +331,8 @@
331
331
  UIViewController *from = [coordinator viewControllerForKey:UITransitionContextFromViewControllerKey];
332
332
  UIViewController *to = [coordinator viewControllerForKey:UITransitionContextToViewControllerKey];
333
333
 
334
- if (@available(iOS 12.0, *)) {
335
- // Fix a system bug https://github.com/listenzz/HBDNavigationBar/issues/35
336
- [self resetButtonLabelInNavBar:self.nav.navigationBar];
337
- }
334
+ // Fix a system bug https://github.com/listenzz/HBDNavigationBar/issues/35
335
+ [self resetButtonLabelInNavBar:self.nav.navigationBar];
338
336
 
339
337
  if (self.nav.poppingViewController) {
340
338
  // Inspired by QMUI
@@ -371,11 +369,9 @@
371
369
  }
372
370
  } else {
373
371
  [self.nav updateNavigationBarForViewController:viewController];
374
- if (@available(iOS 13.0, *)) {
375
- if (to == viewController) {
376
- self.nav.navigationBar.scrollEdgeAppearance.backgroundColor = viewController.hbd_barTintColor;
377
- self.nav.navigationBar.standardAppearance.backgroundColor = viewController.hbd_barTintColor;
378
- }
372
+ if (to == viewController) {
373
+ self.nav.navigationBar.scrollEdgeAppearance.backgroundColor = viewController.hbd_barTintColor;
374
+ self.nav.navigationBar.standardAppearance.backgroundColor = viewController.hbd_barTintColor;
379
375
  }
380
376
  }
381
377
 
@@ -399,10 +395,8 @@
399
395
  }
400
396
  }
401
397
 
402
- if (@available(iOS 13.0, *)) {
403
- self.nav.navigationBar.scrollEdgeAppearance.backgroundColor = UIColor.clearColor;
404
- self.nav.navigationBar.standardAppearance.backgroundColor = UIColor.clearColor;
405
- }
398
+ self.nav.navigationBar.scrollEdgeAppearance.backgroundColor = UIColor.clearColor;
399
+ self.nav.navigationBar.standardAppearance.backgroundColor = UIColor.clearColor;
406
400
 
407
401
  if (shouldAnimateTabBar) {
408
402
  [self completeTabBarTransitionFrom:from to:to cancelled:context.isCancelled];
@@ -462,13 +456,11 @@
462
456
  }
463
457
 
464
458
  - (void)resetButtonLabelInNavBar:(UINavigationBar *)navBar {
465
- if (@available(iOS 12.0, *)) {
466
- for (UIView *view in navBar.subviews) {
467
- NSString *viewName = [[[view classForCoder] description] stringByReplacingOccurrencesOfString:@"_" withString:@""];
468
- if ([viewName isEqualToString:@"UINavigationBarContentView"]) {
469
- [self resetButtonLabelInView:view];
470
- break;
471
- }
459
+ for (UIView *view in navBar.subviews) {
460
+ NSString *viewName = [[[view classForCoder] description] stringByReplacingOccurrencesOfString:@"_" withString:@""];
461
+ if ([viewName isEqualToString:@"UINavigationBarContentView"]) {
462
+ [self resetButtonLabelInView:view];
463
+ break;
472
464
  }
473
465
  }
474
466
  }
@@ -562,15 +554,13 @@
562
554
  [self.navigationBar setTranslucent:YES];
563
555
  [self.navigationBar setShadowImage:[UINavigationBar appearance].shadowImage];
564
556
 
565
- if (@available(iOS 13.0, *)) {
566
- UINavigationBarAppearance *scrollEdgeAppearance = [[UINavigationBarAppearance alloc] init];
567
- [scrollEdgeAppearance configureWithTransparentBackground];
568
- scrollEdgeAppearance.shadowColor = UIColor.clearColor;
569
- scrollEdgeAppearance.backgroundColor = UIColor.clearColor;
570
- [scrollEdgeAppearance setBackIndicatorImage:[UINavigationBar appearance].backIndicatorImage transitionMaskImage:[UINavigationBar appearance].backIndicatorTransitionMaskImage];
571
- self.navigationBar.scrollEdgeAppearance = scrollEdgeAppearance;
572
- self.navigationBar.standardAppearance = [scrollEdgeAppearance copy];
573
- }
557
+ UINavigationBarAppearance *scrollEdgeAppearance = [[UINavigationBarAppearance alloc] init];
558
+ [scrollEdgeAppearance configureWithTransparentBackground];
559
+ scrollEdgeAppearance.shadowColor = UIColor.clearColor;
560
+ scrollEdgeAppearance.backgroundColor = UIColor.clearColor;
561
+ [scrollEdgeAppearance setBackIndicatorImage:[UINavigationBar appearance].backIndicatorImage transitionMaskImage:[UINavigationBar appearance].backIndicatorTransitionMaskImage];
562
+ self.navigationBar.scrollEdgeAppearance = scrollEdgeAppearance;
563
+ self.navigationBar.standardAppearance = [scrollEdgeAppearance copy];
574
564
 
575
565
  self.navigationDelegate = [[HBDNavigationControllerDelegate alloc] initWithNavigationController:self];
576
566
  self.navigationDelegate.proxyDelegate = self.delegate;
@@ -593,7 +583,7 @@
593
583
  }
594
584
  }
595
585
 
596
- /// 修正非 iPhone X 机型在 iOS 13+ 上,随 hbd_statusBarHidden 切换时系统 safe area 不准确的问题。
586
+ /// 修正非 iPhone X 机型在 iOS 15+ 上,随 hbd_statusBarHidden 切换时系统 safe area 不准确的问题。
597
587
  /// 刘海屏由系统处理即可;非刘海屏状态栏高度 20pt,系统有时报 0 或 40,需用 additionalSafeAreaInsets 补偿。
598
588
  - (void)viewSafeAreaInsetsDidChange {
599
589
  [super viewSafeAreaInsetsDidChange];
@@ -601,21 +591,19 @@
601
591
  return;
602
592
  }
603
593
 
604
- if (@available(iOS 13.0, *)) {
605
- UIEdgeInsets safeAreaInsets = self.view.safeAreaInsets;
606
- UIEdgeInsets additionalInsets = self.additionalSafeAreaInsets;
594
+ UIEdgeInsets safeAreaInsets = self.view.safeAreaInsets;
595
+ UIEdgeInsets additionalInsets = self.additionalSafeAreaInsets;
607
596
 
608
- BOOL statusBarHidden = RCTKeyWindow().windowScene.statusBarManager.statusBarHidden;
597
+ BOOL statusBarHidden = RCTKeyWindow().windowScene.statusBarManager.statusBarHidden;
609
598
 
610
- // 状态栏隐藏时系统可能把 top 算成 0,补 20pt 避免内容贴顶
611
- if (statusBarHidden && safeAreaInsets.top == 0) {
612
- self.additionalSafeAreaInsets = UIEdgeInsetsMake(20, additionalInsets.left, additionalInsets.bottom, additionalInsets.right);
613
- }
599
+ // 状态栏隐藏时系统可能把 top 算成 0,补 20pt 避免内容贴顶
600
+ if (statusBarHidden && safeAreaInsets.top == 0) {
601
+ self.additionalSafeAreaInsets = UIEdgeInsetsMake(20, additionalInsets.left, additionalInsets.bottom, additionalInsets.right);
602
+ }
614
603
 
615
- // 状态栏显示时系统有时把 top 算成 40(多算 20pt),减 20pt 使有效 top 为状态栏高度
616
- if (!statusBarHidden && safeAreaInsets.top == 40) {
617
- self.additionalSafeAreaInsets = UIEdgeInsetsMake(-20, additionalInsets.left, additionalInsets.bottom, additionalInsets.right);
618
- }
604
+ // 状态栏显示时系统有时把 top 算成 40(多算 20pt),减 20pt 使有效 top 为状态栏高度
605
+ if (!statusBarHidden && safeAreaInsets.top == 40) {
606
+ self.additionalSafeAreaInsets = UIEdgeInsetsMake(-20, additionalInsets.left, additionalInsets.bottom, additionalInsets.right);
619
607
  }
620
608
  }
621
609
 
@@ -633,10 +621,7 @@
633
621
  self.poppingViewController = self.topViewController;
634
622
  }
635
623
 
636
- UIViewController *vc = [super popViewControllerAnimated:animated];
637
- // vc != self.topViewController
638
- [self fixClickBackIssue];
639
- return vc;
624
+ return [super popViewControllerAnimated:animated];
640
625
  }
641
626
 
642
627
  - (NSArray<UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated {
@@ -644,9 +629,7 @@
644
629
  self.poppingViewController = self.topViewController;
645
630
  }
646
631
 
647
- NSArray *array = [super popToViewController:viewController animated:animated];
648
- [self fixClickBackIssue];
649
- return array;
632
+ return [super popToViewController:viewController animated:animated];
650
633
  }
651
634
 
652
635
  - (NSArray<UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated {
@@ -654,22 +637,7 @@
654
637
  self.poppingViewController = self.topViewController;
655
638
  }
656
639
 
657
- NSArray *array = [super popToRootViewControllerAnimated:animated];
658
- [self fixClickBackIssue];
659
- return array;
660
- }
661
-
662
- - (void)fixClickBackIssue {
663
- if (@available(iOS 13.0, *)) {
664
- return;
665
- }
666
-
667
- // fix:ios 11,12,当前后两个页面的 barStyle 不一样时,点击返回按钮返回,前一个页面的标题颜色响应迟缓或不响应
668
- id <UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator;
669
- if (!(coordinator && coordinator.interactive)) {
670
- self.navigationBar.barStyle = self.topViewController.hbd_barStyle;
671
- self.navigationBar.titleTextAttributes = self.topViewController.hbd_titleTextAttributes;
672
- }
640
+ return [super popToRootViewControllerAnimated:animated];
673
641
  }
674
642
 
675
643
  - (void)updateNavigationBarForViewController:(UIViewController *)vc {
@@ -691,10 +659,8 @@
691
659
  - (void)updateNavigationBarTintColorForViewController:(UIViewController *)vc {
692
660
  self.navigationBar.tintColor = vc.hbd_tintColor;
693
661
  self.navigationBar.titleTextAttributes = vc.hbd_titleTextAttributes;
694
- if (@available(iOS 13.0, *)) {
695
- self.navigationBar.scrollEdgeAppearance.titleTextAttributes = vc.hbd_titleTextAttributes;
696
- self.navigationBar.standardAppearance.titleTextAttributes = vc.hbd_titleTextAttributes;
697
- }
662
+ self.navigationBar.scrollEdgeAppearance.titleTextAttributes = vc.hbd_titleTextAttributes;
663
+ self.navigationBar.standardAppearance.titleTextAttributes = vc.hbd_titleTextAttributes;
698
664
  }
699
665
 
700
666
  - (void)updateNavigationBarAlphaForViewController:(UIViewController *)vc {
@@ -109,13 +109,21 @@
109
109
  }
110
110
 
111
111
  - (CGFloat)hbd_statusBarHeight {
112
- if (@available(iOS 13.0, *)) {
113
- UIWindowScene *scene = self.view.window.windowScene;
114
- if (scene) {
115
- return scene.statusBarManager.statusBarFrame.size.height;
112
+ UIWindow *window = self.view.window ?: self.navigationController.view.window;
113
+ UIWindowScene *scene = window.windowScene;
114
+ if (!scene) {
115
+ NSArray *connectedScenes = [[UIApplication sharedApplication].connectedScenes allObjects];
116
+ for (id connectedScene in connectedScenes) {
117
+ if ([connectedScene isKindOfClass:[UIWindowScene class]]) {
118
+ UIWindowScene *windowScene = (UIWindowScene *)connectedScene;
119
+ if (windowScene.activationState == UISceneActivationStateForegroundActive) {
120
+ scene = windowScene;
121
+ break;
122
+ }
123
+ }
116
124
  }
117
125
  }
118
- return [UIApplication sharedApplication].statusBarFrame.size.height;
126
+ return scene ? scene.statusBarManager.statusBarFrame.size.height : 0;
119
127
  }
120
128
 
121
129
  /// 局部隐藏 topBar 或局部透明 topBar(非全局隐藏)时,需将 SafeArea 顶部修正为状态栏高度
@@ -56,12 +56,9 @@
56
56
  if (tabBarBackgroundColor) {
57
57
  if (@available(iOS 26.0, *)) {
58
58
  // [tabBar setBackgroundColor: [HBDUtils colorWithHexString:tabBarBackgroundColor]];
59
- } else
60
- if (@available(iOS 15.0, *)) {
59
+ } else {
61
60
  [tabBar standardAppearance].backgroundImage = [HBDUtils imageWithColor:[HBDUtils colorWithHexString:tabBarBackgroundColor]];
62
61
  [tabBar scrollEdgeAppearance].backgroundImage = [HBDUtils imageWithColor:[HBDUtils colorWithHexString:tabBarBackgroundColor]];
63
- } else {
64
- [tabBar setBackgroundImage:[HBDUtils imageWithColor:[HBDUtils colorWithHexString:tabBarBackgroundColor]]];
65
62
  }
66
63
  }
67
64
 
@@ -8,6 +8,24 @@
8
8
 
9
9
  @implementation HBDViewController (Garden)
10
10
 
11
+ - (void)applyImageInsetsForButtonItem:(UIBarButtonItem *)buttonItem
12
+ button:(HBDImageBarButton *)button
13
+ alignmentRectInsets:(UIEdgeInsets)alignmentRectInsets {
14
+ UIEdgeInsets imageInsets = buttonItem.imageInsets;
15
+ if (!UIEdgeInsetsEqualToEdgeInsets(imageInsets, UIEdgeInsetsZero)) {
16
+ UIButtonConfiguration *configuration = button.configuration ? [button.configuration copy] : [UIButtonConfiguration plainButtonConfiguration];
17
+ if (!configuration.image) {
18
+ UIImage *currentImage = [button imageForState:UIControlStateNormal];
19
+ if (currentImage) {
20
+ configuration.image = currentImage;
21
+ }
22
+ }
23
+ configuration.contentInsets = NSDirectionalEdgeInsetsMake(imageInsets.top, imageInsets.left, imageInsets.bottom, imageInsets.right);
24
+ button.configuration = configuration;
25
+ }
26
+ button.alignmentRectInsetsOverride = alignmentRectInsets;
27
+ }
28
+
11
29
  - (void)setLeftBarButtonItem:(NSDictionary *)item {
12
30
  if (self.hbd_barHidden) {
13
31
  return;
@@ -23,8 +41,7 @@
23
41
  UIView *customView = buttonItem.customView;
24
42
  if ([customView isKindOfClass:[HBDImageBarButton class]]) {
25
43
  HBDImageBarButton *button = (HBDImageBarButton *)customView;
26
- button.imageEdgeInsets = buttonItem.imageInsets;
27
- button.alignmentRectInsetsOverride = UIEdgeInsetsMake(0, 4, 0, -4);
44
+ [self applyImageInsetsForButtonItem:buttonItem button:button alignmentRectInsets:UIEdgeInsetsMake(0, 4, 0, -4)];
28
45
  }
29
46
  [array addObject:buttonItem];
30
47
 
@@ -49,8 +66,7 @@
49
66
  UIView *customView = buttonItem.customView;
50
67
  if ([customView isKindOfClass:[HBDImageBarButton class]]) {
51
68
  HBDImageBarButton *button = (HBDImageBarButton *)customView;
52
- button.imageEdgeInsets = buttonItem.imageInsets;
53
- button.alignmentRectInsetsOverride = UIEdgeInsetsMake(0, -4, 0, 4);
69
+ [self applyImageInsetsForButtonItem:buttonItem button:button alignmentRectInsets:UIEdgeInsetsMake(0, -4, 0, 4)];
54
70
  }
55
71
  [array addObject:buttonItem];
56
72
 
@@ -78,8 +94,7 @@
78
94
  UIView *customView = buttonItem.customView;
79
95
  if ([customView isKindOfClass:[HBDImageBarButton class]]) {
80
96
  HBDImageBarButton *button = (HBDImageBarButton *)customView;
81
- button.imageEdgeInsets = buttonItem.imageInsets;
82
- button.alignmentRectInsetsOverride = UIEdgeInsetsMake(0, 4, 0, -4);
97
+ [self applyImageInsetsForButtonItem:buttonItem button:button alignmentRectInsets:UIEdgeInsetsMake(0, 4, 0, -4)];
83
98
  }
84
99
  }
85
100
 
@@ -105,8 +120,7 @@
105
120
  UIView *customView = buttonItem.customView;
106
121
  if ([customView isKindOfClass:[HBDImageBarButton class]]) {
107
122
  HBDImageBarButton *button = (HBDImageBarButton *)customView;
108
- button.imageEdgeInsets = buttonItem.imageInsets;
109
- button.alignmentRectInsetsOverride = UIEdgeInsetsMake(0, -4, 0, 4);
123
+ [self applyImageInsetsForButtonItem:buttonItem button:button alignmentRectInsets:UIEdgeInsetsMake(0, -4, 0, 4)];
110
124
  }
111
125
  }
112
126
 
@@ -63,11 +63,7 @@
63
63
  }
64
64
 
65
65
  - (UIStatusBarStyle)preferredStatusBarStyle {
66
- if (@available(iOS 13.0, *)) {
67
- return self.hbd_barStyle == UIBarStyleDefault ? UIStatusBarStyleDarkContent : UIStatusBarStyleLightContent;
68
- } else {
69
- return self.hbd_barStyle == UIBarStyleDefault ? UIStatusBarStyleDefault : UIStatusBarStyleLightContent;
70
- }
66
+ return self.hbd_barStyle == UIBarStyleDefault ? UIStatusBarStyleDarkContent : UIStatusBarStyleLightContent;
71
67
  }
72
68
 
73
69
  - (BOOL)prefersStatusBarHidden {
@@ -94,10 +90,7 @@
94
90
  }
95
91
 
96
92
  - (void)adjustScreenOrientation {
97
- UIWindowScene *windowScene = nil;
98
- if (@available(iOS 13.0, *)) {
99
- windowScene = [self getWindowScene];
100
- }
93
+ UIWindowScene *windowScene = [self getWindowScene];
101
94
 
102
95
  if (!self.forceScreenLandscape && windowScene != nil && windowScene.interfaceOrientation != UIInterfaceOrientationPortrait && ![[self hbd_mode] isEqual:@"modal"]) {
103
96
  [self setScreenOrientation:UIInterfaceOrientationPortrait usingMask:UIInterfaceOrientationMaskPortrait];
@@ -131,7 +124,7 @@
131
124
  [UIViewController attemptRotationToDeviceOrientation];
132
125
  }
133
126
 
134
- - (UIWindowScene *)getWindowScene API_AVAILABLE(ios(13.0)){
127
+ - (UIWindowScene *)getWindowScene {
135
128
  UIWindow *window = self.view.window ?: self.navigationController.view.window;
136
129
  if ([window.windowScene isKindOfClass:[UIWindowScene class]]) {
137
130
  return window.windowScene;
@@ -313,9 +306,7 @@
313
306
  if ([GlobalStyle globalStyle].isBackTitleHidden) {
314
307
  UIBarButtonItem *buttonItem = [[HBDBackBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:NULL];
315
308
  self.navigationItem.backBarButtonItem = buttonItem;
316
- if (@available(iOS 14.0, *)) {
317
- self.navigationItem.backButtonDisplayMode = UINavigationItemBackButtonDisplayModeMinimal;
318
- }
309
+ self.navigationItem.backButtonDisplayMode = UINavigationItemBackButtonDisplayModeMinimal;
319
310
  }
320
311
 
321
312
  NSNumber *swipeBackEnabled = options[@"swipeBackEnabled"];
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.2",
4
+ "version": "3.1.4",
5
5
  "main": "./dist/index",
6
6
  "module": "./dist/index",
7
7
  "types": "./dist/index.d.ts",