hybrid-navigation 2.7.5 → 2.7.8
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/CHANGELOG.md +24 -0
- package/android/build.gradle +1 -1
- package/ios/HybridNavigation/Bridge/HBDEventEmitter.h +16 -16
- package/ios/HybridNavigation/Bridge/HBDEventEmitter.m +33 -33
- package/ios/HybridNavigation/Bridge/HBDGardenModule.m +43 -25
- package/ios/HybridNavigation/Bridge/HBDNavigationModule.m +83 -58
- package/ios/HybridNavigation/Bridge/HBDReactBridgeManager.h +3 -3
- package/ios/HybridNavigation/Bridge/HBDReactBridgeManager.m +57 -61
- package/ios/HybridNavigation/GlobalStyle.h +7 -7
- package/ios/HybridNavigation/GlobalStyle.m +86 -86
- package/ios/HybridNavigation/HBDGarden.m +28 -28
- package/ios/HybridNavigation/HBDUtils.h +4 -4
- package/ios/HybridNavigation/HBDUtils.m +43 -49
- package/ios/HybridNavigation/Navigator/HBDDrawerNavigator.m +24 -24
- package/ios/HybridNavigation/Navigator/HBDNavigator.h +2 -2
- package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.h +4 -4
- package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.m +19 -20
- package/ios/HybridNavigation/Navigator/HBDScreenNavigator.m +24 -26
- package/ios/HybridNavigation/Navigator/HBDStackNavigator.m +31 -30
- package/ios/HybridNavigation/Navigator/HBDTabNavigator.m +54 -56
- package/ios/HybridNavigation/View/HBDBarButtonItem.h +1 -1
- package/ios/HybridNavigation/View/HBDBarButtonItem.m +5 -5
- package/ios/HybridNavigation/View/HBDNavigationBar.h +4 -4
- package/ios/HybridNavigation/View/HBDNavigationBar.m +19 -20
- package/ios/HybridNavigation/View/HBDReactTabBar.m +3 -3
- package/ios/HybridNavigation/View/HBDRootView.m +3 -3
- package/ios/HybridNavigation/View/HBDTitleView.m +7 -7
- package/ios/HybridNavigation/View/UITabBar+Badge.h +1 -0
- package/ios/HybridNavigation/View/UITabBar+Badge.m +6 -6
- package/ios/HybridNavigation/ViewController/HBDDrawerController.h +8 -5
- package/ios/HybridNavigation/ViewController/HBDDrawerController.m +39 -38
- package/ios/HybridNavigation/ViewController/HBDModalViewController.h +2 -2
- package/ios/HybridNavigation/ViewController/HBDModalViewController.m +45 -44
- package/ios/HybridNavigation/ViewController/HBDNavigationController.h +1 -1
- package/ios/HybridNavigation/ViewController/HBDNavigationController.m +111 -113
- package/ios/HybridNavigation/ViewController/HBDPopAnimation.m +4 -4
- package/ios/HybridNavigation/ViewController/HBDPushAnimation.m +4 -4
- package/ios/HybridNavigation/ViewController/HBDReactViewController.m +24 -26
- package/ios/HybridNavigation/ViewController/HBDTabBarController.h +1 -1
- package/ios/HybridNavigation/ViewController/HBDTabBarController.m +25 -26
- package/ios/HybridNavigation/ViewController/HBDViewController.m +31 -32
- package/ios/HybridNavigation/ViewController/UINavigationController+HBD.m +5 -4
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.h +20 -19
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.m +35 -36
- package/lib/DeepLink.js +5 -5
- package/lib/hooks.d.ts +1 -1
- package/lib/hooks.js +4 -7
- package/package.json +1 -1
|
@@ -14,18 +14,18 @@
|
|
|
14
14
|
+ (NSDictionary *)mergeItem:(NSDictionary *)item withTarget:(NSDictionary *)target {
|
|
15
15
|
NSMutableDictionary *mutableTarget = [target mutableCopy];
|
|
16
16
|
for (NSString *key in [item allKeys]) {
|
|
17
|
-
id obj = [
|
|
17
|
+
id obj = item[key];
|
|
18
18
|
if (obj == nil) {
|
|
19
19
|
//ignore
|
|
20
20
|
} else if ([obj isKindOfClass:[NSDictionary class]]) {
|
|
21
|
-
NSDictionary *subTarget = [
|
|
21
|
+
NSDictionary *subTarget = target[key];
|
|
22
22
|
if (RCTNilIfNull(subTarget)) {
|
|
23
|
-
[
|
|
23
|
+
mutableTarget[key] = [self mergeItem:obj withTarget:subTarget];
|
|
24
24
|
} else {
|
|
25
|
-
[
|
|
25
|
+
mutableTarget[key] = obj;
|
|
26
26
|
}
|
|
27
27
|
} else if ([obj isKindOfClass:[NSArray class]]) {
|
|
28
|
-
NSArray *array = [
|
|
28
|
+
NSArray *array = target[key];
|
|
29
29
|
if (array) {
|
|
30
30
|
NSArray *items = obj;
|
|
31
31
|
NSMutableArray *result = [[NSMutableArray alloc] init];
|
|
@@ -33,79 +33,73 @@
|
|
|
33
33
|
NSDictionary *dict = [self mergeItem:items[i] withTarget:array[i]];
|
|
34
34
|
[result addObject:dict];
|
|
35
35
|
}
|
|
36
|
-
[
|
|
36
|
+
mutableTarget[key] = result;
|
|
37
37
|
} else {
|
|
38
|
-
[
|
|
38
|
+
mutableTarget[key] = obj;
|
|
39
39
|
}
|
|
40
40
|
} else {
|
|
41
|
-
[
|
|
41
|
+
mutableTarget[key] = obj;
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
return [mutableTarget copy];
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
+ (UIColor *)
|
|
48
|
+
+ (UIColor *)colorWithHexString:(NSString *)hexString {
|
|
49
49
|
NSString *colorString = [[hexString stringByReplacingOccurrencesOfString:@"#" withString:@""] uppercaseString];
|
|
50
50
|
CGFloat alpha, red, green, blue;
|
|
51
51
|
switch ([colorString length]) {
|
|
52
52
|
case 6: // #RRGGBB
|
|
53
53
|
alpha = 1.0f;
|
|
54
|
-
red
|
|
55
|
-
green = [self colorComponentFrom:
|
|
56
|
-
blue
|
|
54
|
+
red = [self colorComponentFrom:colorString start:0 length:2];
|
|
55
|
+
green = [self colorComponentFrom:colorString start:2 length:2];
|
|
56
|
+
blue = [self colorComponentFrom:colorString start:4 length:2];
|
|
57
57
|
break;
|
|
58
58
|
case 8: // #AARRGGBB
|
|
59
|
-
alpha = [self colorComponentFrom:
|
|
60
|
-
red
|
|
61
|
-
green = [self colorComponentFrom:
|
|
62
|
-
blue
|
|
59
|
+
alpha = [self colorComponentFrom:colorString start:0 length:2];
|
|
60
|
+
red = [self colorComponentFrom:colorString start:2 length:2];
|
|
61
|
+
green = [self colorComponentFrom:colorString start:4 length:2];
|
|
62
|
+
blue = [self colorComponentFrom:colorString start:6 length:2];
|
|
63
63
|
break;
|
|
64
64
|
default:
|
|
65
|
-
|
|
66
|
-
red = 0.0f;
|
|
67
|
-
green = 0.0f;
|
|
68
|
-
blue = 0.0f;
|
|
69
|
-
[NSException raise:@"Invalid color value" format: @"Color value %@ is invalid. It should be a hex value of the form #RRGGBB, or #AARRGGBB", hexString];
|
|
70
|
-
break;
|
|
65
|
+
[NSException raise:@"Invalid color value" format:@"Color value %@ is invalid. It should be a hex value of the form #RRGGBB, or #AARRGGBB", hexString];
|
|
71
66
|
}
|
|
72
|
-
return [UIColor colorWithRed:
|
|
67
|
+
return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
|
|
73
68
|
}
|
|
74
69
|
|
|
75
|
-
+ (CGFloat)colorComponentFrom:
|
|
76
|
-
NSString *substring = [string substringWithRange:
|
|
77
|
-
NSString *fullHex = length == 2 ? substring : [NSString stringWithFormat
|
|
70
|
+
+ (CGFloat)colorComponentFrom:(NSString *)string start:(NSUInteger)start length:(NSUInteger)length {
|
|
71
|
+
NSString *substring = [string substringWithRange:NSMakeRange(start, length)];
|
|
72
|
+
NSString *fullHex = length == 2 ? substring : [NSString stringWithFormat:@"0%@", substring];
|
|
78
73
|
unsigned hexComponent;
|
|
79
|
-
[[NSScanner scannerWithString:
|
|
74
|
+
[[NSScanner scannerWithString:fullHex] scanHexInt:&hexComponent];
|
|
80
75
|
return hexComponent / 255.0;
|
|
81
76
|
}
|
|
82
77
|
|
|
83
|
-
+ (UIImage*)imageWithColor:(UIColor*)color {
|
|
78
|
+
+ (UIImage *)imageWithColor:(UIColor *)color {
|
|
84
79
|
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
|
|
85
80
|
UIGraphicsBeginImageContext(rect.size);
|
|
86
81
|
CGContextRef context = UIGraphicsGetCurrentContext();
|
|
87
82
|
CGContextSetFillColorWithColor(context, [color CGColor]);
|
|
88
83
|
CGContextFillRect(context, rect);
|
|
89
|
-
UIImage*theImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
84
|
+
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
90
85
|
UIGraphicsEndImageContext();
|
|
91
86
|
return theImage;
|
|
92
87
|
}
|
|
93
88
|
|
|
94
89
|
+ (UIImage *)UIImage:(NSDictionary *)json {
|
|
95
90
|
if ([json isKindOfClass:[NSDictionary class]]) {
|
|
96
|
-
|
|
91
|
+
NSString *uri = json[@"uri"];
|
|
97
92
|
if (uri && [uri hasPrefix:@"font:"]) {
|
|
98
93
|
NSString *path = [self imagePathFromFontUri:uri];
|
|
99
94
|
// RCTLogInfo(@"[Navigator] font path:%@", path);
|
|
100
95
|
UIImage *image = [UIImage imageWithContentsOfFile:path];
|
|
101
96
|
return image;
|
|
102
|
-
}
|
|
97
|
+
} else {
|
|
103
98
|
return [RCTConvert UIImage:json];
|
|
104
99
|
}
|
|
105
100
|
} else {
|
|
106
101
|
return [RCTConvert UIImage:json];
|
|
107
102
|
}
|
|
108
|
-
return nil;
|
|
109
103
|
}
|
|
110
104
|
|
|
111
105
|
+ (NSString *)iconUriFromUri:(NSString *)uri {
|
|
@@ -126,37 +120,37 @@
|
|
|
126
120
|
NSString *glyph = components[1];
|
|
127
121
|
CGFloat size = [components[2] floatValue];
|
|
128
122
|
UIColor *color = UIColor.whiteColor;
|
|
129
|
-
if (components.count >=4) {
|
|
123
|
+
if (components.count >= 4) {
|
|
130
124
|
color = [self colorWithHexString:components[3]];
|
|
131
125
|
}
|
|
132
126
|
NSString *path = [self imagePathForFont:font withGlyph:glyph withFontSize:size withColor:color];
|
|
133
127
|
return path;
|
|
134
128
|
}
|
|
135
129
|
|
|
136
|
-
+ (NSString *)imagePathForFont:(NSString*)fontName withGlyph:(NSString*)glyph withFontSize:(CGFloat)fontSize withColor:(UIColor *)color {
|
|
130
|
+
+ (NSString *)imagePathForFont:(NSString *)fontName withGlyph:(NSString *)glyph withFontSize:(CGFloat)fontSize withColor:(UIColor *)color {
|
|
137
131
|
CGFloat screenScale = RCTScreenScale();
|
|
138
|
-
|
|
132
|
+
|
|
139
133
|
NSString *hexColor = [self hexStringFromColor:color];
|
|
140
|
-
|
|
134
|
+
|
|
141
135
|
NSString *fileName = [NSString stringWithFormat:@"tmp/RNVectorIcons_%@_%hu_%.f%@@%.fx.png", fontName, [glyph characterAtIndex:0], fontSize, hexColor, screenScale];
|
|
142
136
|
NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent:fileName];
|
|
143
|
-
|
|
144
|
-
if(![[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
|
|
137
|
+
|
|
138
|
+
if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
|
|
145
139
|
// No cached icon exists, we need to create it and persist to disk
|
|
146
|
-
|
|
140
|
+
|
|
147
141
|
UIFont *font = [UIFont fontWithName:fontName size:fontSize];
|
|
148
142
|
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:glyph attributes:@{NSFontAttributeName: font, NSForegroundColorAttributeName: color}];
|
|
149
|
-
|
|
143
|
+
|
|
150
144
|
CGSize iconSize = [attributedString size];
|
|
151
145
|
UIGraphicsBeginImageContextWithOptions(iconSize, NO, 0.0);
|
|
152
146
|
[attributedString drawAtPoint:CGPointMake(0, 0)];
|
|
153
|
-
|
|
147
|
+
|
|
154
148
|
UIImage *iconImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
155
149
|
UIGraphicsEndImageContext();
|
|
156
|
-
|
|
150
|
+
|
|
157
151
|
NSData *imageData = UIImagePNGRepresentation(iconImage);
|
|
158
152
|
BOOL success = [imageData writeToFile:filePath atomically:YES];
|
|
159
|
-
if(!success) {
|
|
153
|
+
if (!success) {
|
|
160
154
|
RCTLogInfo(@"[Navigator] can't save %@", fileName);
|
|
161
155
|
return nil;
|
|
162
156
|
}
|
|
@@ -166,15 +160,15 @@
|
|
|
166
160
|
|
|
167
161
|
+ (NSString *)hexStringFromColor:(UIColor *)color {
|
|
168
162
|
const CGFloat *components = CGColorGetComponents(color.CGColor);
|
|
169
|
-
|
|
163
|
+
|
|
170
164
|
CGFloat r = components[0];
|
|
171
165
|
CGFloat g = components[1];
|
|
172
166
|
CGFloat b = components[2];
|
|
173
|
-
|
|
167
|
+
|
|
174
168
|
return [NSString stringWithFormat:@"#%02lX%02lX%02lX",
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
169
|
+
lroundf(r * 255),
|
|
170
|
+
lroundf(g * 255),
|
|
171
|
+
lroundf(b * 255)];
|
|
178
172
|
}
|
|
179
173
|
|
|
180
174
|
+ (BOOL)isIphoneX {
|
|
@@ -16,34 +16,34 @@
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
- (NSArray<NSString *> *)supportActions {
|
|
19
|
-
return @[
|
|
19
|
+
return @[@"toggleMenu", @"openMenu", @"closeMenu"];
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
- (UIViewController *)createViewControllerWithLayout:(NSDictionary *)layout {
|
|
23
|
-
NSDictionary *drawer = [
|
|
24
|
-
NSArray *children = [
|
|
23
|
+
NSDictionary *drawer = layout[self.name];
|
|
24
|
+
NSArray *children = drawer[@"children"];
|
|
25
25
|
if (children.count == 2) {
|
|
26
|
-
NSDictionary *content = [
|
|
27
|
-
NSDictionary *menu = [
|
|
28
|
-
|
|
26
|
+
NSDictionary *content = children[0];
|
|
27
|
+
NSDictionary *menu = children[1];
|
|
28
|
+
|
|
29
29
|
UIViewController *contentController = [[HBDReactBridgeManager get] controllerWithLayout:content];
|
|
30
30
|
UIViewController *menuController = [[HBDReactBridgeManager get] controllerWithLayout:menu];
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
if (contentController && menuController) {
|
|
33
33
|
HBDDrawerController *drawerController = [[HBDDrawerController alloc] initWithContentViewController:contentController menuViewController:menuController];
|
|
34
|
-
NSDictionary *options = [
|
|
34
|
+
NSDictionary *options = drawer[@"options"];
|
|
35
35
|
if (options) {
|
|
36
|
-
NSNumber *maxDrawerWidth = [
|
|
36
|
+
NSNumber *maxDrawerWidth = options[@"maxDrawerWidth"];
|
|
37
37
|
if (maxDrawerWidth) {
|
|
38
38
|
[drawerController setMaxDrawerWidth:[maxDrawerWidth floatValue]];
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
NSNumber *minDrawerMargin = [
|
|
40
|
+
|
|
41
|
+
NSNumber *minDrawerMargin = options[@"minDrawerMargin"];
|
|
42
42
|
if (minDrawerMargin) {
|
|
43
43
|
[drawerController setMinDrawerMargin:[minDrawerMargin floatValue]];
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
NSNumber *menuInteractive = [
|
|
45
|
+
|
|
46
|
+
NSNumber *menuInteractive = options[@"menuInteractive"];
|
|
47
47
|
if (menuInteractive) {
|
|
48
48
|
drawerController.menuInteractive = [menuInteractive boolValue];
|
|
49
49
|
}
|
|
@@ -56,14 +56,14 @@
|
|
|
56
56
|
|
|
57
57
|
- (NSDictionary *)buildRouteGraphWithViewController:(UIViewController *)vc {
|
|
58
58
|
if ([vc isKindOfClass:[HBDDrawerController class]]) {
|
|
59
|
-
HBDDrawerController *drawer = (HBDDrawerController *)vc;
|
|
60
|
-
NSDictionary *content= [[HBDReactBridgeManager get] buildRouteGraphWithViewController:drawer.contentController];
|
|
59
|
+
HBDDrawerController *drawer = (HBDDrawerController *) vc;
|
|
60
|
+
NSDictionary *content = [[HBDReactBridgeManager get] buildRouteGraphWithViewController:drawer.contentController];
|
|
61
61
|
NSDictionary *menu = [[HBDReactBridgeManager get] buildRouteGraphWithViewController:drawer.menuController];
|
|
62
62
|
return @{
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
@"layout": @"drawer",
|
|
64
|
+
@"sceneId": vc.sceneId,
|
|
65
|
+
@"children": @[content, menu],
|
|
66
|
+
@"mode": [vc hbd_mode],
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
return nil;
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
|
|
72
72
|
- (HBDViewController *)primaryViewControllerWithViewController:(UIViewController *)vc {
|
|
73
73
|
if ([vc isKindOfClass:[HBDDrawerController class]]) {
|
|
74
|
-
HBDDrawerController *drawer = (HBDDrawerController *)vc;
|
|
74
|
+
HBDDrawerController *drawer = (HBDDrawerController *) vc;
|
|
75
75
|
if (drawer.isMenuOpened) {
|
|
76
76
|
return [[HBDReactBridgeManager get] primaryViewControllerWithViewController:drawer.menuController];
|
|
77
77
|
} else {
|
|
@@ -87,14 +87,14 @@
|
|
|
87
87
|
resolve(@(NO));
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
|
-
|
|
90
|
+
|
|
91
91
|
if (!drawer.hbd_viewAppeared) {
|
|
92
|
-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
92
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
93
93
|
[self handleNavigationWithViewController:vc action:action extras:extras resolver:resolve rejecter:reject];
|
|
94
94
|
});
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
|
|
98
98
|
if ([action isEqualToString:@"toggleMenu"]) {
|
|
99
99
|
[drawer toggleMenu];
|
|
100
100
|
} else if ([action isEqualToString:@"openMenu"]) {
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
} else if ([action isEqualToString:@"closeMenu"]) {
|
|
103
103
|
[drawer closeMenu];
|
|
104
104
|
}
|
|
105
|
-
|
|
105
|
+
|
|
106
106
|
resolve(@(YES));
|
|
107
107
|
}
|
|
108
108
|
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
|
|
13
13
|
@protocol HBDNavigator <NSObject>
|
|
14
14
|
|
|
15
|
-
@property
|
|
16
|
-
@property
|
|
15
|
+
@property(nonatomic, copy, readonly) NSString *name;
|
|
16
|
+
@property(nonatomic, copy, readonly) NSArray<NSString *> *supportActions;
|
|
17
17
|
|
|
18
18
|
- (UIViewController *)createViewControllerWithLayout:(NSDictionary *)layout;
|
|
19
19
|
|
|
@@ -11,17 +11,17 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
11
11
|
|
|
12
12
|
@interface HBDNavigatorRegistry : NSObject
|
|
13
13
|
|
|
14
|
-
- (void)registerNavigator:(id<HBDNavigator>)navigator;
|
|
14
|
+
- (void)registerNavigator:(id <HBDNavigator>)navigator;
|
|
15
15
|
|
|
16
|
-
- (id<HBDNavigator>)navigatorForAction:(NSString *)action;
|
|
16
|
+
- (id <HBDNavigator>)navigatorForAction:(NSString *)action;
|
|
17
17
|
|
|
18
|
-
- (id<HBDNavigator>)navigatorForLayout:(NSString *)layout;
|
|
18
|
+
- (id <HBDNavigator>)navigatorForLayout:(NSString *)layout;
|
|
19
19
|
|
|
20
20
|
- (NSString *)layoutForViewController:(UIViewController *)vc;
|
|
21
21
|
|
|
22
22
|
- (void)setLayout:(NSString *)layout forViewController:(UIViewController *)vc;
|
|
23
23
|
|
|
24
|
-
- (NSArray<NSString *> *)
|
|
24
|
+
- (NSArray<NSString *> *)allLayouts;
|
|
25
25
|
|
|
26
26
|
@end
|
|
27
27
|
|
|
@@ -16,13 +16,12 @@
|
|
|
16
16
|
|
|
17
17
|
#import "HBDNavigationController.h"
|
|
18
18
|
#import "HBDTabBarController.h"
|
|
19
|
-
#import "HBDDrawerController.h"
|
|
20
19
|
|
|
21
20
|
@interface HBDNavigatorRegistry ()
|
|
22
21
|
|
|
23
22
|
@property(nonatomic, strong) NSMutableArray<NSString *> *layouts;
|
|
24
|
-
@property(nonatomic, strong) NSMutableDictionary<NSString *, id<HBDNavigator>> *actionNavigatorPairs;
|
|
25
|
-
@property(nonatomic, strong) NSMutableDictionary<NSString *, id<HBDNavigator>> *layoutNavigatorPairs;
|
|
23
|
+
@property(nonatomic, strong) NSMutableDictionary<NSString *, id <HBDNavigator>> *actionNavigatorPairs;
|
|
24
|
+
@property(nonatomic, strong) NSMutableDictionary<NSString *, id <HBDNavigator>> *layoutNavigatorPairs;
|
|
26
25
|
@property(nonatomic, strong) NSMutableDictionary<NSString *, NSString *> *classLayoutPairs;
|
|
27
26
|
|
|
28
27
|
@end
|
|
@@ -36,44 +35,44 @@
|
|
|
36
35
|
_layoutNavigatorPairs = [NSMutableDictionary new];
|
|
37
36
|
_classLayoutPairs = [NSMutableDictionary new];
|
|
38
37
|
}
|
|
39
|
-
|
|
38
|
+
|
|
40
39
|
[self registerNavigator:[HBDStackNavigator new]];
|
|
41
40
|
[self registerNavigator:[HBDScreenNavigator new]];
|
|
42
41
|
[self registerNavigator:[HBDTabNavigator new]];
|
|
43
42
|
[self registerNavigator:[HBDDrawerNavigator new]];
|
|
44
|
-
|
|
43
|
+
|
|
45
44
|
return self;
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
- (void)registerNavigator:(id<HBDNavigator>)navigator {
|
|
47
|
+
- (void)registerNavigator:(id <HBDNavigator>)navigator {
|
|
49
48
|
[self.layouts addObject:[navigator name]];
|
|
50
|
-
|
|
49
|
+
|
|
51
50
|
for (NSString *action in [navigator supportActions]) {
|
|
52
|
-
id<HBDNavigator> duplicated =
|
|
51
|
+
id <HBDNavigator> duplicated = self.actionNavigatorPairs[action];
|
|
53
52
|
if (duplicated) {
|
|
54
53
|
RCTLogError(@"[Navigator] The action %@ that %@ wants to register has been registered by %@", action, [navigator class], [duplicated class]);
|
|
55
54
|
}
|
|
56
|
-
|
|
55
|
+
self.actionNavigatorPairs[action] = navigator;
|
|
57
56
|
}
|
|
58
|
-
|
|
57
|
+
|
|
59
58
|
NSString *layout = [navigator name];
|
|
60
|
-
id<HBDNavigator> duplicatedLayout =
|
|
59
|
+
id <HBDNavigator> duplicatedLayout = self.layoutNavigatorPairs[layout];
|
|
61
60
|
if (duplicatedLayout) {
|
|
62
61
|
RCTLogError(@"[Navigator] The layout %@ that %@ wants to register has been registered by %@", layout, [navigator class], [duplicatedLayout class]);
|
|
63
62
|
}
|
|
64
|
-
|
|
63
|
+
self.layoutNavigatorPairs[layout] = navigator;
|
|
65
64
|
}
|
|
66
65
|
|
|
67
|
-
- (id<HBDNavigator>)navigatorForAction:(NSString *)action {
|
|
68
|
-
return
|
|
66
|
+
- (id <HBDNavigator>)navigatorForAction:(NSString *)action {
|
|
67
|
+
return self.actionNavigatorPairs[action];
|
|
69
68
|
}
|
|
70
69
|
|
|
71
|
-
- (id<HBDNavigator>)navigatorForLayout:(NSString *)layout {
|
|
72
|
-
return
|
|
70
|
+
- (id <HBDNavigator>)navigatorForLayout:(NSString *)layout {
|
|
71
|
+
return self.layoutNavigatorPairs[layout];
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
- (NSString *)layoutForViewController:(UIViewController *)vc {
|
|
76
|
-
NSString *layout =
|
|
75
|
+
NSString *layout = self.classLayoutPairs[NSStringFromClass([vc class])];
|
|
77
76
|
if (!layout) {
|
|
78
77
|
if ([vc isKindOfClass:[HBDViewController class]]) {
|
|
79
78
|
return @"screen";
|
|
@@ -92,13 +91,13 @@
|
|
|
92
91
|
}
|
|
93
92
|
|
|
94
93
|
- (void)setLayout:(NSString *)layout forViewController:(UIViewController *)vc {
|
|
95
|
-
NSString *current =
|
|
94
|
+
NSString *current = self.classLayoutPairs[NSStringFromClass([vc class])];
|
|
96
95
|
if (!current || ![current isEqualToString:layout]) {
|
|
97
|
-
|
|
96
|
+
self.classLayoutPairs[NSStringFromClass([vc class])] = layout;
|
|
98
97
|
}
|
|
99
98
|
}
|
|
100
99
|
|
|
101
|
-
- (NSArray<NSString *> *)
|
|
100
|
+
- (NSArray<NSString *> *)allLayouts {
|
|
102
101
|
return [self.layouts copy];
|
|
103
102
|
}
|
|
104
103
|
|
|
@@ -10,9 +10,7 @@
|
|
|
10
10
|
#import "HBDReactBridgeManager.h"
|
|
11
11
|
#import "HBDNavigationController.h"
|
|
12
12
|
#import "HBDModalViewController.h"
|
|
13
|
-
#import <React/RCTAssert.h>
|
|
14
13
|
#import <React/RCTLog.h>
|
|
15
|
-
#import "HBDEventEmitter.h"
|
|
16
14
|
|
|
17
15
|
@implementation HBDScreenNavigator
|
|
18
16
|
|
|
@@ -21,15 +19,15 @@
|
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
- (NSArray<NSString *> *)supportActions {
|
|
24
|
-
return @[
|
|
22
|
+
return @[@"present", @"presentLayout", @"dismiss", @"showModal", @"showModalLayout", @"hideModal"];
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
- (UIViewController *)createViewControllerWithLayout:(NSDictionary *)layout {
|
|
28
|
-
NSDictionary *screen = [
|
|
26
|
+
NSDictionary *screen = layout[self.name];
|
|
29
27
|
if (screen) {
|
|
30
|
-
NSString *moduleName = [
|
|
31
|
-
NSDictionary *props = [
|
|
32
|
-
NSDictionary *options = [
|
|
28
|
+
NSString *moduleName = screen[@"moduleName"];
|
|
29
|
+
NSDictionary *props = screen[@"props"];
|
|
30
|
+
NSDictionary *options = screen[@"options"];
|
|
33
31
|
return [[HBDReactBridgeManager get] controllerWithModuleName:moduleName props:props options:options];
|
|
34
32
|
}
|
|
35
33
|
return nil;
|
|
@@ -37,12 +35,12 @@
|
|
|
37
35
|
|
|
38
36
|
- (NSDictionary *)buildRouteGraphWithViewController:(UIViewController *)vc {
|
|
39
37
|
if ([vc isKindOfClass:[HBDViewController class]]) {
|
|
40
|
-
HBDViewController *screen = (HBDViewController *)vc;
|
|
38
|
+
HBDViewController *screen = (HBDViewController *) vc;
|
|
41
39
|
return @{
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
@"layout": @"screen",
|
|
41
|
+
@"sceneId": screen.sceneId,
|
|
42
|
+
@"moduleName": RCTNullIfNil(screen.moduleName),
|
|
43
|
+
@"mode": [vc hbd_mode],
|
|
46
44
|
};
|
|
47
45
|
}
|
|
48
46
|
return nil;
|
|
@@ -50,28 +48,28 @@
|
|
|
50
48
|
|
|
51
49
|
- (HBDViewController *)primaryViewControllerWithViewController:(UIViewController *)vc {
|
|
52
50
|
if ([vc isKindOfClass:[HBDModalViewController class]]) {
|
|
53
|
-
HBDModalViewController *modal = (HBDModalViewController *)vc;
|
|
51
|
+
HBDModalViewController *modal = (HBDModalViewController *) vc;
|
|
54
52
|
return [[HBDReactBridgeManager get] primaryViewControllerWithViewController:modal.contentViewController];
|
|
55
53
|
} else if ([vc isKindOfClass:[HBDViewController class]]) {
|
|
56
|
-
return (HBDViewController *)vc;
|
|
54
|
+
return (HBDViewController *) vc;
|
|
57
55
|
}
|
|
58
56
|
return nil;
|
|
59
57
|
}
|
|
60
58
|
|
|
61
59
|
- (void)handleNavigationWithViewController:(UIViewController *)target action:(NSString *)action extras:(NSDictionary *)extras resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject {
|
|
62
|
-
|
|
60
|
+
|
|
63
61
|
if (!target.hbd_viewAppeared) {
|
|
64
|
-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
62
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
65
63
|
[self handleNavigationWithViewController:target action:action extras:extras resolver:resolve rejecter:reject];
|
|
66
64
|
});
|
|
67
65
|
return;
|
|
68
66
|
}
|
|
69
|
-
|
|
67
|
+
|
|
70
68
|
UIViewController *viewController = nil;
|
|
71
69
|
|
|
72
70
|
if ([action isEqualToString:@"present"]) {
|
|
73
71
|
viewController = [self createViewControllerWithExtras:extras];
|
|
74
|
-
NSInteger requestCode = [[
|
|
72
|
+
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
75
73
|
HBDNavigationController *navVC = [[HBDNavigationController alloc] initWithRootViewController:viewController];
|
|
76
74
|
navVC.modalPresentationStyle = UIModalPresentationCurrentContext;
|
|
77
75
|
[navVC setRequestCode:requestCode];
|
|
@@ -91,7 +89,7 @@
|
|
|
91
89
|
}
|
|
92
90
|
} else if ([action isEqualToString:@"showModal"]) {
|
|
93
91
|
viewController = [self createViewControllerWithExtras:extras];
|
|
94
|
-
NSInteger requestCode = [[
|
|
92
|
+
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
95
93
|
[target hbd_showViewController:viewController requestCode:requestCode animated:YES completion:^(BOOL finished) {
|
|
96
94
|
resolve(@(finished));
|
|
97
95
|
}];
|
|
@@ -100,8 +98,8 @@
|
|
|
100
98
|
resolve(@(finished));
|
|
101
99
|
}];
|
|
102
100
|
} else if ([action isEqualToString:@"presentLayout"]) {
|
|
103
|
-
NSDictionary *layout = [
|
|
104
|
-
NSInteger requestCode = [[
|
|
101
|
+
NSDictionary *layout = extras[@"layout"];
|
|
102
|
+
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
105
103
|
viewController = [[HBDReactBridgeManager get] controllerWithLayout:layout];
|
|
106
104
|
[viewController setRequestCode:requestCode];
|
|
107
105
|
viewController.modalPresentationStyle = UIModalPresentationCurrentContext;
|
|
@@ -109,8 +107,8 @@
|
|
|
109
107
|
resolve(@(YES));
|
|
110
108
|
}];
|
|
111
109
|
} else if ([action isEqualToString:@"showModalLayout"]) {
|
|
112
|
-
NSInteger requestCode = [[
|
|
113
|
-
NSDictionary *layout = [
|
|
110
|
+
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
111
|
+
NSDictionary *layout = extras[@"layout"];
|
|
114
112
|
viewController = [[HBDReactBridgeManager get] controllerWithLayout:layout];
|
|
115
113
|
[target hbd_showViewController:viewController requestCode:requestCode animated:YES completion:^(BOOL finished) {
|
|
116
114
|
resolve(@(finished));
|
|
@@ -119,11 +117,11 @@
|
|
|
119
117
|
}
|
|
120
118
|
|
|
121
119
|
- (UIViewController *)createViewControllerWithExtras:(NSDictionary *)extras {
|
|
122
|
-
NSString *moduleName = [
|
|
120
|
+
NSString *moduleName = extras[@"moduleName"];
|
|
123
121
|
HBDViewController *viewController = nil;
|
|
124
122
|
if (moduleName) {
|
|
125
|
-
NSDictionary *props = [
|
|
126
|
-
NSDictionary *options = [
|
|
123
|
+
NSDictionary *props = extras[@"props"];
|
|
124
|
+
NSDictionary *options = extras[@"options"];
|
|
127
125
|
viewController = [[HBDReactBridgeManager get] controllerWithModuleName:moduleName props:props options:options];
|
|
128
126
|
}
|
|
129
127
|
return viewController;
|