hybrid-navigation 2.20.0 → 2.20.1

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.
@@ -36,20 +36,28 @@
36
36
  @implementation HBDBarButtonItem
37
37
 
38
38
  - (instancetype)initWithImage:(UIImage *)image style:(UIBarButtonItemStyle)style {
39
- HBDImageBarButton *button = [HBDImageBarButton buttonWithType:UIButtonTypeSystem];
40
- button.translatesAutoresizingMaskIntoConstraints = NO;
41
- [button setFrame:CGRectMake(0, 0, 32, 32)];
42
- [button setImage:image forState:UIControlStateNormal];
43
- [button addTarget:self action:@selector(didButtonClick) forControlEvents:UIControlEventTouchUpInside];
44
- return [super initWithCustomView:button];
39
+ if (@available(iOS 26.0, *)) {
40
+ return [super initWithImage:image style:style target:self action:@selector(didButtonClick)];
41
+ } else {
42
+ HBDImageBarButton *button = [HBDImageBarButton buttonWithType:UIButtonTypeSystem];
43
+ button.translatesAutoresizingMaskIntoConstraints = NO;
44
+ [button setFrame:CGRectMake(0, 0, 32, 32)];
45
+ [button setImage:image forState:UIControlStateNormal];
46
+ [button addTarget:self action:@selector(didButtonClick) forControlEvents:UIControlEventTouchUpInside];
47
+ return [super initWithCustomView:button];
48
+ }
45
49
  }
46
50
 
47
51
  - (instancetype)initWithTitle:(NSString *)title style:(UIBarButtonItemStyle)style {
48
- UIButton *button = [HBDTextBarButton buttonWithType:UIButtonTypeSystem];
49
- button.translatesAutoresizingMaskIntoConstraints = NO;
50
- [button setTitle:title forState:UIControlStateNormal];
51
- [button addTarget:self action:@selector(didButtonClick) forControlEvents:UIControlEventTouchUpInside];
52
- return [super initWithCustomView:button];
52
+ if (@available(iOS 26.0, *)) {
53
+ return [super initWithTitle:title style:style target:self action:@selector(didButtonClick)];
54
+ } else {
55
+ UIButton *button = [HBDTextBarButton buttonWithType:UIButtonTypeSystem];
56
+ button.translatesAutoresizingMaskIntoConstraints = NO;
57
+ [button setTitle:title forState:UIControlStateNormal];
58
+ [button addTarget:self action:@selector(didButtonClick) forControlEvents:UIControlEventTouchUpInside];
59
+ return [super initWithCustomView:button];
60
+ }
53
61
  }
54
62
 
55
63
  - (void)didButtonClick {
@@ -24,7 +24,7 @@
24
24
  if (view && [viewName isEqualToString:@"HBDNavigationBar"]) {
25
25
  for (UIView *subview in self.subviews) {
26
26
  NSString *viewName = [[[subview classForCoder] description] stringByReplacingOccurrencesOfString:@"_" withString:@""];
27
- NSArray *array = @[@"UINavigationItemButtonView"];
27
+ NSArray *array = @[@"UINavigationItemButtonView", @"UIKit.NavigationBarContentView", @"UIButtonBarButton"];
28
28
  if ([array containsObject:viewName]) {
29
29
  CGPoint convertedPoint = [self convertPoint:point toView:subview];
30
30
  CGRect bounds = subview.bounds;
@@ -38,7 +38,7 @@
38
38
  }
39
39
  }
40
40
 
41
- NSArray *array = @[@"UINavigationBarContentView", @"UIButtonBarStackView", @"HBDNavigationBar"];
41
+ NSArray *array = @[@"UINavigationBarContentView", @"UIButtonBarStackView", @"UIKit.NavigationBarContentView", @"UIButtonBarButton", NSStringFromClass([self class])];
42
42
  if ([array containsObject:viewName]) {
43
43
  if (self.fakeBackgroundView.alpha < 0.01) {
44
44
  return nil;
@@ -119,11 +119,11 @@
119
119
  }
120
120
 
121
121
  - (UILabel *)backButtonLabel {
122
- UIView *navigationBarContentView = [self valueForKeyPath:@"visualProvider.contentView"];
122
+ UIView *navigationBarContentView = [self getViewFromContext:self withKeyPath:@"visualProvider.contentView"];
123
123
  __block UILabel *backButtonLabel = nil;
124
124
  [navigationBarContentView.subviews enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(__kindof UIView *_Nonnull subview, NSUInteger idx, BOOL *_Nonnull stop) {
125
125
  if ([subview isKindOfClass:NSClassFromString(@"_UIButtonBarButton")]) {
126
- UIButton *titleButton = [subview valueForKeyPath:@"visualProvider.titleButton"];
126
+ UIButton *titleButton = (UIButton *)[self getViewFromContext:subview withKeyPath:@"visualProvider.titleButton"];
127
127
  backButtonLabel = titleButton.titleLabel;
128
128
  *stop = YES;
129
129
  }
@@ -131,6 +131,70 @@
131
131
  return backButtonLabel;
132
132
  }
133
133
 
134
+ // 兼容 iOS26
135
+ - (UIView *)getViewFromContext:(id)context withKeyPath:(NSString *)keyPath {
136
+ if (!context || !keyPath) {
137
+ return nil;
138
+ }
139
+
140
+ if (@available(iOS 26.0, *)) {
141
+ // 如果 context 是 UIView,先尝试通过遍历 subviews 查找包含 "ContentView" 的视图
142
+ if ([context isKindOfClass:[UIView class]]) {
143
+ UIView *view = (UIView *)context;
144
+ __block UIView *contentView = nil;
145
+
146
+ // 使用标准的 enumerateObjectsUsingBlock 替代 qmui_firstMatchWithBlock
147
+ [view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull item, NSUInteger idx, BOOL * _Nonnull stop) {
148
+ if ([NSStringFromClass(item.class) containsString:@"ContentView"]) {
149
+ contentView = item;
150
+ *stop = YES;
151
+ }
152
+ }];
153
+
154
+ if (contentView) return contentView;
155
+ }
156
+
157
+ // Xcode 26 编译在 iOS 26 上时,无法用以前的 KVC 方式获取 contentView,所以改为通过 Ivar 获取
158
+ // 解析 keyPath,获取 provider key(例如从 "visualProvider.contentView" 中获取 "visualProvider")
159
+ NSArray *components = [keyPath componentsSeparatedByString:@"."];
160
+ if (components.count > 0) {
161
+ NSString *providerKey = components.firstObject;
162
+ NSObject *provider = [context valueForKey:providerKey];
163
+
164
+ if (provider && components.count > 1) {
165
+ NSString *targetKey = components.lastObject;
166
+ __block UIView *result = nil;
167
+
168
+ // 使用 Runtime API 直接获取 Ivar 列表,替代 qmui_enumrateIvarsUsingBlock
169
+ unsigned int ivarCount = 0;
170
+ Ivar *ivars = class_copyIvarList([provider class], &ivarCount);
171
+
172
+ if (ivars) {
173
+ for (unsigned int i = 0; i < ivarCount && !result; i++) {
174
+ Ivar ivar = ivars[i];
175
+ const char *ivarName = ivar_getName(ivar);
176
+
177
+ if (ivarName) {
178
+ NSString *ivarNameString = [NSString stringWithUTF8String:ivarName];
179
+ // 检查 ivar 名称是否包含 targetKey
180
+ if ([ivarNameString containsString:targetKey]) {
181
+ // 直接使用 object_getIvar 获取 Ivar 值,替代 getObjectIvarValue
182
+ result = object_getIvar(provider, ivar);
183
+ }
184
+ }
185
+ }
186
+ free(ivars);
187
+ }
188
+
189
+ return result;
190
+ }
191
+ }
192
+ }
193
+
194
+ // 在 iOS 26.0 以下,直接通过 KVC 获取
195
+ return [context valueForKeyPath:keyPath];
196
+ }
197
+
134
198
  @end
135
199
 
136
200
  @implementation UILabel (NavigationBarTransition)
@@ -160,5 +224,4 @@
160
224
  [self hbd_setAttributedText:attributedText];
161
225
  }
162
226
 
163
-
164
227
  @end
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": "2.20.0",
4
+ "version": "2.20.1",
5
5
  "main": "./dist/index.js",
6
6
  "typings": "./dist/index.d.ts",
7
7
  "react-native": "src/index",