hybrid-navigation 2.20.0 → 3.0.0

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.
Files changed (136) hide show
  1. package/HybridNavigation.podspec +7 -5
  2. package/README.md +17 -0
  3. package/android/build.gradle +56 -19
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +1 -2
  6. package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +320 -326
  7. package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +13 -20
  8. package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +6 -11
  9. package/android/src/main/java/com/reactnative/hybridnavigation/HybridNavigationPackage.java +55 -21
  10. package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +31 -0
  11. package/android/src/main/java/com/reactnative/hybridnavigation/NativeGarden.java +223 -0
  12. package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +370 -0
  13. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +239 -224
  14. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivityDelegate.java +177 -198
  15. package/android/src/main/java/com/reactnative/hybridnavigation/ReactDrawerFragment.java +2 -9
  16. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +41 -78
  17. package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +438 -0
  18. package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +10 -19
  19. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBar.java +7 -15
  20. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +135 -173
  21. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +54 -227
  22. package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +2 -3
  23. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +12 -14
  24. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +18 -21
  25. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +17 -20
  26. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +13 -26
  27. package/dist/NativeEvent.d.ts +33 -0
  28. package/dist/NativeEvent.js +2 -0
  29. package/dist/NativeGarden.d.ts +18 -0
  30. package/dist/NativeGarden.js +2 -0
  31. package/dist/NativeNavigation.d.ts +47 -0
  32. package/dist/NativeNavigation.js +2 -0
  33. package/dist/Navigation.js +3 -3
  34. package/dist/NavigationModule.d.ts +3 -3
  35. package/dist/NavigationModule.js +18 -19
  36. package/dist/Navigator.js +1 -2
  37. package/dist/Options.d.ts +4 -7
  38. package/dist/Route.d.ts +0 -2
  39. package/dist/handler/BarButtonEventHandler.js +2 -2
  40. package/dist/handler/LayoutCommandHandler.js +3 -3
  41. package/dist/handler/ResultEventHandler.js +3 -3
  42. package/dist/handler/VisibilityEventHandler.js +11 -4
  43. package/dist/index.d.ts +0 -1
  44. package/dist/index.js +0 -1
  45. package/ios/HybridNavigation/GlobalStyle.h +0 -6
  46. package/ios/HybridNavigation/{GlobalStyle.m → GlobalStyle.mm} +54 -44
  47. package/ios/HybridNavigation/HBDUtils.h +0 -4
  48. package/ios/HybridNavigation/{HBDUtils.m → HBDUtils.mm} +0 -41
  49. package/ios/HybridNavigation/Navigator/{HBDScreenNavigator.m → HBDScreenNavigator.mm} +3 -9
  50. package/ios/HybridNavigation/Navigator/{HBDStackNavigator.m → HBDStackNavigator.mm} +0 -4
  51. package/ios/HybridNavigation/Navigator/{HBDTabNavigator.m → HBDTabNavigator.mm} +1 -55
  52. package/ios/HybridNavigation/React/HBDNativeEvent.h +13 -0
  53. package/ios/HybridNavigation/React/HBDNativeEvent.mm +31 -0
  54. package/ios/HybridNavigation/React/HBDNativeGarden.h +10 -0
  55. package/ios/HybridNavigation/React/HBDNativeGarden.mm +151 -0
  56. package/ios/HybridNavigation/React/HBDNativeNavigation.h +11 -0
  57. package/ios/HybridNavigation/React/HBDNativeNavigation.mm +263 -0
  58. package/ios/HybridNavigation/{ReactBridge → React}/HBDReactBridgeManager.h +3 -1
  59. package/ios/HybridNavigation/{ReactBridge/HBDReactBridgeManager.m → React/HBDReactBridgeManager.mm} +7 -30
  60. package/ios/HybridNavigation/View/{HBDBarButtonItem.m → HBDBarButtonItem.mm} +19 -11
  61. package/ios/HybridNavigation/View/{HBDNavigationBar.m → HBDNavigationBar.mm} +68 -5
  62. package/ios/HybridNavigation/View/HBDRootView.h +2 -2
  63. package/ios/HybridNavigation/View/{HBDRootView.m → HBDRootView.mm} +2 -2
  64. package/ios/HybridNavigation/View/HBDTitleView.h +2 -2
  65. package/ios/HybridNavigation/View/{HBDTitleView.m → HBDTitleView.mm} +3 -3
  66. package/ios/HybridNavigation/View/UIImage+WithBadge.h +13 -0
  67. package/ios/HybridNavigation/View/UIImage+WithBadge.mm +36 -0
  68. package/ios/HybridNavigation/ViewController/{HBDDrawerController.m → HBDDrawerController.mm} +2 -25
  69. package/ios/HybridNavigation/ViewController/HBDReactViewController.h +0 -4
  70. package/ios/HybridNavigation/ViewController/{HBDReactViewController.m → HBDReactViewController.mm} +40 -31
  71. package/ios/HybridNavigation/ViewController/HBDTabBarController.h +0 -2
  72. package/ios/HybridNavigation/ViewController/HBDTabBarController.mm +140 -0
  73. package/ios/HybridNavigation/ViewController/HBDViewController+Garden.h +0 -2
  74. package/ios/HybridNavigation/ViewController/{HBDViewController+Garden.m → HBDViewController+Garden.mm} +8 -26
  75. package/ios/HybridNavigation/ViewController/HBDViewController.h +2 -0
  76. package/ios/HybridNavigation/ViewController/{HBDViewController.m → HBDViewController.mm} +67 -57
  77. package/ios/HybridNavigation/ViewController/UIViewController+HBD.h +0 -2
  78. package/ios/HybridNavigation/ViewController/{UIViewController+HBD.m → UIViewController+HBD.mm} +1 -42
  79. package/package.json +11 -2
  80. package/src/DeepLink.ts +3 -3
  81. package/src/NativeEvent.ts +40 -0
  82. package/src/NativeGarden.ts +27 -0
  83. package/src/NativeNavigation.ts +72 -0
  84. package/src/Navigation.ts +13 -13
  85. package/src/NavigationComponentWrap.tsx +4 -4
  86. package/src/NavigationModule.ts +21 -46
  87. package/src/Navigator.ts +13 -13
  88. package/src/Options.ts +9 -9
  89. package/src/Route.ts +0 -2
  90. package/src/handler/BarButtonEventHandler.ts +4 -8
  91. package/src/handler/DispatchCommandHandler.ts +4 -8
  92. package/src/handler/LayoutCommandHandler.ts +4 -5
  93. package/src/handler/ResultEventHandler.ts +11 -27
  94. package/src/handler/VisibilityEventHandler.ts +23 -32
  95. package/src/hooks.ts +2 -2
  96. package/src/index.ts +4 -5
  97. package/src/router/drawer.ts +5 -5
  98. package/src/router/index.ts +15 -15
  99. package/src/router/screen.ts +2 -2
  100. package/src/router/stack.ts +4 -4
  101. package/src/router/tabs.ts +3 -3
  102. package/src/store.ts +1 -1
  103. package/android/src/main/java/com/reactnative/hybridnavigation/DefaultTabBarProvider.java +0 -143
  104. package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +0 -230
  105. package/android/src/main/java/com/reactnative/hybridnavigation/HBDEventEmitter.java +0 -89
  106. package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +0 -71
  107. package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +0 -370
  108. package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +0 -445
  109. package/dist/Event.d.ts +0 -16
  110. package/dist/Event.js +0 -62
  111. package/dist/GardenModule.d.ts +0 -24
  112. package/dist/GardenModule.js +0 -21
  113. package/ios/HybridNavigation/HBDAnimationObserver.h +0 -24
  114. package/ios/HybridNavigation/HBDAnimationObserver.m +0 -45
  115. package/ios/HybridNavigation/ReactBridge/HBDEventEmitter.h +0 -28
  116. package/ios/HybridNavigation/ReactBridge/HBDEventEmitter.m +0 -72
  117. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.h +0 -6
  118. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +0 -157
  119. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.h +0 -6
  120. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +0 -249
  121. package/ios/HybridNavigation/View/HBDReactTabBar.h +0 -9
  122. package/ios/HybridNavigation/View/HBDReactTabBar.m +0 -36
  123. package/ios/HybridNavigation/View/UITabBar+Badge.h +0 -9
  124. package/ios/HybridNavigation/View/UITabBar+Badge.m +0 -46
  125. package/ios/HybridNavigation/ViewController/HBDTabBarController.m +0 -265
  126. package/src/Event.ts +0 -117
  127. package/src/GardenModule.ts +0 -50
  128. /package/ios/HybridNavigation/Navigator/{HBDDrawerNavigator.m → HBDDrawerNavigator.mm} +0 -0
  129. /package/ios/HybridNavigation/Navigator/{HBDNavigatorRegistry.m → HBDNavigatorRegistry.mm} +0 -0
  130. /package/ios/HybridNavigation/{ReactBridge → React}/HBDNavigator.h +0 -0
  131. /package/ios/HybridNavigation/View/{HBDBackBarButtonItem.m → HBDBackBarButtonItem.mm} +0 -0
  132. /package/ios/HybridNavigation/ViewController/{HBDFadeAnimation.m → HBDFadeAnimation.mm} +0 -0
  133. /package/ios/HybridNavigation/ViewController/{HBDNavigationController.m → HBDNavigationController.mm} +0 -0
  134. /package/ios/HybridNavigation/ViewController/{HBDPopAnimation.m → HBDPopAnimation.mm} +0 -0
  135. /package/ios/HybridNavigation/ViewController/{HBDPushAnimation.m → HBDPushAnimation.mm} +0 -0
  136. /package/ios/HybridNavigation/ViewController/{UINavigationController+HBD.m → UINavigationController+HBD.mm} +0 -0
@@ -0,0 +1,263 @@
1
+ #import "HBDNativeNavigation.h"
2
+
3
+ #import "HBDReactBridgeManager.h"
4
+ #import "HBDReactViewController.h"
5
+
6
+ #import <React/RCTLog.h>
7
+ #import <ReactCommon/RCTTurboModule.h>
8
+
9
+ @interface HBDNativeNavigation ()
10
+
11
+ @property(nonatomic, strong, readonly) HBDReactBridgeManager *bridgeManager;
12
+
13
+ @end
14
+
15
+ @implementation HBDNativeNavigation
16
+
17
+ + (NSString *)moduleName {
18
+ return @"HBDNativeNavigation";
19
+ }
20
+
21
+ + (BOOL)requiresMainQueueSetup {
22
+ return YES;
23
+ }
24
+
25
+ - (dispatch_queue_t)methodQueue {
26
+ return dispatch_get_main_queue();
27
+ }
28
+
29
+ - (instancetype)init {
30
+ if (self = [super init]) {
31
+ _bridgeManager = [HBDReactBridgeManager get];
32
+ }
33
+ return self;
34
+ }
35
+
36
+ - (void)initialize {
37
+ RCTLogInfo(@"[Navigation] HBDNativeNavigation#initialize");
38
+ }
39
+
40
+ - (void)invalidate {
41
+ RCTLogInfo(@"[Navigation] HBDNativeNavigation#invalidate");
42
+ [NSObject cancelPreviousPerformRequestsWithTarget:self];
43
+ [self.bridgeManager invalidate];
44
+ }
45
+
46
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params {
47
+ return std::make_shared<facebook::react::NativeNavigationSpecJSI>(params);
48
+ }
49
+
50
+ - (nonnull facebook::react::ModuleConstants<JS::NativeNavigation::Constants::Builder>)constantsToExport {
51
+ JS::NativeNavigation::Constants::Builder::Input input = {
52
+ ResultOK,
53
+ ResultCancel,
54
+ ResultBlock
55
+ };
56
+ // 这里用 typedConstants 工厂函数来生成 ModuleConstants
57
+ return facebook::react::typedConstants<JS::NativeNavigation::Constants::Builder>(std::move(input));
58
+ }
59
+
60
+ - (nonnull facebook::react::ModuleConstants<JS::NativeNavigation::Constants::Builder>)getConstants {
61
+ return [self constantsToExport];
62
+ }
63
+
64
+ - (void)startRegisterReactComponent {
65
+ [self.bridgeManager startRegisterReactModule];
66
+ }
67
+
68
+ - (void)endRegisterReactComponent {
69
+ [self.bridgeManager endRegisterReactModule];
70
+ }
71
+
72
+ - (void)registerReactComponent:(nonnull NSString *)appKey options:(nonnull NSDictionary *)options {
73
+ [self.bridgeManager registerReactModule:appKey options:options];
74
+ }
75
+
76
+ - (void)signalFirstRenderComplete:(nonnull NSString *)sceneId {
77
+ UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
78
+ if ([vc isKindOfClass:[HBDReactViewController class]]) {
79
+ [(HBDReactViewController *)vc signalFirstRenderComplete];
80
+ }
81
+ }
82
+
83
+ - (void)currentTab:(nonnull NSString *)sceneId callback:(nonnull RCTResponseSenderBlock)callback {
84
+ UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
85
+ UITabBarController *tabs = vc.tabBarController;
86
+ if (tabs) {
87
+ callback(@[NSNull.null, @(tabs.selectedIndex)]);
88
+ } else {
89
+ callback(@[NSNull.null, @(-1)]);
90
+ }
91
+ }
92
+
93
+ - (void)currentRoute:(nonnull RCTResponseSenderBlock)callback {
94
+ [self performSelector:@selector(currentRouteWithCallback:) withObject:callback];
95
+ }
96
+
97
+ - (void)routeGraph:(nonnull RCTResponseSenderBlock)callback {
98
+ [self performSelector:@selector(routeGraphWithCallback:) withObject:callback];
99
+ }
100
+
101
+ - (void)findSceneIdByModuleName:(nonnull NSString *)moduleName callback:(nonnull RCTResponseSenderBlock)callback {
102
+ [self performSelector:@selector(findSceneIdWithParams:) withObject:@{
103
+ @"callback": callback,
104
+ @"moduleName": moduleName,
105
+ }];
106
+ }
107
+
108
+ - (void)isStackRoot:(nonnull NSString *)sceneId callback:(nonnull RCTResponseSenderBlock)callback {
109
+ UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
110
+ UINavigationController *nav = vc.navigationController;
111
+ if (!nav) {
112
+ callback(@[NSNull.null, @NO]);
113
+ return;
114
+ }
115
+
116
+ NSArray *children = nav.childViewControllers;
117
+ if (children.count == 0) {
118
+ callback(@[NSNull.null, @NO]);
119
+ return;
120
+ }
121
+
122
+ UIViewController *root = children[0];
123
+ if ([root.sceneId isEqualToString:sceneId]) {
124
+ callback(@[NSNull.null, @YES]);
125
+ return;
126
+ }
127
+
128
+ callback(@[NSNull.null, @NO]);
129
+ }
130
+
131
+ - (void)dispatch:(nonnull NSString *)sceneId action:(nonnull NSString *)action params:(nonnull NSDictionary *)params callback:(nonnull RCTResponseSenderBlock)callback {
132
+ UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
133
+ if (!vc) {
134
+ callback(@[NSNull.null, @NO]);
135
+ RCTLogInfo(@"[Navigation] Can't find target scene for action: %@, maybe the scene is gone. \nextras: %@", action, params);
136
+ return;
137
+ }
138
+
139
+ [self.bridgeManager handleNavigationWithViewController:vc action:action extras:params callback:(RCTResponseSenderBlock)callback];
140
+ }
141
+
142
+ - (void)setRoot:(nonnull NSDictionary *)layout sticky:(BOOL)sticky callback:(nonnull RCTResponseSenderBlock)callback {
143
+ self.bridgeManager.viewHierarchyReady = NO;
144
+ UIViewController *vc = [self.bridgeManager viewControllerWithLayout:layout];
145
+ if (!vc) {
146
+ @throw [[NSException alloc] initWithName:@"IllegalArgumentsException" reason:@"无法创建 ViewController" userInfo:@{ @"layout": layout }];
147
+ }
148
+
149
+ if (self.bridgeManager.didSetRoot) {
150
+ self.bridgeManager.didSetRoot(@[NSNull.null, @NO]);
151
+ }
152
+ self.bridgeManager.didSetRoot = callback;
153
+ self.bridgeManager.hasRootLayout = YES;
154
+
155
+ [self.bridgeManager setRootViewController:vc];
156
+ }
157
+
158
+ - (void)setResult:(nonnull NSString *)sceneId resultCode:(double)resultCode data:(nonnull NSDictionary *)data {
159
+ UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
160
+ [vc setResultCode:resultCode resultData:data];
161
+ }
162
+
163
+ - (void)findSceneIdWithParams:(NSDictionary *)params {
164
+ if (!self.bridgeManager.isViewHierarchyReady) {
165
+ [self performSelector:@selector(findSceneIdWithParams:) withObject:params afterDelay:0.016];
166
+ return;
167
+ }
168
+
169
+ NSString *moduleName = params[@"moduleName"];
170
+ RCTResponseSenderBlock callback = params[@"callback"];
171
+
172
+ NSString *sceneId = [self findSceneIdByModuleName:moduleName];
173
+ if (sceneId == nil) {
174
+ RCTLogInfo(@"[Navigation] Can't find sceneId by : %@", moduleName);
175
+ callback(@[NSNull.null, NSNull.null]);
176
+ return;
177
+ }
178
+
179
+ RCTLogInfo(@"[Navigation] The sceneId found by %@ : %@", moduleName, sceneId);
180
+ callback(@[[NSNull null], sceneId]);
181
+ }
182
+
183
+ - (NSString *)findSceneIdByModuleName:(NSString *)moduleName {
184
+ UIWindow *keyWindow = RCTKeyWindow();
185
+ if (keyWindow) {
186
+ NSString *sceneId = [self findSceneIdByModuleName:moduleName withViewController:keyWindow.rootViewController];
187
+ if (sceneId != nil) {
188
+ RCTLogInfo(@"[Navigation] The sceneId found by %@ : %@", moduleName, sceneId);
189
+ return sceneId;
190
+ }
191
+ }
192
+
193
+ RCTLogInfo(@"[Navigation] KeyWindow NOT found.");
194
+
195
+ return nil;
196
+ }
197
+
198
+ - (NSString *)findSceneIdByModuleName:(NSString *)moduleName withViewController:(UIViewController *)vc {
199
+ if ([vc isKindOfClass:[HBDViewController class]]) {
200
+ HBDViewController *hbd = (HBDViewController *)vc;
201
+ if ([moduleName isEqualToString:hbd.moduleName]) {
202
+ return hbd.sceneId;
203
+ }
204
+ }
205
+
206
+ if (vc.presentedViewController && vc != vc.presentedViewController && !vc.presentedViewController.isBeingDismissed) {
207
+ NSString *sceneId = [self findSceneIdByModuleName:moduleName withViewController:vc.presentedViewController];
208
+ if (sceneId) {
209
+ return sceneId;
210
+ }
211
+ }
212
+
213
+ NSArray<UIViewController *> *children = vc.childViewControllers;
214
+ if (children.count == 0) {
215
+ return nil;
216
+ }
217
+
218
+ for (UIViewController *child in children) {
219
+ NSString *sceneId = [self findSceneIdByModuleName:moduleName withViewController:child];
220
+ if (sceneId) {
221
+ return sceneId;
222
+ }
223
+ }
224
+
225
+ return nil;
226
+ }
227
+
228
+ - (void)currentRouteWithCallback:(RCTResponseSenderBlock)callback {
229
+ if (!self.bridgeManager.isViewHierarchyReady) {
230
+ [self performSelector:@selector(currentRouteWithCallback:) withObject:callback afterDelay:0.016];
231
+ return;
232
+ }
233
+
234
+ HBDViewController *current = [self.bridgeManager primaryViewController];
235
+
236
+ if (current) {
237
+ callback(@[[NSNull null], @{
238
+ @"moduleName": RCTNullIfNil(current.moduleName),
239
+ @"sceneId": current.sceneId,
240
+ @"presentingId": RCTNullIfNil(current.presentingSceneId),
241
+ @"mode": [current hbd_mode],
242
+ @"requestCode": @(current.requestCode),
243
+ }]);
244
+ } else {
245
+ [self performSelector:@selector(currentRouteWithCallback:) withObject:callback afterDelay:0.016];
246
+ }
247
+ }
248
+
249
+ - (void)routeGraphWithCallback:(RCTResponseSenderBlock)callback {
250
+ if (!self.bridgeManager.isViewHierarchyReady) {
251
+ [self performSelector:@selector(routeGraphWithCallback:) withObject:callback afterDelay:0.016];
252
+ return;
253
+ }
254
+
255
+ NSArray *root = [self.bridgeManager routeGraph];
256
+ if (root.count > 0) {
257
+ callback(@[[NSNull null], root]);
258
+ } else {
259
+ [self performSelector:@selector(routeGraphWithCallback:) withObject:callback afterDelay:0.016];
260
+ }
261
+ }
262
+
263
+ @end
@@ -1,5 +1,6 @@
1
1
  #import <React/RCTBridge.h>
2
2
  #import "HBDNavigator.h"
3
+ #import <React-RuntimeApple/ReactCommon/RCTHost.h>
3
4
 
4
5
  extern NSString *const ReactModuleRegistryDidCompletedNotification;
5
6
  extern const NSInteger ResultOK;
@@ -20,13 +21,14 @@ extern const NSInteger ResultBlock;
20
21
  + (instancetype)get;
21
22
 
22
23
  @property(nonatomic, strong, readonly) RCTBridge *bridge;
24
+ @property(nonatomic, strong, readonly) RCTHost *rctHost;
23
25
  @property(nonatomic, weak) id <HBDReactBridgeManagerDelegate> delegate;
24
26
  @property(nonatomic, assign, readonly, getter=isReactModuleRegisterCompleted) BOOL reactModuleRegisterCompleted;
25
27
  @property(nonatomic, assign, getter=isViewHierarchyReady) BOOL viewHierarchyReady;
26
28
  @property(nonatomic, assign) BOOL hasRootLayout;
27
29
  @property(nonatomic, copy) RCTResponseSenderBlock didSetRoot;
28
30
 
29
- - (void)installWithBridge:(RCTBridge *)bridge;
31
+ - (void)installWithReactHost:(RCTHost *)rctHost;
30
32
 
31
33
  - (void)registerNativeModule:(NSString *)moduleName forViewController:(Class)clazz;
32
34
 
@@ -3,7 +3,7 @@
3
3
  #import "HBDUtils.h"
4
4
  #import "HBDReactViewController.h"
5
5
  #import "HBDNavigatorRegistry.h"
6
- #import "HBDEventEmitter.h"
6
+ #import "HBDNativeEvent.h"
7
7
 
8
8
  #import <React/RCTLog.h>
9
9
 
@@ -56,7 +56,7 @@ const NSInteger ResultBlock = -2;
56
56
  - (void)invalidate {
57
57
  RCTLogInfo(@"[Navigation] HBDReactBridgeManager#invalidate");
58
58
  [NSObject cancelPreviousPerformRequestsWithTarget:self];
59
-
59
+
60
60
  NSArray<id <HBDNavigator>> *navigators = [self.navigatorRegistry allNavigators];
61
61
  for (id<HBDNavigator> navigator in navigators) {
62
62
  [navigator invalidate];
@@ -65,33 +65,10 @@ const NSInteger ResultBlock = -2;
65
65
  self.viewHierarchyReady = NO;
66
66
  self.reactModuleRegisterCompleted = NO;
67
67
  self.didSetRoot = NULL;
68
-
69
- UIWindow *mainWindow = [self mainWindow];
70
- UIViewController *presentedViewController = mainWindow.rootViewController.presentedViewController;
71
- if (presentedViewController && !presentedViewController.isBeingDismissed) {
72
- [mainWindow.rootViewController dismissViewControllerAnimated:NO completion:^{
73
- [self setLoadingViewController];
74
- }];
75
- } else {
76
- [self setLoadingViewController];
77
- }
78
- }
79
-
80
- - (void)setLoadingViewController {
81
- UIWindow *mainWindow = [self mainWindow];
82
- UIViewController *vc;
83
- @try {
84
- UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"LaunchScreen" bundle:nil];
85
- vc = [storyboard instantiateInitialViewController];
86
- } @catch (NSException * e){
87
- vc = [UIViewController new];
88
- vc.view.backgroundColor = UIColor.whiteColor;
89
- }
90
- mainWindow.rootViewController = vc;
91
68
  }
92
69
 
93
- - (void)installWithBridge:(RCTBridge *)bridge {
94
- _bridge = bridge;
70
+ - (void)installWithReactHost:(RCTHost *)rctHost {
71
+ _rctHost = rctHost;
95
72
  }
96
73
 
97
74
  - (void)registerNativeModule:(NSString *)moduleName forViewController:(Class)clazz {
@@ -234,7 +211,7 @@ const NSInteger ResultBlock = -2;
234
211
  }
235
212
 
236
213
  - (void)performSetRootViewController:(UIViewController *)rootViewController animated:(BOOL)animated {
237
- [HBDEventEmitter sendEvent:EVENT_WILL_SET_ROOT data:@{}];
214
+ [[HBDNativeEvent getInstance] emitWillSetRoot];
238
215
  UIWindow *mainWindow = [self mainWindow];
239
216
  if (animated) {
240
217
  [UIView transitionWithView:mainWindow duration:0.15f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
@@ -252,7 +229,7 @@ const NSInteger ResultBlock = -2;
252
229
  self.didSetRoot(@[NSNull.null, @YES]);
253
230
  self.didSetRoot = NULL;
254
231
  }
255
- [HBDEventEmitter sendEvent:EVENT_DID_SET_ROOT data:@{}];
232
+ [[HBDNativeEvent getInstance] emitDidSetRoot];
256
233
  }];
257
234
  } else {
258
235
  mainWindow.rootViewController = rootViewController;
@@ -266,7 +243,7 @@ const NSInteger ResultBlock = -2;
266
243
  self.didSetRoot(@[NSNull.null, @YES]);
267
244
  self.didSetRoot = NULL;
268
245
  }
269
- [HBDEventEmitter sendEvent:EVENT_DID_SET_ROOT data:@{}];
246
+ [[HBDNativeEvent getInstance] emitDidSetRoot];
270
247
  }
271
248
  }
272
249
 
@@ -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
@@ -1,7 +1,7 @@
1
- #import <React/RCTRootView.h>
1
+ #import <React/RCTSurfaceHostingProxyRootView.h>
2
2
 
3
3
  @interface HBDRootView : UIView
4
4
 
5
- - (instancetype)initWithRootView:(RCTRootView *)rootView;
5
+ - (instancetype)initWithRootView:(RCTSurfaceHostingProxyRootView *)rootView;
6
6
 
7
7
  @end
@@ -2,13 +2,13 @@
2
2
 
3
3
  @interface HBDRootView ()
4
4
 
5
- @property (nonatomic, strong, readonly) RCTRootView *rootView;
5
+ @property (nonatomic, strong, readonly) RCTSurfaceHostingProxyRootView *rootView;
6
6
 
7
7
  @end
8
8
 
9
9
  @implementation HBDRootView
10
10
 
11
- - (instancetype)initWithRootView:(RCTRootView *)rootView {
11
+ - (instancetype)initWithRootView:(RCTSurfaceHostingProxyRootView *)rootView {
12
12
  if (self = [super initWithFrame:CGRectZero]) {
13
13
  _rootView = rootView;
14
14
  }
@@ -1,7 +1,7 @@
1
- #import <React/RCTRootView.h>
1
+ #import <React/RCTSurfaceHostingProxyRootView.h>
2
2
 
3
3
  @interface HBDTitleView : UIView
4
4
 
5
- - (instancetype)initWithRootView:(RCTRootView *)rootView layoutFittingSize:(CGSize)fittingSize navigationBarBounds:(CGRect)bounds;
5
+ - (instancetype)initWithRootView:(RCTSurfaceHostingProxyRootView *)rootView layoutFittingSize:(CGSize)fittingSize navigationBarBounds:(CGRect)bounds;
6
6
 
7
7
  @end
@@ -5,14 +5,14 @@
5
5
  @interface HBDTitleView () <RCTRootViewDelegate>
6
6
 
7
7
  @property(nonatomic, assign) CGSize fittingSize;
8
- @property(nonatomic, strong) RCTRootView *rootView;
8
+ @property(nonatomic, strong) RCTSurfaceHostingProxyRootView *rootView;
9
9
  @property(nonatomic, assign) CGRect barBounds;
10
10
 
11
11
  @end
12
12
 
13
13
  @implementation HBDTitleView
14
14
 
15
- - (instancetype)initWithRootView:(RCTRootView *)rootView layoutFittingSize:(CGSize)fittingSize navigationBarBounds:(CGRect)bounds {
15
+ - (instancetype)initWithRootView:(RCTSurfaceHostingProxyRootView *)rootView layoutFittingSize:(CGSize)fittingSize navigationBarBounds:(CGRect)bounds {
16
16
  if (self = [super init]) {
17
17
  rootView.backgroundColor = [UIColor clearColor];
18
18
  _rootView = rootView;
@@ -45,7 +45,7 @@
45
45
  }
46
46
  }
47
47
 
48
- - (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView {
48
+ - (void)rootViewDidChangeIntrinsicSize:(RCTSurfaceHostingProxyRootView *)rootView {
49
49
  CGPoint center = self.center;
50
50
  self.bounds = CGRectMake(0, 0, rootView.intrinsicContentSize.width, rootView.intrinsicContentSize.height);
51
51
  self.rootView.frame = CGRectMake(0, 0, rootView.intrinsicContentSize.width, rootView.intrinsicContentSize.height);
@@ -0,0 +1,13 @@
1
+ #import <UIKit/UIKit.h>
2
+
3
+ NS_ASSUME_NONNULL_BEGIN
4
+
5
+ @interface UIImage (WithBadge)
6
+
7
+ - (UIImage *)withIconColor:(UIColor *)iconColor;
8
+
9
+ - (UIImage *)withIconColor:(UIColor *)iconColor badgeColor:(UIColor *)badgeColor;
10
+
11
+ @end
12
+
13
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,36 @@
1
+ #import "UIImage+WithBadge.h"
2
+
3
+ @implementation UIImage (WithBadge)
4
+
5
+ - (UIImage *)withIconColor:(UIColor *)iconColor badgeColor:(UIColor *)badgeColor {
6
+ CGSize imageSize = self.size;
7
+
8
+ UIGraphicsImageRenderer *render = [[UIGraphicsImageRenderer alloc] initWithSize:imageSize];
9
+
10
+ UIImage *resultImage = [render imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
11
+ // 创建 tint 后的图标图片
12
+ UIImage *iconTintedImage = [self imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
13
+
14
+ // 设置图标颜色并绘制
15
+ [iconColor set];
16
+ [iconTintedImage drawAtPoint:CGPointZero];
17
+
18
+ // 创建徽章
19
+ CGSize badgeSize = CGSizeMake(8, 8);
20
+ CGPoint badgeOrigin = CGPointMake(imageSize.width - badgeSize.width, 0);
21
+ CGRect badgeRect = CGRectMake(badgeOrigin.x, badgeOrigin.y, badgeSize.width, badgeSize.height);
22
+
23
+ UIBezierPath *badgePath = [UIBezierPath bezierPathWithOvalInRect:badgeRect];
24
+ [badgeColor setFill];
25
+ [badgePath fill];
26
+ }];
27
+
28
+ return [resultImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
29
+ }
30
+
31
+ // 提供默认参数的便捷方法
32
+ - (UIImage *)withIconColor:(UIColor *)iconColor {
33
+ return [self withIconColor:iconColor badgeColor:[UITabBarItem appearance].badgeColor];
34
+ }
35
+
36
+ @end
@@ -73,30 +73,6 @@
73
73
  }
74
74
  }
75
75
 
76
- - (void)viewDidAppear:(BOOL)animated {
77
- [super viewDidAppear:animated];
78
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameWillChange:) name:UIApplicationWillChangeStatusBarFrameNotification object:nil];
79
- }
80
-
81
- - (void)viewDidDisappear:(BOOL)animated {
82
- [super viewDidDisappear:animated];
83
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillChangeStatusBarFrameNotification object:nil];
84
- }
85
-
86
- - (void)statusBarFrameWillChange:(NSNotification *)notification {
87
- CGFloat statusBarHeight = [HBDUtils statusBarHeight];
88
- if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation) && statusBarHeight != 0) {
89
- if (self.menuOpened) {
90
- [UIView animateWithDuration:0.35 animations:^{
91
- CGFloat dy = [HBDUtils isInCall] ? -20 : 20;
92
- self.menuHolderView.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds) + dy);
93
- self.menuDimmingView.frame = self.menuHolderView.bounds;
94
- self.menuController.view.frame = CGRectMake(0, 0, [self menuWidth], self.menuHolderView.bounds.size.height);
95
- }];
96
- }
97
- }
98
- }
99
-
100
76
  - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator {
101
77
  [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
102
78
  [coordinator animateAlongsideTransition:^(id <UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
@@ -105,7 +81,8 @@
105
81
  self.menuDimmingView.frame = self.menuHolderView.bounds;
106
82
  self.menuController.view.frame = CGRectMake(0, 0, [self menuWidth], size.height);
107
83
  }
108
- } completion:^(id <UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
84
+ } completion:^(id <UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
85
+
109
86
  }];
110
87
  }
111
88