hybrid-navigation 2.20.1 → 3.0.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.
- package/HybridNavigation.podspec +7 -5
- package/README.md +17 -0
- package/android/build.gradle +56 -19
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +320 -326
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +13 -20
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +6 -11
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridNavigationPackage.java +55 -21
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +31 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeGarden.java +223 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +370 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +239 -224
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivityDelegate.java +177 -198
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactDrawerFragment.java +2 -9
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +41 -78
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +438 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +10 -19
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBar.java +7 -15
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +135 -173
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +54 -227
- package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +2 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +12 -14
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +18 -21
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +17 -20
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +13 -26
- package/dist/NativeEvent.d.ts +33 -0
- package/dist/NativeEvent.js +2 -0
- package/dist/NativeGarden.d.ts +18 -0
- package/dist/NativeGarden.js +2 -0
- package/dist/NativeNavigation.d.ts +47 -0
- package/dist/NativeNavigation.js +2 -0
- package/dist/Navigation.js +3 -3
- package/dist/NavigationModule.d.ts +3 -3
- package/dist/NavigationModule.js +18 -19
- package/dist/Navigator.js +1 -2
- package/dist/Options.d.ts +4 -7
- package/dist/Route.d.ts +0 -2
- package/dist/handler/BarButtonEventHandler.js +2 -2
- package/dist/handler/LayoutCommandHandler.js +3 -3
- package/dist/handler/ResultEventHandler.js +3 -3
- package/dist/handler/VisibilityEventHandler.js +11 -4
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/ios/HybridNavigation/GlobalStyle.h +0 -6
- package/ios/HybridNavigation/{GlobalStyle.m → GlobalStyle.mm} +54 -44
- package/ios/HybridNavigation/HBDUtils.h +0 -4
- package/ios/HybridNavigation/{HBDUtils.m → HBDUtils.mm} +0 -41
- package/ios/HybridNavigation/Navigator/{HBDScreenNavigator.m → HBDScreenNavigator.mm} +3 -9
- package/ios/HybridNavigation/Navigator/{HBDStackNavigator.m → HBDStackNavigator.mm} +0 -4
- package/ios/HybridNavigation/Navigator/{HBDTabNavigator.m → HBDTabNavigator.mm} +1 -55
- package/ios/HybridNavigation/React/HBDNativeEvent.h +13 -0
- package/ios/HybridNavigation/React/HBDNativeEvent.mm +31 -0
- package/ios/HybridNavigation/React/HBDNativeGarden.h +10 -0
- package/ios/HybridNavigation/React/HBDNativeGarden.mm +151 -0
- package/ios/HybridNavigation/React/HBDNativeNavigation.h +11 -0
- package/ios/HybridNavigation/React/HBDNativeNavigation.mm +263 -0
- package/ios/HybridNavigation/{ReactBridge → React}/HBDReactBridgeManager.h +3 -1
- package/ios/HybridNavigation/{ReactBridge/HBDReactBridgeManager.m → React/HBDReactBridgeManager.mm} +7 -30
- package/ios/HybridNavigation/View/{HBDNavigationBar.m → HBDNavigationBar.mm} +8 -28
- package/ios/HybridNavigation/View/HBDRootView.h +2 -2
- package/ios/HybridNavigation/View/{HBDRootView.m → HBDRootView.mm} +2 -2
- package/ios/HybridNavigation/View/HBDTitleView.h +2 -2
- package/ios/HybridNavigation/View/{HBDTitleView.m → HBDTitleView.mm} +3 -3
- package/ios/HybridNavigation/View/UIImage+WithBadge.h +13 -0
- package/ios/HybridNavigation/View/UIImage+WithBadge.mm +36 -0
- package/ios/HybridNavigation/ViewController/{HBDDrawerController.m → HBDDrawerController.mm} +2 -25
- package/ios/HybridNavigation/ViewController/HBDReactViewController.h +0 -4
- package/ios/HybridNavigation/ViewController/{HBDReactViewController.m → HBDReactViewController.mm} +40 -31
- package/ios/HybridNavigation/ViewController/HBDTabBarController.h +0 -2
- package/ios/HybridNavigation/ViewController/HBDTabBarController.mm +140 -0
- package/ios/HybridNavigation/ViewController/HBDViewController+Garden.h +0 -2
- package/ios/HybridNavigation/ViewController/{HBDViewController+Garden.m → HBDViewController+Garden.mm} +8 -26
- package/ios/HybridNavigation/ViewController/HBDViewController.h +2 -0
- package/ios/HybridNavigation/ViewController/{HBDViewController.m → HBDViewController.mm} +67 -57
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.h +0 -2
- package/ios/HybridNavigation/ViewController/{UIViewController+HBD.m → UIViewController+HBD.mm} +10 -44
- package/package.json +11 -2
- package/src/DeepLink.ts +3 -3
- package/src/NativeEvent.ts +40 -0
- package/src/NativeGarden.ts +27 -0
- package/src/NativeNavigation.ts +72 -0
- package/src/Navigation.ts +13 -13
- package/src/NavigationComponentWrap.tsx +4 -4
- package/src/NavigationModule.ts +21 -46
- package/src/Navigator.ts +13 -13
- package/src/Options.ts +9 -9
- package/src/Route.ts +0 -2
- package/src/handler/BarButtonEventHandler.ts +4 -8
- package/src/handler/DispatchCommandHandler.ts +4 -8
- package/src/handler/LayoutCommandHandler.ts +4 -5
- package/src/handler/ResultEventHandler.ts +11 -27
- package/src/handler/VisibilityEventHandler.ts +23 -32
- package/src/hooks.ts +2 -2
- package/src/index.ts +4 -5
- package/src/router/drawer.ts +5 -5
- package/src/router/index.ts +15 -15
- package/src/router/screen.ts +2 -2
- package/src/router/stack.ts +4 -4
- package/src/router/tabs.ts +3 -3
- package/src/store.ts +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/DefaultTabBarProvider.java +0 -143
- package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +0 -230
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDEventEmitter.java +0 -89
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +0 -71
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +0 -370
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +0 -445
- package/dist/Event.d.ts +0 -16
- package/dist/Event.js +0 -62
- package/dist/GardenModule.d.ts +0 -24
- package/dist/GardenModule.js +0 -21
- package/ios/HybridNavigation/HBDAnimationObserver.h +0 -24
- package/ios/HybridNavigation/HBDAnimationObserver.m +0 -45
- package/ios/HybridNavigation/ReactBridge/HBDEventEmitter.h +0 -28
- package/ios/HybridNavigation/ReactBridge/HBDEventEmitter.m +0 -72
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.h +0 -6
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +0 -157
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.h +0 -6
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +0 -249
- package/ios/HybridNavigation/View/HBDReactTabBar.h +0 -9
- package/ios/HybridNavigation/View/HBDReactTabBar.m +0 -36
- package/ios/HybridNavigation/View/UITabBar+Badge.h +0 -9
- package/ios/HybridNavigation/View/UITabBar+Badge.m +0 -46
- package/ios/HybridNavigation/ViewController/HBDTabBarController.m +0 -265
- package/src/Event.ts +0 -117
- package/src/GardenModule.ts +0 -50
- /package/ios/HybridNavigation/Navigator/{HBDDrawerNavigator.m → HBDDrawerNavigator.mm} +0 -0
- /package/ios/HybridNavigation/Navigator/{HBDNavigatorRegistry.m → HBDNavigatorRegistry.mm} +0 -0
- /package/ios/HybridNavigation/{ReactBridge → React}/HBDNavigator.h +0 -0
- /package/ios/HybridNavigation/View/{HBDBackBarButtonItem.m → HBDBackBarButtonItem.mm} +0 -0
- /package/ios/HybridNavigation/View/{HBDBarButtonItem.m → HBDBarButtonItem.mm} +0 -0
- /package/ios/HybridNavigation/ViewController/{HBDFadeAnimation.m → HBDFadeAnimation.mm} +0 -0
- /package/ios/HybridNavigation/ViewController/{HBDNavigationController.m → HBDNavigationController.mm} +0 -0
- /package/ios/HybridNavigation/ViewController/{HBDPopAnimation.m → HBDPopAnimation.mm} +0 -0
- /package/ios/HybridNavigation/ViewController/{HBDPushAnimation.m → HBDPushAnimation.mm} +0 -0
- /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)
|
|
31
|
+
- (void)installWithReactHost:(RCTHost *)rctHost;
|
|
30
32
|
|
|
31
33
|
- (void)registerNativeModule:(NSString *)moduleName forViewController:(Class)clazz;
|
|
32
34
|
|
package/ios/HybridNavigation/{ReactBridge/HBDReactBridgeManager.m → React/HBDReactBridgeManager.mm}
RENAMED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
#import "HBDUtils.h"
|
|
4
4
|
#import "HBDReactViewController.h"
|
|
5
5
|
#import "HBDNavigatorRegistry.h"
|
|
6
|
-
#import "
|
|
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)
|
|
94
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
246
|
+
[[HBDNativeEvent getInstance] emitDidSetRoot];
|
|
270
247
|
}
|
|
271
248
|
}
|
|
272
249
|
|
|
@@ -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
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
#import <React/
|
|
1
|
+
#import <React/RCTSurfaceHostingProxyRootView.h>
|
|
2
2
|
|
|
3
3
|
@interface HBDRootView : UIView
|
|
4
4
|
|
|
5
|
-
- (instancetype)initWithRootView:(
|
|
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)
|
|
5
|
+
@property (nonatomic, strong, readonly) RCTSurfaceHostingProxyRootView *rootView;
|
|
6
6
|
|
|
7
7
|
@end
|
|
8
8
|
|
|
9
9
|
@implementation HBDRootView
|
|
10
10
|
|
|
11
|
-
- (instancetype)initWithRootView:(
|
|
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/
|
|
1
|
+
#import <React/RCTSurfaceHostingProxyRootView.h>
|
|
2
2
|
|
|
3
3
|
@interface HBDTitleView : UIView
|
|
4
4
|
|
|
5
|
-
- (instancetype)initWithRootView:(
|
|
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)
|
|
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:(
|
|
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:(
|
|
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
|
package/ios/HybridNavigation/ViewController/{HBDDrawerController.m → HBDDrawerController.mm}
RENAMED
|
@@ -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
|
-
}
|
|
84
|
+
} completion:^(id <UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
85
|
+
|
|
109
86
|
}];
|
|
110
87
|
}
|
|
111
88
|
|