hybrid-navigation 2.20.1 → 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/HBDRootView.h +2 -2
  61. package/ios/HybridNavigation/View/{HBDRootView.m → HBDRootView.mm} +2 -2
  62. package/ios/HybridNavigation/View/HBDTitleView.h +2 -2
  63. package/ios/HybridNavigation/View/{HBDTitleView.m → HBDTitleView.mm} +3 -3
  64. package/ios/HybridNavigation/View/UIImage+WithBadge.h +13 -0
  65. package/ios/HybridNavigation/View/UIImage+WithBadge.mm +36 -0
  66. package/ios/HybridNavigation/ViewController/{HBDDrawerController.m → HBDDrawerController.mm} +2 -25
  67. package/ios/HybridNavigation/ViewController/HBDReactViewController.h +0 -4
  68. package/ios/HybridNavigation/ViewController/{HBDReactViewController.m → HBDReactViewController.mm} +40 -31
  69. package/ios/HybridNavigation/ViewController/HBDTabBarController.h +0 -2
  70. package/ios/HybridNavigation/ViewController/HBDTabBarController.mm +140 -0
  71. package/ios/HybridNavigation/ViewController/HBDViewController+Garden.h +0 -2
  72. package/ios/HybridNavigation/ViewController/{HBDViewController+Garden.m → HBDViewController+Garden.mm} +8 -26
  73. package/ios/HybridNavigation/ViewController/HBDViewController.h +2 -0
  74. package/ios/HybridNavigation/ViewController/{HBDViewController.m → HBDViewController.mm} +67 -57
  75. package/ios/HybridNavigation/ViewController/UIViewController+HBD.h +0 -2
  76. package/ios/HybridNavigation/ViewController/{UIViewController+HBD.m → UIViewController+HBD.mm} +1 -42
  77. package/package.json +11 -2
  78. package/src/DeepLink.ts +3 -3
  79. package/src/NativeEvent.ts +40 -0
  80. package/src/NativeGarden.ts +27 -0
  81. package/src/NativeNavigation.ts +72 -0
  82. package/src/Navigation.ts +13 -13
  83. package/src/NavigationComponentWrap.tsx +4 -4
  84. package/src/NavigationModule.ts +21 -46
  85. package/src/Navigator.ts +13 -13
  86. package/src/Options.ts +9 -9
  87. package/src/Route.ts +0 -2
  88. package/src/handler/BarButtonEventHandler.ts +4 -8
  89. package/src/handler/DispatchCommandHandler.ts +4 -8
  90. package/src/handler/LayoutCommandHandler.ts +4 -5
  91. package/src/handler/ResultEventHandler.ts +11 -27
  92. package/src/handler/VisibilityEventHandler.ts +23 -32
  93. package/src/hooks.ts +2 -2
  94. package/src/index.ts +4 -5
  95. package/src/router/drawer.ts +5 -5
  96. package/src/router/index.ts +15 -15
  97. package/src/router/screen.ts +2 -2
  98. package/src/router/stack.ts +4 -4
  99. package/src/router/tabs.ts +3 -3
  100. package/src/store.ts +1 -1
  101. package/android/src/main/java/com/reactnative/hybridnavigation/DefaultTabBarProvider.java +0 -143
  102. package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +0 -230
  103. package/android/src/main/java/com/reactnative/hybridnavigation/HBDEventEmitter.java +0 -89
  104. package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +0 -71
  105. package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +0 -370
  106. package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +0 -445
  107. package/dist/Event.d.ts +0 -16
  108. package/dist/Event.js +0 -62
  109. package/dist/GardenModule.d.ts +0 -24
  110. package/dist/GardenModule.js +0 -21
  111. package/ios/HybridNavigation/HBDAnimationObserver.h +0 -24
  112. package/ios/HybridNavigation/HBDAnimationObserver.m +0 -45
  113. package/ios/HybridNavigation/ReactBridge/HBDEventEmitter.h +0 -28
  114. package/ios/HybridNavigation/ReactBridge/HBDEventEmitter.m +0 -72
  115. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.h +0 -6
  116. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +0 -157
  117. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.h +0 -6
  118. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +0 -249
  119. package/ios/HybridNavigation/View/HBDReactTabBar.h +0 -9
  120. package/ios/HybridNavigation/View/HBDReactTabBar.m +0 -36
  121. package/ios/HybridNavigation/View/UITabBar+Badge.h +0 -9
  122. package/ios/HybridNavigation/View/UITabBar+Badge.m +0 -46
  123. package/ios/HybridNavigation/ViewController/HBDTabBarController.m +0 -265
  124. package/src/Event.ts +0 -117
  125. package/src/GardenModule.ts +0 -50
  126. /package/ios/HybridNavigation/Navigator/{HBDDrawerNavigator.m → HBDDrawerNavigator.mm} +0 -0
  127. /package/ios/HybridNavigation/Navigator/{HBDNavigatorRegistry.m → HBDNavigatorRegistry.mm} +0 -0
  128. /package/ios/HybridNavigation/{ReactBridge → React}/HBDNavigator.h +0 -0
  129. /package/ios/HybridNavigation/View/{HBDBackBarButtonItem.m → HBDBackBarButtonItem.mm} +0 -0
  130. /package/ios/HybridNavigation/View/{HBDBarButtonItem.m → HBDBarButtonItem.mm} +0 -0
  131. /package/ios/HybridNavigation/View/{HBDNavigationBar.m → HBDNavigationBar.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
 
@@ -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
 
@@ -1,11 +1,7 @@
1
1
  #import "HBDViewController.h"
2
2
 
3
- @class RCTRootView;
4
-
5
3
  @interface HBDReactViewController : HBDViewController
6
4
 
7
- @property(nonatomic, strong, readonly) RCTRootView *rootView;
8
-
9
5
  - (void)signalFirstRenderComplete;
10
6
 
11
7
  @end
@@ -3,16 +3,17 @@
3
3
  #import "HBDReactBridgeManager.h"
4
4
  #import "HBDTitleView.h"
5
5
  #import "HBDRootView.h"
6
- #import "HBDEventEmitter.h"
7
6
  #import "HBDUtils.h"
7
+ #import "HBDNativeEvent.h"
8
8
 
9
9
  #import <React/RCTConvert.h>
10
+ #import <React/RCTSurfaceHostingProxyRootView.h>
10
11
 
11
12
  @interface HBDReactViewController ()
12
13
 
13
14
  @property(nonatomic, assign) BOOL firstRenderCompleted;
14
15
  @property(nonatomic, assign) BOOL viewAppeared;
15
- @property(nonatomic, strong, readwrite) RCTRootView *rootView;
16
+ @property(nonatomic, strong, readwrite) RCTSurfaceHostingProxyRootView *rootView;
16
17
 
17
18
  @end
18
19
 
@@ -38,7 +39,9 @@
38
39
  }
39
40
 
40
41
  - (void)loadView {
41
- RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:[HBDReactBridgeManager get].bridge moduleName:self.moduleName initialProperties:[self propsWithSceneId]];
42
+ RCTHost *host = [HBDReactBridgeManager get].rctHost;
43
+ RCTFabricSurface *surface = [host createSurfaceWithModuleName:self.moduleName initialProperties:[self propsWithSceneId]];
44
+ RCTSurfaceHostingProxyRootView *rootView = [[RCTSurfaceHostingProxyRootView alloc] initWithSurface:(id)surface];
42
45
  self.rootView = rootView;
43
46
 
44
47
  BOOL passThroughTouches = [self.options[@"passThroughTouches"] boolValue];
@@ -67,7 +70,10 @@
67
70
  } else {
68
71
  size = UILayoutFittingCompressedSize;
69
72
  }
70
- RCTRootView *titleRootView = [[RCTRootView alloc] initWithBridge:[HBDReactBridgeManager get].bridge moduleName:moduleName initialProperties:[self propsWithSceneId]];
73
+
74
+ RCTHost *host = [HBDReactBridgeManager get].rctHost;
75
+ RCTFabricSurface *surface = [host createSurfaceWithModuleName:moduleName initialProperties:[self propsWithSceneId]];
76
+ RCTSurfaceHostingProxyRootView *titleRootView = [[RCTSurfaceHostingProxyRootView alloc] initWithSurface:(id)surface];
71
77
  HBDTitleView *titleView = [[HBDTitleView alloc] initWithRootView:titleRootView layoutFittingSize:size navigationBarBounds:self.navigationController.navigationBar.bounds];
72
78
  self.navigationItem.titleView = titleView;
73
79
  }
@@ -102,6 +108,13 @@
102
108
  return isTranslucent || self.extendedLayoutIncludesOpaqueBars;
103
109
  }
104
110
 
111
+ - (BOOL)shouldFitSafeAreaLayoutBottom {
112
+ if (self.navigationController && self.tabBarController) {
113
+ return self == [self.navigationController.viewControllers firstObject];
114
+ }
115
+ return NO;
116
+ }
117
+
105
118
  - (NSDictionary *)propsWithSceneId {
106
119
  NSMutableDictionary *props;
107
120
  if (self.props) {
@@ -131,10 +144,9 @@
131
144
  if (!self.viewAppeared) {
132
145
  self.viewAppeared = YES;
133
146
  if (self.firstRenderCompleted) {
134
- [HBDEventEmitter sendEvent:EVENT_NAVIGATION data:@{
135
- KEY_SCENE_ID: self.sceneId,
136
- KEY_ON: ON_COMPONENT_APPEAR
137
- }];
147
+ [[HBDNativeEvent getInstance] emitOnComponentAppear:@{
148
+ @"sceneId": self.sceneId,
149
+ }];
138
150
  }
139
151
  }
140
152
  }
@@ -145,10 +157,9 @@
145
157
  if (!self.viewAppeared) {
146
158
  self.viewAppeared = YES;
147
159
  if (self.firstRenderCompleted) {
148
- [HBDEventEmitter sendEvent:EVENT_NAVIGATION data:@{
149
- KEY_SCENE_ID: self.sceneId,
150
- KEY_ON: ON_COMPONENT_APPEAR
151
- }];
160
+ [[HBDNativeEvent getInstance] emitOnComponentAppear:@{
161
+ @"sceneId": self.sceneId,
162
+ }];
152
163
  }
153
164
  }
154
165
  }
@@ -160,10 +171,9 @@
160
171
  if (self.viewAppeared) {
161
172
  self.viewAppeared = NO;
162
173
  if (self.firstRenderCompleted) {
163
- [HBDEventEmitter sendEvent:EVENT_NAVIGATION data:@{
164
- KEY_SCENE_ID: self.sceneId,
165
- KEY_ON: ON_COMPONENT_DISAPPEAR
166
- }];
174
+ [[HBDNativeEvent getInstance] emitOnComponentDisappear:@{
175
+ @"sceneId": self.sceneId,
176
+ }];
167
177
  }
168
178
  }
169
179
  }
@@ -174,10 +184,9 @@
174
184
  if (self.viewAppeared) {
175
185
  self.viewAppeared = NO;
176
186
  if (self.firstRenderCompleted) {
177
- [HBDEventEmitter sendEvent:EVENT_NAVIGATION data:@{
178
- KEY_SCENE_ID: self.sceneId,
179
- KEY_ON: ON_COMPONENT_DISAPPEAR
180
- }];
187
+ [[HBDNativeEvent getInstance] emitOnComponentDisappear:@{
188
+ @"sceneId": self.sceneId,
189
+ }];
181
190
  }
182
191
  }
183
192
  }
@@ -188,22 +197,22 @@
188
197
  }
189
198
  self.firstRenderCompleted = YES;
190
199
  if (self.viewAppeared) {
191
- [HBDEventEmitter sendEvent:EVENT_NAVIGATION data:@{
192
- KEY_SCENE_ID: self.sceneId,
193
- KEY_ON: ON_COMPONENT_APPEAR
194
- }];
200
+ if (self.firstRenderCompleted) {
201
+ [[HBDNativeEvent getInstance] emitOnComponentAppear:@{
202
+ @"sceneId": self.sceneId,
203
+ }];
204
+ }
195
205
  }
196
206
  }
197
207
 
198
208
  - (void)didReceiveResultCode:(NSInteger)resultCode resultData:(NSDictionary *)data requestCode:(NSInteger)requestCode {
199
209
  [super didReceiveResultCode:resultCode resultData:data requestCode:requestCode];
200
- [HBDEventEmitter sendEvent:EVENT_NAVIGATION data:@{
201
- KEY_ON: ON_COMPONENT_RESULT,
202
- KEY_REQUEST_CODE: @(requestCode),
203
- KEY_RESULT_CODE: @(resultCode),
204
- KEY_RESULT_DATA: RCTNullIfNil(data),
205
- KEY_SCENE_ID: self.sceneId,
206
- }];
210
+ [[HBDNativeEvent getInstance] emitOnResult:@{
211
+ @"requestCode": @(requestCode),
212
+ @"resultCode": @(resultCode),
213
+ @"resultData": RCTNullIfNil(data),
214
+ @"sceneId": self.sceneId,
215
+ }];
207
216
  }
208
217
 
209
218