hybrid-navigation 3.0.0 → 3.0.2

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.
@@ -1,6 +1,7 @@
1
1
  #import "HBDNavigationBar.h"
2
2
 
3
3
  #import "HBDUtils.h"
4
+ #import <React/RCTLog.h>
4
5
 
5
6
  #define hairlineWidth (1.f/[UIScreen mainScreen].scale)
6
7
 
@@ -14,39 +15,18 @@
14
15
  @implementation HBDNavigationBar
15
16
 
16
17
  - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
17
- if (!self.isUserInteractionEnabled || self.isHidden || self.alpha <= 0.01) {
18
+ if (!self.isUserInteractionEnabled || self.isHidden || self.alpha < 0.01) {
18
19
  return nil;
19
20
  }
20
21
 
21
22
  UIView *view = [super hitTest:point withEvent:event];
22
23
  NSString *viewName = [[[view classForCoder] description] stringByReplacingOccurrencesOfString:@"_" withString:@""];
23
-
24
- if (view && [viewName isEqualToString:@"HBDNavigationBar"]) {
25
- for (UIView *subview in self.subviews) {
26
- NSString *viewName = [[[subview classForCoder] description] stringByReplacingOccurrencesOfString:@"_" withString:@""];
27
- NSArray *array = @[@"UINavigationItemButtonView", @"UIKit.NavigationBarContentView", @"UIButtonBarButton"];
28
- if ([array containsObject:viewName]) {
29
- CGPoint convertedPoint = [self convertPoint:point toView:subview];
30
- CGRect bounds = subview.bounds;
31
- if (bounds.size.width < 80) {
32
- bounds = CGRectInset(bounds, bounds.size.width - 80, 0);
33
- }
34
- if (CGRectContainsPoint(bounds, convertedPoint)) {
35
- return view;
36
- }
37
- }
38
- }
39
- }
40
-
41
- NSArray *array = @[@"UINavigationBarContentView", @"UIButtonBarStackView", @"UIKit.NavigationBarContentView", @"UIButtonBarButton", NSStringFromClass([self class])];
42
- if ([array containsObject:viewName]) {
43
- if (self.fakeBackgroundView.alpha < 0.01) {
44
- return nil;
45
- }
46
- }
47
-
48
- if (CGRectEqualToRect(view.bounds, CGRectZero)) {
49
- return nil;
24
+
25
+ // RCTLogInfo(@"viewName:%@", viewName);
26
+
27
+ NSArray *array = @[@"UINavigationBarContentView", @"UIButtonBarStackView", @"UIKit.NavigationBarContentView", NSStringFromClass([self class])];
28
+ if ([array containsObject:viewName] && self.fakeBackgroundView.alpha < 0.01) {
29
+ return nil;
50
30
  }
51
31
 
52
32
  return view;
@@ -2,7 +2,6 @@
2
2
 
3
3
  #import "HBDReactBridgeManager.h"
4
4
  #import "HBDTitleView.h"
5
- #import "HBDRootView.h"
6
5
  #import "HBDUtils.h"
7
6
  #import "HBDNativeEvent.h"
8
7
 
@@ -47,8 +46,10 @@
47
46
  BOOL passThroughTouches = [self.options[@"passThroughTouches"] boolValue];
48
47
  rootView.passThroughTouches = passThroughTouches;
49
48
  rootView.backgroundColor = UIColor.clearColor;
50
- rootView.translatesAutoresizingMaskIntoConstraints = NO;
51
- self.view = [[HBDRootView alloc] initWithRootView:rootView];
49
+ rootView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
50
+
51
+ self.view = [[UIView alloc] initWithFrame:UIScreen.mainScreen.bounds];
52
+ [rootView setFrame:self.view.frame];
52
53
  [self.view addSubview:rootView];
53
54
  [self updateReactViewConstraints];
54
55
  RCTLogInfo(@"[Navigation] 加载页面 %@", self.moduleName);
@@ -70,7 +71,7 @@
70
71
  } else {
71
72
  size = UILayoutFittingCompressedSize;
72
73
  }
73
-
74
+
74
75
  RCTHost *host = [HBDReactBridgeManager get].rctHost;
75
76
  RCTFabricSurface *surface = [host createSurfaceWithModuleName:moduleName initialProperties:[self propsWithSceneId]];
76
77
  RCTSurfaceHostingProxyRootView *titleRootView = [[RCTSurfaceHostingProxyRootView alloc] initWithSurface:(id)surface];
@@ -87,20 +88,18 @@
87
88
 
88
89
  - (void)updateReactViewConstraints {
89
90
  if (self.isViewLoaded && self.rootView) {
90
- [NSLayoutConstraint deactivateConstraints:_reactViewConstraints];
91
- _reactViewConstraints = @[
92
- [self.rootView.topAnchor
93
- constraintEqualToAnchor:self.shouldFitWindowInsetTop ? self.view.topAnchor : self.view.safeAreaLayoutGuide.topAnchor],
94
- [self.rootView.bottomAnchor
95
- constraintEqualToAnchor:self.view.bottomAnchor],
96
- [self.rootView.leftAnchor constraintEqualToAnchor:self.view.leftAnchor],
97
- [self.rootView.rightAnchor constraintEqualToAnchor:self.view.rightAnchor]
98
- ];
99
- [NSLayoutConstraint activateConstraints:_reactViewConstraints];
91
+ CGFloat bottomInset = self.shouldFitWindowInsetsBottom ? 0: self.view.safeAreaInsets.bottom;
92
+ CGFloat topInset = self.shouldFitWindowInsetsTop ? 0 : self.view.safeAreaInsets.top;
93
+ [self.rootView setFrame:CGRectMake(
94
+ 0,
95
+ topInset,
96
+ self.view.frame.size.width,
97
+ self.view.frame.size.height - topInset - bottomInset
98
+ )];
100
99
  }
101
100
  }
102
101
 
103
- - (BOOL)shouldFitWindowInsetTop {
102
+ - (BOOL)shouldFitWindowInsetsTop {
104
103
  if (![self.parentViewController isKindOfClass:UINavigationController.class]) {
105
104
  return YES;
106
105
  }
@@ -108,11 +107,11 @@
108
107
  return isTranslucent || self.extendedLayoutIncludesOpaqueBars;
109
108
  }
110
109
 
111
- - (BOOL)shouldFitSafeAreaLayoutBottom {
110
+ - (BOOL)shouldFitWindowInsetsBottom {
112
111
  if (self.navigationController && self.tabBarController) {
113
- return self == [self.navigationController.viewControllers firstObject];
112
+ return self != [self.navigationController.viewControllers firstObject];
114
113
  }
115
- return NO;
114
+ return YES;
116
115
  }
117
116
 
118
117
  - (NSDictionary *)propsWithSceneId {
@@ -192,12 +192,19 @@
192
192
 
193
193
  - (void)setHbd_barHidden:(BOOL)hidden {
194
194
  if (hidden) {
195
- self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[UIView new]];
196
195
  self.navigationItem.titleView = [UIView new];
197
196
  } else {
198
- self.navigationItem.leftBarButtonItem = nil;
199
197
  self.navigationItem.titleView = nil;
200
198
  }
199
+ if (@available(iOS 16.0, *)) {
200
+ [self.navigationItem setHidesBackButton:hidden];
201
+ } else {
202
+ if (hidden) {
203
+ self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[UIView new]];
204
+ } else {
205
+ self.navigationItem.leftBarButtonItem = nil;
206
+ }
207
+ }
201
208
  objc_setAssociatedObject(self, @selector(hbd_barHidden), @(hidden), OBJC_ASSOCIATION_COPY_NONATOMIC);
202
209
  }
203
210
 
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.0.0",
4
+ "version": "3.0.2",
5
5
  "main": "./dist/index.js",
6
6
  "typings": "./dist/index.d.ts",
7
7
  "react-native": "src/index",