hybrid-navigation 3.1.3 → 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.
@@ -12,6 +12,7 @@ import android.widget.FrameLayout;
12
12
  import androidx.annotation.NonNull;
13
13
  import androidx.annotation.Nullable;
14
14
 
15
+ import com.facebook.react.bridge.ReactContext;
15
16
  import com.facebook.react.bridge.UIManager;
16
17
  import com.facebook.react.interfaces.fabric.ReactSurface;
17
18
  import com.facebook.react.runtime.ReactSurfaceView;
@@ -22,169 +23,178 @@ import com.facebook.react.uimanager.common.UIManagerType;
22
23
  import java.lang.reflect.InvocationTargetException;
23
24
  import java.lang.reflect.Method;
24
25
 
26
+ @SuppressLint("ClickableViewAccessibility")
25
27
  public class HBDRootView extends FrameLayout {
26
28
 
27
- @Nullable
28
- private ReactSurface surface;
29
+ @Nullable
30
+ private ReactSurface surface;
29
31
 
30
- @Nullable
31
- private ReactSurfaceView reactSurfaceView;
32
+ @Nullable
33
+ private ReactSurfaceView reactSurfaceView;
32
34
 
33
- private boolean passThroughTouches;
35
+ private boolean passThroughTouches;
34
36
 
35
- @Nullable
36
- private Bundle appProperties;
37
+ @Nullable
38
+ private Bundle appProperties;
37
39
 
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
- }
40
+ public HBDRootView(@NonNull Context context) {
41
+ super(context);
42
+ }
45
43
 
46
- public HBDRootView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
47
- super(context, attrs, defStyleAttr);
48
- }
44
+ public HBDRootView(@NonNull Context context, @Nullable AttributeSet attrs) {
45
+ super(context, attrs);
46
+ }
49
47
 
50
- public void setPassThroughTouches(boolean passThroughTouches) {
51
- this.passThroughTouches = passThroughTouches;
52
- }
48
+ public HBDRootView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
49
+ super(context, attrs, defStyleAttr);
50
+ }
53
51
 
54
- public void setSurface(@NonNull ReactSurface reactSurface) {
55
- if (surface == reactSurface) {
56
- return;
57
- }
52
+ public void setPassThroughTouches(boolean passThroughTouches) {
53
+ this.passThroughTouches = passThroughTouches;
54
+ }
58
55
 
59
- clearSurface();
60
- surface = reactSurface;
56
+ public void setSurface(@NonNull ReactSurface reactSurface) {
57
+ if (surface == reactSurface) {
58
+ return;
59
+ }
61
60
 
62
- View view = reactSurface.getView();
63
- if (view == null) {
64
- throw new IllegalStateException("[Navigation] ReactSurface.getView() 不能为空。");
65
- }
61
+ clearSurface();
62
+ surface = reactSurface;
66
63
 
67
- addView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
68
- reactSurfaceView = findReactSurfaceView(this);
64
+ View view = reactSurface.getView();
65
+ if (view == null) {
66
+ throw new IllegalStateException("[Navigation] ReactSurface.getView() 不能为空。");
67
+ }
69
68
 
70
- if (appProperties != null) {
71
- applyAppProperties(appProperties);
72
- }
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
+ }
73
84
 
74
- reactSurface.start();
75
- }
85
+ if (appProperties != null) {
86
+ applyAppProperties(appProperties);
87
+ }
76
88
 
77
- public void clearSurface() {
78
- clearSurface(true);
79
- }
89
+ reactSurface.start();
90
+ }
80
91
 
81
- public void clearSurface(boolean stopSurface) {
82
- if (surface != null && stopSurface) {
83
- surface.stop();
84
- }
85
- surface = null;
86
- reactSurfaceView = null;
87
- removeAllViews();
88
- }
92
+ public void clearSurface() {
93
+ clearSurface(true);
94
+ }
89
95
 
90
- public void setAppProperties(@Nullable Bundle appProperties) {
91
- this.appProperties = appProperties == null ? null : new Bundle(appProperties);
92
- applyAppProperties(this.appProperties);
93
- }
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
+ }
94
107
 
95
- @Override
96
- public boolean dispatchTouchEvent(MotionEvent ev) {
97
- if (shouldPassTouches(ev)) {
98
- return false;
99
- }
100
- return super.dispatchTouchEvent(ev);
101
- }
108
+ public void setAppProperties(@Nullable Bundle appProperties) {
109
+ this.appProperties = appProperties == null ? null : new Bundle(appProperties);
110
+ applyAppProperties(this.appProperties);
111
+ }
102
112
 
103
- @SuppressLint("ClickableViewAccessibility")
104
113
  @Override
105
- public boolean onTouchEvent(MotionEvent event) {
106
- ReactSurfaceView surfaceView = getReactSurfaceView();
107
- if (surfaceView != null) {
108
- surfaceView.onChildStartedNativeGesture(surfaceView, event);
114
+ public boolean dispatchTouchEvent(MotionEvent ev) {
115
+ if (shouldPassTouches(ev)) {
116
+ return false;
109
117
  }
110
- return true;
118
+ return super.dispatchTouchEvent(ev);
111
119
  }
112
120
 
113
121
  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
- }
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
+ }
190
200
  }
@@ -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.3",
4
+ "version": "3.1.4",
5
5
  "main": "./dist/index",
6
6
  "module": "./dist/index",
7
7
  "types": "./dist/index.d.ts",