hybrid-navigation 2.12.2 → 2.13.0-beta.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.
- package/README.md +63 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +2 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDEventEmitter.java +1 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +29 -30
- package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +2 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +4 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +6 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +24 -33
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +22 -22
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +8 -8
- package/ios/HybridNavigation/GlobalStyle.h +0 -8
- package/ios/HybridNavigation/GlobalStyle.m +7 -15
- package/ios/HybridNavigation/HBDUtils.h +5 -13
- package/ios/HybridNavigation/HBDUtils.m +2 -12
- package/ios/HybridNavigation/Navigator/HBDDrawerNavigator.h +0 -9
- package/ios/HybridNavigation/Navigator/HBDDrawerNavigator.m +91 -67
- package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.h +2 -7
- package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.m +28 -26
- package/ios/HybridNavigation/Navigator/HBDScreenNavigator.h +0 -9
- package/ios/HybridNavigation/Navigator/HBDScreenNavigator.m +127 -99
- package/ios/HybridNavigation/Navigator/HBDStackNavigator.h +0 -9
- package/ios/HybridNavigation/Navigator/HBDStackNavigator.m +199 -142
- package/ios/HybridNavigation/Navigator/HBDTabNavigator.h +0 -9
- package/ios/HybridNavigation/Navigator/HBDTabNavigator.m +144 -124
- package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDEventEmitter.h +1 -11
- package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDEventEmitter.m +4 -10
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.h +5 -0
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +128 -0
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.h +6 -0
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +237 -0
- package/ios/HybridNavigation/ReactBridge/HBDNavigator.h +20 -0
- package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDReactBridgeManager.h +12 -20
- package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDReactBridgeManager.m +91 -91
- package/ios/HybridNavigation/View/HBDBarButtonItem.h +0 -8
- package/ios/HybridNavigation/View/HBDBarButtonItem.m +1 -11
- package/ios/HybridNavigation/View/HBDNavigationBar.h +0 -8
- package/ios/HybridNavigation/View/HBDNavigationBar.m +13 -20
- package/ios/HybridNavigation/View/HBDReactTabBar.h +0 -8
- package/ios/HybridNavigation/View/HBDReactTabBar.m +1 -8
- package/ios/HybridNavigation/View/HBDRootView.h +0 -9
- package/ios/HybridNavigation/View/HBDRootView.m +0 -8
- package/ios/HybridNavigation/View/HBDTitleView.h +0 -9
- package/ios/HybridNavigation/View/HBDTitleView.m +1 -26
- package/ios/HybridNavigation/View/UITabBar+Badge.h +0 -8
- package/ios/HybridNavigation/View/UITabBar+Badge.m +0 -7
- package/ios/HybridNavigation/ViewController/HBDDrawerController.h +0 -8
- package/ios/HybridNavigation/ViewController/HBDDrawerController.m +2 -9
- package/ios/HybridNavigation/ViewController/HBDFadeAnimation.h +9 -0
- package/ios/HybridNavigation/ViewController/HBDFadeAnimation.m +22 -0
- package/ios/HybridNavigation/ViewController/HBDNavigationController.h +0 -8
- package/ios/HybridNavigation/ViewController/HBDNavigationController.m +17 -120
- package/ios/HybridNavigation/ViewController/HBDPopAnimation.h +0 -7
- package/ios/HybridNavigation/ViewController/HBDPopAnimation.m +1 -8
- package/ios/HybridNavigation/ViewController/HBDPushAnimation.h +0 -7
- package/ios/HybridNavigation/ViewController/HBDPushAnimation.m +1 -8
- package/ios/HybridNavigation/ViewController/HBDReactViewController.h +0 -8
- package/ios/HybridNavigation/ViewController/HBDReactViewController.m +59 -26
- package/ios/HybridNavigation/ViewController/HBDTabBarController.h +0 -8
- package/ios/HybridNavigation/ViewController/HBDTabBarController.m +12 -9
- package/ios/HybridNavigation/ViewController/HBDViewController+Garden.m +23 -33
- package/ios/HybridNavigation/ViewController/HBDViewController.h +1 -8
- package/ios/HybridNavigation/ViewController/HBDViewController.m +6 -23
- package/ios/HybridNavigation/ViewController/UINavigationController+HBD.h +0 -8
- package/ios/HybridNavigation/ViewController/UINavigationController+HBD.m +0 -8
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.h +2 -16
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.m +32 -46
- package/lib/Navigator.d.ts +25 -25
- package/lib/Navigator.js +116 -73
- package/package.json +4 -5
- package/src/Navigator.ts +96 -58
- package/ios/HybridNavigation/Bridge/HBDGardenModule.h +0 -14
- package/ios/HybridNavigation/Bridge/HBDGardenModule.m +0 -155
- package/ios/HybridNavigation/Bridge/HBDNavigationModule.h +0 -15
- package/ios/HybridNavigation/Bridge/HBDNavigationModule.m +0 -272
- package/ios/HybridNavigation/Navigator/HBDNavigator.h +0 -26
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
//
|
|
2
|
-
// HBDTabNavigator.h
|
|
3
|
-
// HybridNavigation
|
|
4
|
-
//
|
|
5
|
-
// Created by Listen on 2018/6/28.
|
|
6
|
-
// Copyright © 2018年 Listen. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
#import <Foundation/Foundation.h>
|
|
10
1
|
#import "HBDNavigator.h"
|
|
11
2
|
|
|
12
3
|
@interface HBDTabNavigator : NSObject <HBDNavigator>
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
//
|
|
2
|
-
// HBDTabNavigator.m
|
|
3
|
-
// HybridNavigation
|
|
4
|
-
//
|
|
5
|
-
// Created by Listen on 2018/6/28.
|
|
6
|
-
// Copyright © 2018年 Listen. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
1
|
#import "HBDTabNavigator.h"
|
|
2
|
+
|
|
10
3
|
#import "HBDTabBarController.h"
|
|
11
4
|
#import "HBDReactBridgeManager.h"
|
|
12
5
|
#import "HBDUtils.h"
|
|
13
6
|
#import "GlobalStyle.h"
|
|
7
|
+
|
|
14
8
|
#import <React/RCTUtils.h>
|
|
15
9
|
|
|
16
10
|
@implementation HBDTabNavigator
|
|
@@ -23,65 +17,65 @@
|
|
|
23
17
|
return @[@"switchTab"];
|
|
24
18
|
}
|
|
25
19
|
|
|
26
|
-
- (UIViewController *)
|
|
27
|
-
NSDictionary *
|
|
28
|
-
NSArray *children =
|
|
29
|
-
if (children) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
tabBarOptions[@"tabBarItemColor"] = style.tabBarItemColorHexString;
|
|
51
|
-
tabBarOptions[@"tabBarUnselectedItemColor"] = style.tabBarUnselectedItemColorHexString;
|
|
52
|
-
tabBarOptions[@"badgeColor"] = style.badgeColorHexString;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
HBDTabBarController *tabBarController = nil;
|
|
56
|
-
|
|
57
|
-
if (hasCustomTabBar) {
|
|
58
|
-
tabBarController = [[HBDTabBarController alloc] initWithTabBarOptions:tabBarOptions];
|
|
59
|
-
} else {
|
|
60
|
-
tabBarController = [[HBDTabBarController alloc] init];
|
|
20
|
+
- (UIViewController *)viewControllerWithLayout:(NSDictionary *)layout {
|
|
21
|
+
NSDictionary *model = layout[self.name];
|
|
22
|
+
NSArray *children = model[@"children"];
|
|
23
|
+
if (!children) {
|
|
24
|
+
return nil;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
NSMutableArray *viewControllers = [[NSMutableArray alloc] initWithCapacity:4];
|
|
28
|
+
for (NSDictionary *tab in children) {
|
|
29
|
+
UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:tab];
|
|
30
|
+
[viewControllers addObject:vc];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
NSDictionary *options = model[@"options"];
|
|
34
|
+
NSArray *tabModels = [self tabModelsWithViewControllers:viewControllers];
|
|
35
|
+
HBDTabBarController *tabBarController = [self createTabBarControllerWithTabModels:tabModels options:options];
|
|
36
|
+
[tabBarController setViewControllers:viewControllers];
|
|
37
|
+
|
|
38
|
+
if (options) {
|
|
39
|
+
NSNumber *selectedIndex = options[@"selectedIndex"];
|
|
40
|
+
if (selectedIndex) {
|
|
41
|
+
tabBarController.intercepted = NO;
|
|
42
|
+
tabBarController.selectedIndex = (NSUInteger) [selectedIndex integerValue];
|
|
43
|
+
tabBarController.intercepted = YES;
|
|
61
44
|
}
|
|
45
|
+
}
|
|
62
46
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (options) {
|
|
66
|
-
NSNumber *selectedIndex = options[@"selectedIndex"];
|
|
67
|
-
if (selectedIndex) {
|
|
68
|
-
tabBarController.intercepted = NO;
|
|
69
|
-
tabBarController.selectedIndex = (NSUInteger) [selectedIndex integerValue];
|
|
70
|
-
tabBarController.intercepted = YES;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
47
|
+
return tabBarController;
|
|
48
|
+
}
|
|
73
49
|
|
|
74
|
-
|
|
50
|
+
- (HBDTabBarController *)createTabBarControllerWithTabModels:(NSArray *)tabModels options:(NSDictionary *)options {
|
|
51
|
+
NSString *moduleName = options[@"tabBarModuleName"];
|
|
52
|
+
BOOL hasCustomTabBar = moduleName.length > 0;
|
|
53
|
+
|
|
54
|
+
if (!hasCustomTabBar) {
|
|
55
|
+
return [[HBDTabBarController alloc] init];
|
|
75
56
|
}
|
|
76
|
-
|
|
57
|
+
|
|
58
|
+
GlobalStyle *style = [GlobalStyle globalStyle];
|
|
59
|
+
|
|
60
|
+
NSDictionary *tabBarOptions = @{
|
|
61
|
+
@"tabs": tabModels,
|
|
62
|
+
@"tabBarModuleName": moduleName,
|
|
63
|
+
@"sizeIndeterminate": options[@"sizeIndeterminate"],
|
|
64
|
+
@"selectedIndex": options[@"selectedIndex"] ?: @(0),
|
|
65
|
+
@"tabBarItemColor": style.tabBarItemColorHexString,
|
|
66
|
+
@"tabBarUnselectedItemColor": style.tabBarUnselectedItemColorHexString,
|
|
67
|
+
@"badgeColor": style.badgeColorHexString,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return [[HBDTabBarController alloc] initWithTabBarOptions:tabBarOptions];
|
|
77
71
|
}
|
|
78
72
|
|
|
79
|
-
- (NSArray<NSDictionary *> *)
|
|
73
|
+
- (NSArray<NSDictionary *> *)tabModelsWithViewControllers:(NSArray<UIViewController *> *)children {
|
|
80
74
|
NSUInteger count = children.count;
|
|
81
|
-
|
|
82
|
-
|
|
75
|
+
NSMutableArray *tabModels = [[NSMutableArray alloc] initWithCapacity:4];
|
|
76
|
+
|
|
83
77
|
for (NSUInteger i = 0; i < count; i++) {
|
|
84
|
-
vc = children[i];
|
|
78
|
+
UIViewController *vc = children[i];
|
|
85
79
|
if ([vc isKindOfClass:[UINavigationController class]]) {
|
|
86
80
|
UINavigationController *nav = (UINavigationController *) vc;
|
|
87
81
|
vc = nav.childViewControllers[0];
|
|
@@ -98,97 +92,123 @@
|
|
|
98
92
|
@"unselectedIcon": RCTNullIfNil([HBDUtils iconUriFromUri:tabItem[@"unselectedIcon"][@"uri"]]),
|
|
99
93
|
@"title": RCTNullIfNil(tabItem[@"title"]),
|
|
100
94
|
};
|
|
101
|
-
[
|
|
95
|
+
[tabModels addObject:tab];
|
|
102
96
|
}
|
|
103
97
|
}
|
|
104
98
|
}
|
|
105
|
-
|
|
99
|
+
|
|
100
|
+
return [tabModels copy];
|
|
106
101
|
}
|
|
107
102
|
|
|
108
|
-
- (NSDictionary *)
|
|
109
|
-
if ([vc isKindOfClass:[HBDTabBarController class]]) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
103
|
+
- (NSDictionary *)routeGraphWithViewController:(UIViewController *)vc {
|
|
104
|
+
if (![vc isKindOfClass:[HBDTabBarController class]]) {
|
|
105
|
+
return nil;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
HBDTabBarController *tabBarController = (HBDTabBarController *) vc;
|
|
109
|
+
NSMutableArray *children = [[NSMutableArray alloc] init];
|
|
110
|
+
for (NSUInteger i = 0; i < tabBarController.childViewControllers.count; i++) {
|
|
111
|
+
UIViewController *child = tabBarController.childViewControllers[i];
|
|
112
|
+
NSDictionary *graph = [[HBDReactBridgeManager get] routeGraphWithViewController:child];
|
|
113
|
+
[children addObject:graph];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return @{
|
|
117
|
+
@"layout": self.name,
|
|
118
|
+
@"sceneId": tabBarController.sceneId,
|
|
119
|
+
@"children": children,
|
|
120
|
+
@"mode": [tabBarController hbd_mode],
|
|
121
|
+
@"selectedIndex": @(tabBarController.selectedIndex)
|
|
122
|
+
};
|
|
126
123
|
}
|
|
127
124
|
|
|
128
125
|
- (HBDViewController *)primaryViewControllerWithViewController:(UIViewController *)vc {
|
|
129
|
-
if ([vc isKindOfClass:[UITabBarController class]]) {
|
|
130
|
-
|
|
131
|
-
return [[HBDReactBridgeManager get] primaryViewControllerWithViewController:tabBarVc.selectedViewController];
|
|
126
|
+
if (![vc isKindOfClass:[UITabBarController class]]) {
|
|
127
|
+
return nil;
|
|
132
128
|
}
|
|
133
|
-
|
|
129
|
+
UITabBarController *tabBarController = (UITabBarController *) vc;
|
|
130
|
+
return [[HBDReactBridgeManager get] primaryViewControllerWithViewController:tabBarController.selectedViewController];
|
|
134
131
|
}
|
|
135
132
|
|
|
136
|
-
- (
|
|
137
|
-
|
|
138
|
-
UITabBarController *tabBarController = nil;
|
|
133
|
+
- (UITabBarController *)tabBarControllerForViewController:(UIViewController *)vc {
|
|
139
134
|
if ([vc isKindOfClass:[UITabBarController class]]) {
|
|
140
|
-
|
|
135
|
+
return (UITabBarController *) vc;
|
|
136
|
+
} else {
|
|
137
|
+
return vc.tabBarController;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
- (void)handleSwitchTabWithTabBarController:(UITabBarController *)tabBarController extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
|
|
142
|
+
BOOL popToRoot = [extras[@"popToRoot"] boolValue];
|
|
143
|
+
NSNumber *from = extras[@"from"];
|
|
144
|
+
NSUInteger to = [extras[@"to"] integerValue];
|
|
145
|
+
|
|
146
|
+
if (from && [from integerValue] == to) {
|
|
147
|
+
callback(@[NSNull.null, @YES]);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (popToRoot) {
|
|
152
|
+
UIViewController *selectedViewController = [tabBarController selectedViewController];
|
|
153
|
+
UINavigationController *nav = nil;
|
|
154
|
+
if ([selectedViewController isKindOfClass:[UINavigationController class]]) {
|
|
155
|
+
nav = (UINavigationController *)selectedViewController;
|
|
156
|
+
} else {
|
|
157
|
+
nav = selectedViewController.navigationController;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (nav && nav.childViewControllers.count > 1) {
|
|
161
|
+
[nav popToRootViewControllerAnimated:NO];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if ([tabBarController isKindOfClass:[HBDTabBarController class]]) {
|
|
166
|
+
HBDTabBarController *hbdTabBarController = (HBDTabBarController *)tabBarController;
|
|
167
|
+
hbdTabBarController.intercepted = NO;
|
|
168
|
+
tabBarController.selectedIndex = to;
|
|
169
|
+
hbdTabBarController.intercepted = YES;
|
|
141
170
|
} else {
|
|
142
|
-
tabBarController =
|
|
171
|
+
tabBarController.selectedIndex = to;
|
|
143
172
|
}
|
|
173
|
+
|
|
174
|
+
callback(@[NSNull.null, @YES]);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
|
|
178
|
+
if (!vc.hbd_inViewHierarchy) {
|
|
179
|
+
callback(@[NSNull.null, @NO]);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
UITabBarController *tabBarController = [self tabBarControllerForViewController:vc];
|
|
144
184
|
|
|
145
185
|
if (!tabBarController) {
|
|
146
|
-
|
|
186
|
+
callback(@[NSNull.null, @NO]);
|
|
147
187
|
return;
|
|
148
188
|
}
|
|
149
189
|
|
|
150
190
|
if (!tabBarController.hbd_viewAppeared) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
191
|
+
[self performSelector:@selector(handleNavigation:) withObject:@{
|
|
192
|
+
@"viewController": vc,
|
|
193
|
+
@"action": action,
|
|
194
|
+
@"extras": extras,
|
|
195
|
+
@"callback": callback,
|
|
196
|
+
} afterDelay:0.05];
|
|
154
197
|
return;
|
|
155
198
|
}
|
|
156
199
|
|
|
157
200
|
if ([action isEqualToString:@"switchTab"]) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
NSUInteger to = [extras[@"to"] integerValue];
|
|
161
|
-
|
|
162
|
-
if (from && [from integerValue] == to) {
|
|
163
|
-
resolve(@(YES));
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (popToRoot) {
|
|
168
|
-
UIViewController *selectedViewController = [tabBarController selectedViewController];
|
|
169
|
-
UINavigationController *nav = nil;
|
|
170
|
-
if ([selectedViewController isKindOfClass:[UINavigationController class]]) {
|
|
171
|
-
nav = (UINavigationController *) selectedViewController;
|
|
172
|
-
} else {
|
|
173
|
-
nav = selectedViewController.navigationController;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (nav && nav.childViewControllers.count > 1) {
|
|
177
|
-
[nav popToRootViewControllerAnimated:NO];
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
if ([tabBarController isKindOfClass:[HBDTabBarController class]]) {
|
|
182
|
-
HBDTabBarController *hbdTabBarVC = (HBDTabBarController *) tabBarController;
|
|
183
|
-
hbdTabBarVC.intercepted = NO;
|
|
184
|
-
tabBarController.selectedIndex = to;
|
|
185
|
-
hbdTabBarVC.intercepted = YES;
|
|
186
|
-
} else {
|
|
187
|
-
tabBarController.selectedIndex = to;
|
|
188
|
-
}
|
|
201
|
+
[self handleSwitchTabWithTabBarController:tabBarController extras:extras callback:callback];
|
|
202
|
+
return;
|
|
189
203
|
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
-(void)handleNavigation:(NSDictionary *)params {
|
|
207
|
+
[self handleNavigationWithViewController:params[@"viewController"] action:params[@"action"] extras:params[@"extras"] callback:params[@"callback"]];
|
|
208
|
+
}
|
|
190
209
|
|
|
191
|
-
|
|
210
|
+
- (void)invalidate {
|
|
211
|
+
[NSObject cancelPreviousPerformRequestsWithTarget:self];
|
|
192
212
|
}
|
|
193
213
|
|
|
194
214
|
@end
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
//
|
|
2
|
-
// HBDEventEmitter.h
|
|
3
|
-
// HybridNavigation
|
|
4
|
-
//
|
|
5
|
-
// Created by Listen on 2018/12/27.
|
|
6
|
-
// Copyright © 2018 Listen. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
#import <Foundation/Foundation.h>
|
|
10
|
-
#import <React/RCTBridgeModule.h>
|
|
11
1
|
#import <React/RCTEventEmitter.h>
|
|
12
2
|
|
|
13
3
|
NS_ASSUME_NONNULL_BEGIN
|
|
@@ -29,7 +19,7 @@ extern NSString *const KEY_INDEX;
|
|
|
29
19
|
extern NSString *const KEY_ACTION;
|
|
30
20
|
extern NSString *const KEY_ON;
|
|
31
21
|
|
|
32
|
-
@interface HBDEventEmitter : RCTEventEmitter
|
|
22
|
+
@interface HBDEventEmitter : RCTEventEmitter
|
|
33
23
|
|
|
34
24
|
+ (void)sendEvent:(NSString *)eventName data:(NSDictionary *)data;
|
|
35
25
|
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
//
|
|
2
|
-
// HBDEventEmitter.m
|
|
3
|
-
// HybridNavigation
|
|
4
|
-
//
|
|
5
|
-
// Created by Listen on 2018/12/27.
|
|
6
|
-
// Copyright © 2018 Listen. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
1
|
#import "HBDEventEmitter.h"
|
|
2
|
+
|
|
10
3
|
#import "HBDReactBridgeManager.h"
|
|
11
4
|
|
|
5
|
+
#import <React/RCTBridgeModule.h>
|
|
6
|
+
|
|
12
7
|
NSString *const ON_COMPONENT_RESULT = @"ON_COMPONENT_RESULT";
|
|
13
8
|
NSString *const ON_BAR_BUTTON_ITEM_CLICK = @"ON_BAR_BUTTON_ITEM_CLICK";
|
|
14
9
|
NSString *const ON_COMPONENT_APPEAR = @"ON_COMPONENT_APPEAR";
|
|
@@ -30,8 +25,7 @@ NSString *const KEY_ON = @"on";
|
|
|
30
25
|
|
|
31
26
|
@implementation HBDEventEmitter
|
|
32
27
|
|
|
33
|
-
|
|
34
|
-
RCT_EXPORT_MODULE(HBDEventEmitter);
|
|
28
|
+
RCT_EXPORT_MODULE(HBDEventEmitter)
|
|
35
29
|
|
|
36
30
|
- (NSArray<NSString *> *)supportedEvents {
|
|
37
31
|
return @[EVENT_NAVIGATION, EVENT_SWITCH_TAB, EVENT_DID_SET_ROOT, EVENT_WILL_SET_ROOT];
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#import "HBDGardenModule.h"
|
|
2
|
+
|
|
3
|
+
#import "HBDReactBridgeManager.h"
|
|
4
|
+
#import "HBDTabBarController.h"
|
|
5
|
+
#import "GlobalStyle.h"
|
|
6
|
+
|
|
7
|
+
#import <React/RCTLog.h>
|
|
8
|
+
|
|
9
|
+
@interface HBDGardenModule ()
|
|
10
|
+
|
|
11
|
+
@property(nonatomic, strong, readonly) HBDReactBridgeManager *bridgeManager;
|
|
12
|
+
|
|
13
|
+
@end
|
|
14
|
+
|
|
15
|
+
@implementation HBDGardenModule
|
|
16
|
+
|
|
17
|
+
+ (BOOL)requiresMainQueueSetup {
|
|
18
|
+
return YES;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
RCT_EXPORT_MODULE(GardenModule)
|
|
22
|
+
|
|
23
|
+
- (instancetype)init {
|
|
24
|
+
if (self = [super init]) {
|
|
25
|
+
_bridgeManager = [HBDReactBridgeManager get];
|
|
26
|
+
}
|
|
27
|
+
return self;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
- (dispatch_queue_t)methodQueue {
|
|
31
|
+
return dispatch_get_main_queue();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
- (NSDictionary *)constantsToExport {
|
|
35
|
+
return @{@"TOOLBAR_HEIGHT": @(44)};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
RCT_EXPORT_METHOD(setStyle:(NSDictionary *) style) {
|
|
39
|
+
[GlobalStyle createWithOptions:style];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
RCT_EXPORT_METHOD(setTitleItem:(NSString *)sceneId item:(NSDictionary *)item) {
|
|
43
|
+
HBDViewController *vc = [self viewControllerWithSceneId:sceneId];
|
|
44
|
+
if (vc) {
|
|
45
|
+
[vc updateNavigationBarOptions:@{@"titleItem": RCTNullIfNil(item)}];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
RCT_EXPORT_METHOD(setLeftBarButtonItem:(NSString *)sceneId item:(NSDictionary *__nullable)item) {
|
|
50
|
+
HBDViewController *vc = [self viewControllerWithSceneId:sceneId];
|
|
51
|
+
if (vc) {
|
|
52
|
+
[vc updateNavigationBarOptions:@{@"leftBarButtonItem": RCTNullIfNil(item)}];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
RCT_EXPORT_METHOD(setRightBarButtonItem:(NSString *)sceneId item:(NSDictionary *__nullable)item) {
|
|
57
|
+
HBDViewController *vc = [self viewControllerWithSceneId:sceneId];
|
|
58
|
+
if (vc) {
|
|
59
|
+
[vc updateNavigationBarOptions:@{@"rightBarButtonItem": RCTNullIfNil(item)}];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
RCT_EXPORT_METHOD(setLeftBarButtonItems:(NSString *)sceneId item:(NSArray *__nullable)items) {
|
|
64
|
+
HBDViewController *vc = [self viewControllerWithSceneId:sceneId];
|
|
65
|
+
if (vc) {
|
|
66
|
+
[vc updateNavigationBarOptions:@{@"leftBarButtonItems": RCTNullIfNil(items)}];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
RCT_EXPORT_METHOD(setRightBarButtonItems:(NSString *)sceneId item:(NSArray *__nullable)items) {
|
|
71
|
+
HBDViewController *vc = [self viewControllerWithSceneId:sceneId];
|
|
72
|
+
if (vc) {
|
|
73
|
+
[vc updateNavigationBarOptions:@{@"rightBarButtonItems": RCTNullIfNil(items)}];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
RCT_EXPORT_METHOD(updateOptions:(NSString *)sceneId item:(NSDictionary *)options) {
|
|
78
|
+
RCTLogInfo(@"[Navigator] updateNavigationBarOptions: %@", options);
|
|
79
|
+
HBDViewController *vc = [self viewControllerWithSceneId:sceneId];
|
|
80
|
+
if (vc) {
|
|
81
|
+
[vc updateNavigationBarOptions:options];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
RCT_EXPORT_METHOD(updateTabBar:(NSString *)sceneId item:(NSDictionary *)item) {
|
|
86
|
+
RCTLogInfo(@"[Navigator] updateTabBar: %@", item);
|
|
87
|
+
UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
|
|
88
|
+
UITabBarController *tabBarVC = [self tabBarControllerWithViewController:vc];
|
|
89
|
+
if (tabBarVC && [tabBarVC isKindOfClass:[HBDTabBarController class]]) {
|
|
90
|
+
[((HBDTabBarController *)tabBarVC) updateTabBar:item];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
RCT_EXPORT_METHOD(setTabItem:(NSString *)sceneId options:(NSArray<NSDictionary *> *)options) {
|
|
95
|
+
RCTLogInfo(@"[Navigator] setTabItem: %@", options);
|
|
96
|
+
UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
|
|
97
|
+
UITabBarController *tabBarController = [self tabBarControllerWithViewController:vc];
|
|
98
|
+
if ([tabBarController isKindOfClass:[HBDTabBarController class]]) {
|
|
99
|
+
HBDTabBarController *tabBarVC = (HBDTabBarController *)tabBarController;
|
|
100
|
+
[tabBarVC setTabItem:options];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
RCT_EXPORT_METHOD(setMenuInteractive:(NSString *)sceneId enabled:(BOOL)enabled) {
|
|
105
|
+
UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
|
|
106
|
+
HBDDrawerController *drawer = [vc drawerController];
|
|
107
|
+
if (drawer) {
|
|
108
|
+
drawer.menuInteractive = enabled;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
- (HBDViewController *)viewControllerWithSceneId:(NSString *)sceneId {
|
|
113
|
+
UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
|
|
114
|
+
if ([vc isKindOfClass:[HBDViewController class]]) {
|
|
115
|
+
return (HBDViewController *)vc;
|
|
116
|
+
}
|
|
117
|
+
return nil;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
- (UITabBarController *)tabBarControllerWithViewController:(UIViewController *)vc {
|
|
121
|
+
if ([vc isKindOfClass:[UITabBarController class]]) {
|
|
122
|
+
return (UITabBarController *)vc;
|
|
123
|
+
} else {
|
|
124
|
+
return vc.tabBarController;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
@end
|