|
@@ -18,405 +18,365 @@
|
18
|
18
|
|
19
|
19
|
|
20
|
20
|
-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
|
21
|
|
- return [self supportedControllerOrientations];
|
|
21
|
+ return [self supportedControllerOrientations];
|
22
|
22
|
}
|
23
|
23
|
|
24
|
24
|
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
|
25
|
|
- id queue = [[RCCManager sharedInstance].getBridge uiManager].methodQueue;
|
26
|
|
- dispatch_async(queue, ^{
|
27
|
|
- [[[RCCManager sharedInstance].getBridge uiManager] configureNextLayoutAnimation:nil withCallback:^(NSArray* arr){} errorCallback:^(NSArray* arr){}];
|
28
|
|
- });
|
29
|
|
-
|
30
|
|
- if (tabBarController.selectedIndex != [tabBarController.viewControllers indexOfObject:viewController]) {
|
31
|
|
- NSDictionary *body = @{
|
32
|
|
- @"selectedTabIndex": @([tabBarController.viewControllers indexOfObject:viewController]),
|
33
|
|
- @"unselectedTabIndex": @(tabBarController.selectedIndex)
|
34
|
|
- };
|
35
|
|
- [RCCTabBarController sendScreenTabChangedEvent:viewController body:body];
|
|
25
|
+ id queue = [[RCCManager sharedInstance].getBridge uiManager].methodQueue;
|
|
26
|
+ dispatch_async(queue, ^{
|
|
27
|
+ [[[RCCManager sharedInstance].getBridge uiManager] configureNextLayoutAnimation:nil withCallback:^(NSArray* arr){} errorCallback:^(NSArray* arr){}];
|
|
28
|
+ });
|
36
|
29
|
|
37
|
|
- [[[RCCManager sharedInstance] getBridge].eventDispatcher sendAppEventWithName:@"bottomTabSelected" body:body];
|
38
|
|
- if ([viewController isKindOfClass:[UINavigationController class]]) {
|
39
|
|
- UINavigationController *navigationController = (UINavigationController*)viewController;
|
40
|
|
- UIViewController *topViewController = navigationController.topViewController;
|
41
|
|
-
|
42
|
|
- if ([topViewController isKindOfClass:[RCCViewController class]]) {
|
43
|
|
- RCCViewController *topRCCViewController = (RCCViewController*)topViewController;
|
44
|
|
- topRCCViewController.commandType = COMMAND_TYPE_BOTTOME_TAB_SELECTED;
|
45
|
|
- topRCCViewController.timestamp = [RCTHelpers getTimestampString];
|
46
|
|
- }
|
|
30
|
+ if (tabBarController.selectedIndex != [tabBarController.viewControllers indexOfObject:viewController]) {
|
|
31
|
+ NSDictionary *body = @{
|
|
32
|
+ @"selectedTabIndex": @([tabBarController.viewControllers indexOfObject:viewController]),
|
|
33
|
+ @"unselectedTabIndex": @(tabBarController.selectedIndex)
|
|
34
|
+ };
|
|
35
|
+ [RCCTabBarController sendScreenTabChangedEvent:viewController body:body];
|
|
36
|
+
|
|
37
|
+ [[[RCCManager sharedInstance] getBridge].eventDispatcher sendAppEventWithName:@"bottomTabSelected" body:body];
|
|
38
|
+ if ([viewController isKindOfClass:[UINavigationController class]]) {
|
|
39
|
+ UINavigationController *navigationController = (UINavigationController*)viewController;
|
|
40
|
+ UIViewController *topViewController = navigationController.topViewController;
|
|
41
|
+
|
|
42
|
+ if ([topViewController isKindOfClass:[RCCViewController class]]) {
|
|
43
|
+ RCCViewController *topRCCViewController = (RCCViewController*)topViewController;
|
|
44
|
+ topRCCViewController.commandType = COMMAND_TYPE_BOTTOME_TAB_SELECTED;
|
|
45
|
+ topRCCViewController.timestamp = [RCTHelpers getTimestampString];
|
|
46
|
+ }
|
|
47
|
+ }
|
|
48
|
+
|
|
49
|
+ } else {
|
|
50
|
+ [RCCTabBarController sendScreenTabPressedEvent:viewController body:nil];
|
47
|
51
|
}
|
48
|
52
|
|
49
|
|
- } else {
|
50
|
|
- [RCCTabBarController sendScreenTabPressedEvent:viewController body:nil];
|
51
|
|
- }
|
52
|
|
-
|
53
|
|
-
|
54
|
|
-
|
55
|
|
- return YES;
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+ return YES;
|
56
|
56
|
}
|
57
|
57
|
|
58
|
|
-- (UIImage *)image:(UIImage*)image withColor:(UIColor *)color1
|
59
|
|
-{
|
60
|
|
- UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
|
61
|
|
- CGContextRef context = UIGraphicsGetCurrentContext();
|
62
|
|
- CGContextTranslateCTM(context, 0, image.size.height);
|
63
|
|
- CGContextScaleCTM(context, 1.0, -1.0);
|
64
|
|
- CGContextSetBlendMode(context, kCGBlendModeNormal);
|
65
|
|
- CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
|
66
|
|
- CGContextClipToMask(context, rect, image.CGImage);
|
67
|
|
- [color1 setFill];
|
68
|
|
- CGContextFillRect(context, rect);
|
69
|
|
- UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
|
70
|
|
- UIGraphicsEndImageContext();
|
71
|
|
- return newImage;
|
|
58
|
+- (UIImage *)image:(UIImage*)image withColor:(UIColor *)color1 {
|
|
59
|
+ UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
|
|
60
|
+ CGContextRef context = UIGraphicsGetCurrentContext();
|
|
61
|
+ CGContextTranslateCTM(context, 0, image.size.height);
|
|
62
|
+ CGContextScaleCTM(context, 1.0, -1.0);
|
|
63
|
+ CGContextSetBlendMode(context, kCGBlendModeNormal);
|
|
64
|
+ CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
|
|
65
|
+ CGContextClipToMask(context, rect, image.CGImage);
|
|
66
|
+ [color1 setFill];
|
|
67
|
+ CGContextFillRect(context, rect);
|
|
68
|
+ UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
69
|
+ UIGraphicsEndImageContext();
|
|
70
|
+ return newImage;
|
72
|
71
|
}
|
73
|
72
|
|
74
|
|
-- (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children globalProps:(NSDictionary*)globalProps bridge:(RCTBridge *)bridge
|
75
|
|
-{
|
76
|
|
- self = [super init];
|
77
|
|
- if (!self) return nil;
|
78
|
|
-
|
79
|
|
- self.delegate = self;
|
80
|
|
-
|
81
|
|
- self.tabBar.translucent = YES; // default
|
82
|
|
-
|
83
|
|
- UIColor *buttonColor = nil;
|
84
|
|
- UIColor *selectedButtonColor = nil;
|
85
|
|
- UIColor *labelColor = nil;
|
86
|
|
- UIColor *selectedLabelColor = nil;
|
87
|
|
- NSDictionary *tabsStyle = props[@"style"];
|
88
|
|
- if (tabsStyle)
|
89
|
|
- {
|
90
|
|
- NSString *tabBarButtonColor = tabsStyle[@"tabBarButtonColor"];
|
91
|
|
- if (tabBarButtonColor)
|
92
|
|
- {
|
93
|
|
- UIColor *color = tabBarButtonColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarButtonColor] : nil;
|
94
|
|
- self.tabBar.tintColor = color;
|
95
|
|
- buttonColor = color;
|
96
|
|
- selectedButtonColor = color;
|
97
|
|
- }
|
98
|
|
- NSString *tabBarSelectedButtonColor = tabsStyle[@"tabBarSelectedButtonColor"];
|
99
|
|
- if (tabBarSelectedButtonColor)
|
100
|
|
- {
|
101
|
|
- UIColor *color = tabBarSelectedButtonColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarSelectedButtonColor] : nil;
|
102
|
|
- self.tabBar.tintColor = color;
|
103
|
|
- selectedButtonColor = color;
|
104
|
|
- }
|
105
|
|
- NSString *tabBarLabelColor = tabsStyle[@"tabBarLabelColor"];
|
106
|
|
- if(tabBarLabelColor) {
|
107
|
|
- UIColor *color = tabBarLabelColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarLabelColor] : nil;
|
108
|
|
- labelColor = color;
|
109
|
|
- }
|
110
|
|
- NSString *tabBarSelectedLabelColor = tabsStyle[@"tabBarSelectedLabelColor"];
|
111
|
|
- if(tabBarLabelColor) {
|
112
|
|
- UIColor *color = tabBarSelectedLabelColor != (id)[NSNull null] ? [RCTConvert UIColor:
|
113
|
|
- tabBarSelectedLabelColor] : nil;
|
114
|
|
- selectedLabelColor = color;
|
115
|
|
- }
|
116
|
|
- NSString *tabBarBackgroundColor = tabsStyle[@"tabBarBackgroundColor"];
|
117
|
|
- if (tabBarBackgroundColor)
|
118
|
|
- {
|
119
|
|
- UIColor *color = tabBarBackgroundColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarBackgroundColor] : nil;
|
120
|
|
- self.tabBar.barTintColor = color;
|
121
|
|
- }
|
122
|
|
-
|
123
|
|
- NSString *tabBarTranslucent = tabsStyle[@"tabBarTranslucent"];
|
124
|
|
- if (tabBarTranslucent)
|
125
|
|
- {
|
126
|
|
- self.tabBar.translucent = [tabBarTranslucent boolValue] ? YES : NO;
|
127
|
|
- }
|
128
|
|
-
|
129
|
|
- NSString *tabBarHideShadow = tabsStyle[@"tabBarHideShadow"];
|
130
|
|
- if (tabBarHideShadow)
|
131
|
|
- {
|
132
|
|
- self.tabBar.clipsToBounds = [tabBarHideShadow boolValue] ? YES : NO;
|
133
|
|
- }
|
134
|
|
- }
|
135
|
|
-
|
136
|
|
- NSMutableArray *viewControllers = [NSMutableArray array];
|
137
|
|
-
|
138
|
|
- // go over all the tab bar items
|
139
|
|
- for (NSDictionary *tabItemLayout in children)
|
140
|
|
- {
|
141
|
|
- // make sure the layout is valid
|
142
|
|
- if (![tabItemLayout[@"type"] isEqualToString:@"TabBarControllerIOS.Item"]) continue;
|
143
|
|
- if (!tabItemLayout[@"props"]) continue;
|
|
73
|
+- (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children globalProps:(NSDictionary*)globalProps bridge:(RCTBridge *)bridge {
|
|
74
|
+ self = [super init];
|
|
75
|
+ if (!self) return nil;
|
144
|
76
|
|
145
|
|
- // get the view controller inside
|
146
|
|
- if (!tabItemLayout[@"children"]) continue;
|
147
|
|
- if (![tabItemLayout[@"children"] isKindOfClass:[NSArray class]]) continue;
|
148
|
|
- if ([tabItemLayout[@"children"] count] < 1) continue;
|
149
|
|
- NSDictionary *childLayout = tabItemLayout[@"children"][0];
|
150
|
|
- UIViewController *viewController = [RCCViewController controllerWithLayout:childLayout globalProps:globalProps bridge:bridge];
|
151
|
|
- if (!viewController) continue;
|
|
77
|
+ self.delegate = self;
|
152
|
78
|
|
153
|
|
- // create the tab icon and title
|
154
|
|
- NSString *title = tabItemLayout[@"props"][@"title"];
|
155
|
|
- UIImage *iconImage = nil;
|
156
|
|
- id icon = tabItemLayout[@"props"][@"icon"];
|
157
|
|
- if (icon)
|
158
|
|
- {
|
159
|
|
- iconImage = [RCTConvert UIImage:icon];
|
160
|
|
- if (buttonColor)
|
161
|
|
- {
|
162
|
|
- iconImage = [[self image:iconImage withColor:buttonColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
163
|
|
- }
|
164
|
|
- }
|
165
|
|
- UIImage *iconImageSelected = nil;
|
166
|
|
- id selectedIcon = tabItemLayout[@"props"][@"selectedIcon"];
|
167
|
|
- if (selectedIcon) {
|
168
|
|
- iconImageSelected = [RCTConvert UIImage:selectedIcon];
|
169
|
|
- } else {
|
170
|
|
- iconImageSelected = [RCTConvert UIImage:icon];
|
|
79
|
+ self.tabBar.translucent = YES; // default
|
|
80
|
+
|
|
81
|
+ UIColor *buttonColor = nil;
|
|
82
|
+ UIColor *selectedButtonColor = nil;
|
|
83
|
+ UIColor *labelColor = nil;
|
|
84
|
+ UIColor *selectedLabelColor = nil;
|
|
85
|
+ NSDictionary *tabsStyle = props[@"style"];
|
|
86
|
+ if (tabsStyle) {
|
|
87
|
+ NSString *tabBarButtonColor = tabsStyle[@"tabBarButtonColor"];
|
|
88
|
+ if (tabBarButtonColor) {
|
|
89
|
+ UIColor *color = tabBarButtonColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarButtonColor] : nil;
|
|
90
|
+ self.tabBar.tintColor = color;
|
|
91
|
+ buttonColor = color;
|
|
92
|
+ selectedButtonColor = color;
|
|
93
|
+ }
|
|
94
|
+ NSString *tabBarSelectedButtonColor = tabsStyle[@"tabBarSelectedButtonColor"];
|
|
95
|
+ if (tabBarSelectedButtonColor) {
|
|
96
|
+ UIColor *color = tabBarSelectedButtonColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarSelectedButtonColor] : nil;
|
|
97
|
+ self.tabBar.tintColor = color;
|
|
98
|
+ selectedButtonColor = color;
|
|
99
|
+ }
|
|
100
|
+ NSString *tabBarLabelColor = tabsStyle[@"tabBarLabelColor"];
|
|
101
|
+ if (tabBarLabelColor) {
|
|
102
|
+ UIColor *color = tabBarLabelColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarLabelColor] : nil;
|
|
103
|
+ labelColor = color;
|
|
104
|
+ }
|
|
105
|
+ NSString *tabBarSelectedLabelColor = tabsStyle[@"tabBarSelectedLabelColor"];
|
|
106
|
+ if (tabBarLabelColor) {
|
|
107
|
+ UIColor *color = tabBarSelectedLabelColor != (id)[NSNull null] ? [RCTConvert UIColor:
|
|
108
|
+ tabBarSelectedLabelColor] : nil;
|
|
109
|
+ selectedLabelColor = color;
|
|
110
|
+ }
|
|
111
|
+ NSString *tabBarBackgroundColor = tabsStyle[@"tabBarBackgroundColor"];
|
|
112
|
+ if (tabBarBackgroundColor) {
|
|
113
|
+ UIColor *color = tabBarBackgroundColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarBackgroundColor] : nil;
|
|
114
|
+ self.tabBar.barTintColor = color;
|
|
115
|
+ }
|
|
116
|
+
|
|
117
|
+ NSString *tabBarTranslucent = tabsStyle[@"tabBarTranslucent"];
|
|
118
|
+ if (tabBarTranslucent) {
|
|
119
|
+ self.tabBar.translucent = [tabBarTranslucent boolValue] ? YES : NO;
|
|
120
|
+ }
|
|
121
|
+
|
|
122
|
+ NSString *tabBarHideShadow = tabsStyle[@"tabBarHideShadow"];
|
|
123
|
+ if (tabBarHideShadow) {
|
|
124
|
+ self.tabBar.clipsToBounds = [tabBarHideShadow boolValue] ? YES : NO;
|
|
125
|
+ }
|
171
|
126
|
}
|
172
|
127
|
|
173
|
|
- viewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:iconImage tag:0];
|
174
|
|
- viewController.tabBarItem.accessibilityIdentifier = tabItemLayout[@"props"][@"testID"];
|
175
|
|
- viewController.tabBarItem.selectedImage = iconImageSelected;
|
|
128
|
+ NSMutableArray *viewControllers = [NSMutableArray array];
|
176
|
129
|
|
177
|
|
- id imageInsets = tabItemLayout[@"props"][@"iconInsets"];
|
178
|
|
- if (imageInsets && imageInsets != (id)[NSNull null])
|
179
|
|
- {
|
180
|
|
- id topInset = imageInsets[@"top"];
|
181
|
|
- id leftInset = imageInsets[@"left"];
|
182
|
|
- id bottomInset = imageInsets[@"bottom"];
|
183
|
|
- id rightInset = imageInsets[@"right"];
|
184
|
|
-
|
185
|
|
- CGFloat top = topInset != (id)[NSNull null] ? [RCTConvert CGFloat:topInset] : 0;
|
186
|
|
- CGFloat left = topInset != (id)[NSNull null] ? [RCTConvert CGFloat:leftInset] : 0;
|
187
|
|
- CGFloat bottom = topInset != (id)[NSNull null] ? [RCTConvert CGFloat:bottomInset] : 0;
|
188
|
|
- CGFloat right = topInset != (id)[NSNull null] ? [RCTConvert CGFloat:rightInset] : 0;
|
189
|
|
-
|
190
|
|
- viewController.tabBarItem.imageInsets = UIEdgeInsetsMake(top, left, bottom, right);
|
191
|
|
- }
|
192
|
|
- NSMutableDictionary *unselectedAttributes = [RCTHelpers textAttributesFromDictionary:tabsStyle withPrefix:@"tabBarText" baseFont:[UIFont systemFontOfSize:10]];
|
193
|
|
- if (!unselectedAttributes[NSForegroundColorAttributeName] && labelColor) {
|
194
|
|
- unselectedAttributes[NSForegroundColorAttributeName] = labelColor;
|
|
130
|
+ // go over all the tab bar items
|
|
131
|
+ for (NSDictionary *tabItemLayout in children) {
|
|
132
|
+ // make sure the layout is valid
|
|
133
|
+ if (![tabItemLayout[@"type"] isEqualToString:@"TabBarControllerIOS.Item"]) continue;
|
|
134
|
+ if (!tabItemLayout[@"props"]) continue;
|
|
135
|
+
|
|
136
|
+ // get the view controller inside
|
|
137
|
+ if (!tabItemLayout[@"children"]) continue;
|
|
138
|
+ if (![tabItemLayout[@"children"] isKindOfClass:[NSArray class]]) continue;
|
|
139
|
+ if ([tabItemLayout[@"children"] count] < 1) continue;
|
|
140
|
+ NSDictionary *childLayout = tabItemLayout[@"children"][0];
|
|
141
|
+ UIViewController *viewController = [RCCViewController controllerWithLayout:childLayout globalProps:globalProps bridge:bridge];
|
|
142
|
+ if (!viewController) continue;
|
|
143
|
+
|
|
144
|
+ // create the tab icon and title
|
|
145
|
+ NSString *title = tabItemLayout[@"props"][@"title"];
|
|
146
|
+ UIImage *iconImage = nil;
|
|
147
|
+ id icon = tabItemLayout[@"props"][@"icon"];
|
|
148
|
+ if (icon) {
|
|
149
|
+ iconImage = [RCTConvert UIImage:icon];
|
|
150
|
+ if (buttonColor) {
|
|
151
|
+ iconImage = [[self image:iconImage withColor:buttonColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
|
152
|
+ }
|
|
153
|
+ }
|
|
154
|
+ UIImage *iconImageSelected = nil;
|
|
155
|
+ id selectedIcon = tabItemLayout[@"props"][@"selectedIcon"];
|
|
156
|
+ if (selectedIcon) {
|
|
157
|
+ iconImageSelected = [RCTConvert UIImage:selectedIcon];
|
|
158
|
+ } else {
|
|
159
|
+ iconImageSelected = [RCTConvert UIImage:icon];
|
|
160
|
+ }
|
|
161
|
+
|
|
162
|
+ viewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:iconImage tag:0];
|
|
163
|
+ viewController.tabBarItem.accessibilityIdentifier = tabItemLayout[@"props"][@"testID"];
|
|
164
|
+ viewController.tabBarItem.selectedImage = iconImageSelected;
|
|
165
|
+
|
|
166
|
+ id imageInsets = tabItemLayout[@"props"][@"iconInsets"];
|
|
167
|
+ if (imageInsets && imageInsets != (id)[NSNull null]) {
|
|
168
|
+ id topInset = imageInsets[@"top"];
|
|
169
|
+ id leftInset = imageInsets[@"left"];
|
|
170
|
+ id bottomInset = imageInsets[@"bottom"];
|
|
171
|
+ id rightInset = imageInsets[@"right"];
|
|
172
|
+
|
|
173
|
+ CGFloat top = topInset != (id)[NSNull null] ? [RCTConvert CGFloat:topInset] : 0;
|
|
174
|
+ CGFloat left = topInset != (id)[NSNull null] ? [RCTConvert CGFloat:leftInset] : 0;
|
|
175
|
+ CGFloat bottom = topInset != (id)[NSNull null] ? [RCTConvert CGFloat:bottomInset] : 0;
|
|
176
|
+ CGFloat right = topInset != (id)[NSNull null] ? [RCTConvert CGFloat:rightInset] : 0;
|
|
177
|
+
|
|
178
|
+ viewController.tabBarItem.imageInsets = UIEdgeInsetsMake(top, left, bottom, right);
|
|
179
|
+ }
|
|
180
|
+ NSMutableDictionary *unselectedAttributes = [RCTHelpers textAttributesFromDictionary:tabsStyle withPrefix:@"tabBarText" baseFont:[UIFont systemFontOfSize:10]];
|
|
181
|
+ if (!unselectedAttributes[NSForegroundColorAttributeName] && labelColor) {
|
|
182
|
+ unselectedAttributes[NSForegroundColorAttributeName] = labelColor;
|
|
183
|
+ }
|
|
184
|
+
|
|
185
|
+ [viewController.tabBarItem setTitleTextAttributes:unselectedAttributes forState:UIControlStateNormal];
|
|
186
|
+
|
|
187
|
+ NSMutableDictionary *selectedAttributes = [RCTHelpers textAttributesFromDictionary:tabsStyle withPrefix:@"tabBarSelectedText" baseFont:[UIFont systemFontOfSize:10]];
|
|
188
|
+ if (!selectedAttributes[NSForegroundColorAttributeName] && selectedLabelColor) {
|
|
189
|
+ selectedAttributes[NSForegroundColorAttributeName] = selectedLabelColor;
|
|
190
|
+ }
|
|
191
|
+
|
|
192
|
+ [viewController.tabBarItem setTitleTextAttributes:selectedAttributes forState:UIControlStateSelected];
|
|
193
|
+ // create badge
|
|
194
|
+ NSObject *badge = tabItemLayout[@"props"][@"badge"];
|
|
195
|
+ if (badge == nil || [badge isEqual:[NSNull null]]) {
|
|
196
|
+ viewController.tabBarItem.badgeValue = nil;
|
|
197
|
+ } else {
|
|
198
|
+ viewController.tabBarItem.badgeValue = [NSString stringWithFormat:@"%@", badge];
|
|
199
|
+ }
|
|
200
|
+
|
|
201
|
+ [viewControllers addObject:viewController];
|
195
|
202
|
}
|
196
|
203
|
|
197
|
|
- [viewController.tabBarItem setTitleTextAttributes:unselectedAttributes forState:UIControlStateNormal];
|
|
204
|
+ // replace the tabs
|
|
205
|
+ self.viewControllers = viewControllers;
|
198
|
206
|
|
199
|
|
- NSMutableDictionary *selectedAttributes = [RCTHelpers textAttributesFromDictionary:tabsStyle withPrefix:@"tabBarSelectedText" baseFont:[UIFont systemFontOfSize:10]];
|
200
|
|
- if (!selectedAttributes[NSForegroundColorAttributeName] && selectedLabelColor) {
|
201
|
|
- selectedAttributes[NSForegroundColorAttributeName] = selectedLabelColor;
|
|
207
|
+ NSNumber *initialTab = tabsStyle[@"initialTabIndex"];
|
|
208
|
+ if (initialTab) {
|
|
209
|
+ NSInteger initialTabIndex = initialTab.integerValue;
|
|
210
|
+ [self setSelectedIndex:initialTabIndex];
|
202
|
211
|
}
|
203
|
212
|
|
204
|
|
- [viewController.tabBarItem setTitleTextAttributes:selectedAttributes forState:UIControlStateSelected];
|
205
|
|
- // create badge
|
206
|
|
- NSObject *badge = tabItemLayout[@"props"][@"badge"];
|
207
|
|
- if (badge == nil || [badge isEqual:[NSNull null]])
|
208
|
|
- {
|
209
|
|
- viewController.tabBarItem.badgeValue = nil;
|
210
|
|
- }
|
211
|
|
- else
|
212
|
|
- {
|
213
|
|
- viewController.tabBarItem.badgeValue = [NSString stringWithFormat:@"%@", badge];
|
214
|
|
- }
|
|
213
|
+ [self setRotation:props];
|
215
|
214
|
|
216
|
|
- [viewControllers addObject:viewController];
|
217
|
|
- }
|
218
|
|
-
|
219
|
|
- // replace the tabs
|
220
|
|
- self.viewControllers = viewControllers;
|
221
|
|
-
|
222
|
|
- NSNumber *initialTab = tabsStyle[@"initialTabIndex"];
|
223
|
|
- if (initialTab)
|
224
|
|
- {
|
225
|
|
- NSInteger initialTabIndex = initialTab.integerValue;
|
226
|
|
- [self setSelectedIndex:initialTabIndex];
|
227
|
|
- }
|
228
|
|
-
|
229
|
|
- [self setRotation:props];
|
230
|
|
-
|
231
|
|
- return self;
|
|
215
|
+ return self;
|
232
|
216
|
}
|
233
|
217
|
|
234
|
|
-- (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actionParams bridge:(RCTBridge *)bridge completion:(void (^)(void))completion
|
235
|
|
-{
|
236
|
|
- if ([performAction isEqualToString:@"setBadge"])
|
237
|
|
- {
|
238
|
|
- UIViewController *viewController = nil;
|
239
|
|
- NSNumber *tabIndex = actionParams[@"tabIndex"];
|
240
|
|
- if (tabIndex)
|
241
|
|
- {
|
242
|
|
- int i = (int)[tabIndex integerValue];
|
243
|
|
-
|
244
|
|
- if ([self.viewControllers count] > i)
|
245
|
|
- {
|
246
|
|
- viewController = [self.viewControllers objectAtIndex:i];
|
247
|
|
- }
|
248
|
|
- }
|
249
|
|
- NSString *contentId = actionParams[@"contentId"];
|
250
|
|
- NSString *contentType = actionParams[@"contentType"];
|
251
|
|
- if (contentId && contentType)
|
252
|
|
- {
|
253
|
|
- viewController = [[RCCManager sharedInstance] getControllerWithId:contentId componentType:contentType];
|
|
218
|
+- (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actionParams bridge:(RCTBridge *)bridge completion:(void (^)(void))completion {
|
|
219
|
+ if ([performAction isEqualToString:@"setBadge"]) {
|
|
220
|
+ UIViewController *viewController = nil;
|
|
221
|
+ NSNumber *tabIndex = actionParams[@"tabIndex"];
|
|
222
|
+ if (tabIndex) {
|
|
223
|
+ int i = (int)[tabIndex integerValue];
|
|
224
|
+
|
|
225
|
+ if ([self.viewControllers count] > i) {
|
|
226
|
+ viewController = [self.viewControllers objectAtIndex:i];
|
|
227
|
+ }
|
|
228
|
+ }
|
|
229
|
+ NSString *contentId = actionParams[@"contentId"];
|
|
230
|
+ NSString *contentType = actionParams[@"contentType"];
|
|
231
|
+ if (contentId && contentType) {
|
|
232
|
+ viewController = [[RCCManager sharedInstance] getControllerWithId:contentId componentType:contentType];
|
|
233
|
+ }
|
|
234
|
+
|
|
235
|
+ if (viewController) {
|
|
236
|
+ NSObject *badge = actionParams[@"badge"];
|
|
237
|
+
|
|
238
|
+ if (badge == nil || [badge isEqual:[NSNull null]]) {
|
|
239
|
+ viewController.tabBarItem.badgeValue = nil;
|
|
240
|
+ }
|
|
241
|
+ else
|
|
242
|
+ {
|
|
243
|
+ NSString *badgeColor = actionParams[@"badgeColor"];
|
|
244
|
+ UIColor *color = badgeColor != (id)[NSNull null] ? [RCTConvert UIColor:badgeColor] : nil;
|
|
245
|
+
|
|
246
|
+ if ([viewController.tabBarItem respondsToSelector:@selector(badgeColor)]) {
|
|
247
|
+ viewController.tabBarItem.badgeColor = color;
|
|
248
|
+ }
|
|
249
|
+ viewController.tabBarItem.badgeValue = [NSString stringWithFormat:@"%@", badge];
|
|
250
|
+ }
|
|
251
|
+ }
|
254
|
252
|
}
|
255
|
253
|
|
256
|
|
- if (viewController)
|
257
|
|
- {
|
258
|
|
- NSObject *badge = actionParams[@"badge"];
|
259
|
|
-
|
260
|
|
- if (badge == nil || [badge isEqual:[NSNull null]])
|
261
|
|
- {
|
262
|
|
- viewController.tabBarItem.badgeValue = nil;
|
263
|
|
- }
|
264
|
|
- else
|
265
|
|
- {
|
266
|
|
- NSString *badgeColor = actionParams[@"badgeColor"];
|
267
|
|
- UIColor *color = badgeColor != (id)[NSNull null] ? [RCTConvert UIColor:badgeColor] : nil;
|
|
254
|
+ if ([performAction isEqualToString:@"switchTo"]) {
|
|
255
|
+ UIViewController *viewController = nil;
|
|
256
|
+ NSNumber *tabIndex = actionParams[@"tabIndex"];
|
|
257
|
+ if (tabIndex) {
|
|
258
|
+ int i = (int)[tabIndex integerValue];
|
|
259
|
+
|
|
260
|
+ if ([self.viewControllers count] > i) {
|
|
261
|
+ viewController = [self.viewControllers objectAtIndex:i];
|
|
262
|
+ }
|
|
263
|
+ }
|
|
264
|
+ NSString *contentId = actionParams[@"contentId"];
|
|
265
|
+ NSString *contentType = actionParams[@"contentType"];
|
|
266
|
+ if (contentId && contentType) {
|
|
267
|
+ viewController = [[RCCManager sharedInstance] getControllerWithId:contentId componentType:contentType];
|
|
268
|
+ }
|
268
|
269
|
|
269
|
|
- if ([viewController.tabBarItem respondsToSelector:@selector(badgeColor)]) {
|
270
|
|
- viewController.tabBarItem.badgeColor = color;
|
|
270
|
+ if (viewController) {
|
|
271
|
+ [self setSelectedViewController:viewController];
|
271
|
272
|
}
|
272
|
|
- viewController.tabBarItem.badgeValue = [NSString stringWithFormat:@"%@", badge];
|
273
|
|
- }
|
274
|
|
- }
|
275
|
|
- }
|
276
|
|
-
|
277
|
|
- if ([performAction isEqualToString:@"switchTo"])
|
278
|
|
- {
|
279
|
|
- UIViewController *viewController = nil;
|
280
|
|
- NSNumber *tabIndex = actionParams[@"tabIndex"];
|
281
|
|
- if (tabIndex)
|
282
|
|
- {
|
283
|
|
- int i = (int)[tabIndex integerValue];
|
284
|
|
-
|
285
|
|
- if ([self.viewControllers count] > i)
|
286
|
|
- {
|
287
|
|
- viewController = [self.viewControllers objectAtIndex:i];
|
288
|
|
- }
|
289
|
|
- }
|
290
|
|
- NSString *contentId = actionParams[@"contentId"];
|
291
|
|
- NSString *contentType = actionParams[@"contentType"];
|
292
|
|
- if (contentId && contentType)
|
293
|
|
- {
|
294
|
|
- viewController = [[RCCManager sharedInstance] getControllerWithId:contentId componentType:contentType];
|
295
|
273
|
}
|
296
|
274
|
|
297
|
|
- if (viewController)
|
298
|
|
- {
|
299
|
|
- [self setSelectedViewController:viewController];
|
300
|
|
- }
|
301
|
|
- }
|
302
|
|
-
|
303
|
|
- if ([performAction isEqualToString:@"setTabButton"])
|
304
|
|
- {
|
305
|
|
- UIViewController *viewController = nil;
|
306
|
|
- NSNumber *tabIndex = actionParams[@"tabIndex"];
|
307
|
|
- if (tabIndex)
|
308
|
|
- {
|
309
|
|
- int i = (int)[tabIndex integerValue];
|
310
|
|
-
|
311
|
|
- if ([self.viewControllers count] > i)
|
312
|
|
- {
|
313
|
|
- viewController = [self.viewControllers objectAtIndex:i];
|
314
|
|
- }
|
315
|
|
- }
|
316
|
|
- NSString *contentId = actionParams[@"contentId"];
|
317
|
|
- NSString *contentType = actionParams[@"contentType"];
|
318
|
|
- if (contentId && contentType)
|
319
|
|
- {
|
320
|
|
- viewController = [[RCCManager sharedInstance] getControllerWithId:contentId componentType:contentType];
|
|
275
|
+ if ([performAction isEqualToString:@"setTabButton"]) {
|
|
276
|
+ UIViewController *viewController = nil;
|
|
277
|
+ NSNumber *tabIndex = actionParams[@"tabIndex"];
|
|
278
|
+ if (tabIndex) {
|
|
279
|
+ int i = (int)[tabIndex integerValue];
|
|
280
|
+
|
|
281
|
+ if ([self.viewControllers count] > i) {
|
|
282
|
+ viewController = [self.viewControllers objectAtIndex:i];
|
|
283
|
+ }
|
|
284
|
+ }
|
|
285
|
+ NSString *contentId = actionParams[@"contentId"];
|
|
286
|
+ NSString *contentType = actionParams[@"contentType"];
|
|
287
|
+ if (contentId && contentType) {
|
|
288
|
+ viewController = [[RCCManager sharedInstance] getControllerWithId:contentId componentType:contentType];
|
|
289
|
+ }
|
|
290
|
+
|
|
291
|
+ if (viewController) {
|
|
292
|
+ UIImage *iconImage = nil;
|
|
293
|
+ id icon = actionParams[@"icon"];
|
|
294
|
+ if (icon && icon != (id)[NSNull null]) {
|
|
295
|
+ iconImage = [RCTConvert UIImage:icon];
|
|
296
|
+ iconImage = [[self image:iconImage withColor:self.tabBar.tintColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
|
297
|
+ viewController.tabBarItem.image = iconImage;
|
|
298
|
+ }
|
|
299
|
+
|
|
300
|
+ UIImage *iconImageSelected = nil;
|
|
301
|
+ id selectedIcon = actionParams[@"selectedIcon"];
|
|
302
|
+ if (selectedIcon && selectedIcon != (id)[NSNull null]) {
|
|
303
|
+ iconImageSelected = [RCTConvert UIImage:selectedIcon];
|
|
304
|
+ viewController.tabBarItem.selectedImage = iconImageSelected;
|
|
305
|
+ }
|
|
306
|
+
|
|
307
|
+ id label = actionParams[@"label"];
|
|
308
|
+ if (label && label != (id)[NSNull null]) {
|
|
309
|
+ viewController.tabBarItem.title = label;
|
|
310
|
+ }
|
|
311
|
+ }
|
321
|
312
|
}
|
322
|
313
|
|
323
|
|
- if (viewController)
|
324
|
|
- {
|
325
|
|
- UIImage *iconImage = nil;
|
326
|
|
- id icon = actionParams[@"icon"];
|
327
|
|
- if (icon && icon != (id)[NSNull null])
|
328
|
|
- {
|
329
|
|
- iconImage = [RCTConvert UIImage:icon];
|
330
|
|
- iconImage = [[self image:iconImage withColor:self.tabBar.tintColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
331
|
|
- viewController.tabBarItem.image = iconImage;
|
332
|
|
- }
|
333
|
|
-
|
334
|
|
- UIImage *iconImageSelected = nil;
|
335
|
|
- id selectedIcon = actionParams[@"selectedIcon"];
|
336
|
|
- if (selectedIcon && selectedIcon != (id)[NSNull null])
|
337
|
|
- {
|
338
|
|
- iconImageSelected = [RCTConvert UIImage:selectedIcon];
|
339
|
|
- viewController.tabBarItem.selectedImage = iconImageSelected;
|
340
|
|
- }
|
341
|
|
-
|
342
|
|
- id label = actionParams[@"label"];
|
343
|
|
- if (label && label != (id)[NSNull null])
|
344
|
|
- {
|
345
|
|
- viewController.tabBarItem.title = label;
|
346
|
|
- }
|
|
314
|
+ if ([performAction isEqualToString:@"setTabBarHidden"]) {
|
|
315
|
+ BOOL hidden = [actionParams[@"hidden"] boolValue];
|
|
316
|
+ self.tabBarHidden = hidden;
|
|
317
|
+
|
|
318
|
+ CGRect nextFrame = self.tabBar.frame;
|
|
319
|
+ nextFrame.origin.y = UIScreen.mainScreen.bounds.size.height - (hidden ? 0 : self.tabBar.frame.size.height);
|
|
320
|
+
|
|
321
|
+ [UIView animateWithDuration: ([actionParams[@"animated"] boolValue] ? 0.45 : 0)
|
|
322
|
+ delay: 0
|
|
323
|
+ usingSpringWithDamping: 0.75
|
|
324
|
+ initialSpringVelocity: 0
|
|
325
|
+ options: (hidden ? UIViewAnimationOptionCurveEaseIn : UIViewAnimationOptionCurveEaseOut)
|
|
326
|
+ animations:^()
|
|
327
|
+ {
|
|
328
|
+ [self.tabBar setFrame:nextFrame];
|
|
329
|
+ }
|
|
330
|
+ completion:^(BOOL finished)
|
|
331
|
+ {
|
|
332
|
+ if (completion != nil) {
|
|
333
|
+ completion();
|
|
334
|
+ }
|
|
335
|
+ }];
|
|
336
|
+ return;
|
|
337
|
+ } else if (completion != nil) {
|
|
338
|
+ completion();
|
347
|
339
|
}
|
348
|
|
- }
|
349
|
|
-
|
350
|
|
- if ([performAction isEqualToString:@"setTabBarHidden"])
|
351
|
|
- {
|
352
|
|
- BOOL hidden = [actionParams[@"hidden"] boolValue];
|
353
|
|
- self.tabBarHidden = hidden;
|
354
|
|
-
|
355
|
|
- CGRect nextFrame = self.tabBar.frame;
|
356
|
|
- nextFrame.origin.y = UIScreen.mainScreen.bounds.size.height - (hidden ? 0 : self.tabBar.frame.size.height);
|
357
|
|
-
|
358
|
|
- [UIView animateWithDuration: ([actionParams[@"animated"] boolValue] ? 0.45 : 0)
|
359
|
|
- delay: 0
|
360
|
|
- usingSpringWithDamping: 0.75
|
361
|
|
- initialSpringVelocity: 0
|
362
|
|
- options: (hidden ? UIViewAnimationOptionCurveEaseIn : UIViewAnimationOptionCurveEaseOut)
|
363
|
|
- animations:^()
|
364
|
|
- {
|
365
|
|
- [self.tabBar setFrame:nextFrame];
|
366
|
|
- }
|
367
|
|
- completion:^(BOOL finished)
|
368
|
|
- {
|
369
|
|
- if (completion != nil)
|
370
|
|
- {
|
371
|
|
- completion();
|
372
|
|
- }
|
373
|
|
- }];
|
374
|
|
- return;
|
375
|
|
- }
|
376
|
|
- else if (completion != nil)
|
377
|
|
- {
|
378
|
|
- completion();
|
379
|
|
- }
|
380
|
340
|
}
|
381
|
341
|
|
382
|
342
|
+(void)sendScreenTabChangedEvent:(UIViewController*)viewController body:(NSDictionary*)body{
|
383
|
|
- [RCCTabBarController sendTabEvent:@"bottomTabSelected" controller:viewController body:body];
|
|
343
|
+ [RCCTabBarController sendTabEvent:@"bottomTabSelected" controller:viewController body:body];
|
384
|
344
|
}
|
385
|
345
|
|
386
|
346
|
+(void)sendScreenTabPressedEvent:(UIViewController*)viewController body:(NSDictionary*)body{
|
387
|
|
- [RCCTabBarController sendTabEvent:@"bottomTabReselected" controller:viewController body:body];
|
|
347
|
+ [RCCTabBarController sendTabEvent:@"bottomTabReselected" controller:viewController body:body];
|
388
|
348
|
}
|
389
|
349
|
|
390
|
350
|
+(void)sendTabEvent:(NSString *)event controller:(UIViewController*)viewController body:(NSDictionary*)body{
|
391
|
|
- if ([viewController.view isKindOfClass:[RCTRootView class]]){
|
392
|
|
- RCTRootView *rootView = (RCTRootView *)viewController.view;
|
|
351
|
+ if ([viewController.view isKindOfClass:[RCTRootView class]]){
|
|
352
|
+ RCTRootView *rootView = (RCTRootView *)viewController.view;
|
|
353
|
+
|
|
354
|
+ if (rootView.appProperties && rootView.appProperties[@"navigatorEventID"]) {
|
|
355
|
+ NSString *navigatorID = rootView.appProperties[@"navigatorID"];
|
|
356
|
+ NSString *screenInstanceID = rootView.appProperties[@"screenInstanceID"];
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+ NSMutableDictionary *screenDict = [NSMutableDictionary dictionaryWithDictionary:@
|
|
360
|
+ {
|
|
361
|
+ @"id": event,
|
|
362
|
+ @"navigatorID": navigatorID,
|
|
363
|
+ @"screenInstanceID": screenInstanceID
|
|
364
|
+ }];
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+ if (body) {
|
|
368
|
+ [screenDict addEntriesFromDictionary:body];
|
|
369
|
+ }
|
|
370
|
+
|
|
371
|
+ [[[RCCManager sharedInstance] getBridge].eventDispatcher sendAppEventWithName:rootView.appProperties[@"navigatorEventID"] body:screenDict];
|
|
372
|
+ }
|
|
373
|
+ }
|
393
|
374
|
|
394
|
|
- if (rootView.appProperties && rootView.appProperties[@"navigatorEventID"]) {
|
395
|
|
- NSString *navigatorID = rootView.appProperties[@"navigatorID"];
|
396
|
|
- NSString *screenInstanceID = rootView.appProperties[@"screenInstanceID"];
|
397
|
|
-
|
398
|
|
-
|
399
|
|
- NSMutableDictionary *screenDict = [NSMutableDictionary dictionaryWithDictionary:@
|
400
|
|
- {
|
401
|
|
- @"id": event,
|
402
|
|
- @"navigatorID": navigatorID,
|
403
|
|
- @"screenInstanceID": screenInstanceID
|
404
|
|
- }];
|
405
|
|
-
|
406
|
|
-
|
407
|
|
- if (body) {
|
408
|
|
- [screenDict addEntriesFromDictionary:body];
|
409
|
|
- }
|
410
|
|
-
|
411
|
|
- [[[RCCManager sharedInstance] getBridge].eventDispatcher sendAppEventWithName:rootView.appProperties[@"navigatorEventID"] body:screenDict];
|
|
375
|
+ if ([viewController isKindOfClass:[UINavigationController class]]) {
|
|
376
|
+ UINavigationController *navigationController = (UINavigationController*)viewController;
|
|
377
|
+ UIViewController *topViewController = [navigationController topViewController];
|
|
378
|
+ [RCCTabBarController sendTabEvent:event controller:topViewController body:body];
|
412
|
379
|
}
|
413
|
|
- }
|
414
|
|
-
|
415
|
|
- if ([viewController isKindOfClass:[UINavigationController class]]) {
|
416
|
|
- UINavigationController *navigationController = (UINavigationController*)viewController;
|
417
|
|
- UIViewController *topViewController = [navigationController topViewController];
|
418
|
|
- [RCCTabBarController sendTabEvent:event controller:topViewController body:body];
|
419
|
|
- }
|
420
|
380
|
}
|
421
|
381
|
|
422
|
382
|
|