소스 검색

Revert "Support a “modal” prop for tabbed iOS apps (#1578)"

This reverts commit 5cd2972ca0.
yogevbd 6 년 전
부모
커밋
771e906973
2개의 변경된 파일81개의 추가작업 그리고 164개의 파일을 삭제
  1. 1
    2
      docs/top-level-api.md
  2. 80
    162
      ios/RCCTabBarController.m

+ 1
- 2
docs/top-level-api.md 파일 보기

@@ -44,8 +44,7 @@ Navigation.startTabBasedApp({
44 44
       title: 'Screen One', // title of the screen as appears in the nav bar (optional)
45 45
       titleImage: require('../img/titleImage.png'), // iOS only. navigation bar title image instead of the title text of the pushed screen (optional)
46 46
       navigatorStyle: {}, // override the navigator style for the tab screen, see "Styling the navigator" below (optional),
47
-      navigatorButtons: {}, // override the nav buttons for the tab screen, see "Adding buttons to the navigator" below (optional)
48
-      modal: false // Prevent tab selection and send a 'modalTabSelected' navigator event instead (optional, iOS only)
47
+      navigatorButtons: {} // override the nav buttons for the tab screen, see "Adding buttons to the navigator" below (optional)
49 48
     },
50 49
     {
51 50
       label: 'Two',

+ 80
- 162
ios/RCCTabBarController.m 파일 보기

@@ -14,12 +14,6 @@
14 14
 
15 15
 @end
16 16
 
17
-@interface RCCTabBarController ()
18
-
19
-@property (nonatomic, strong) NSSet *modalTabIndices;
20
-
21
-@end
22
-
23 17
 @implementation RCCTabBarController
24 18
 
25 19
 
@@ -28,47 +22,37 @@
28 22
 }
29 23
 
30 24
 - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
31
-  id queue = [[RCCManager sharedInstance].getBridge uiManager].methodQueue;
32
-  dispatch_async(queue, ^{
33
-    [[[RCCManager sharedInstance].getBridge uiManager] configureNextLayoutAnimation:nil withCallback:^(NSArray* arr){} errorCallback:^(NSArray* arr){}];
34
-  });
35
-
36
-  NSUInteger selectedIndex = [tabBarController.viewControllers indexOfObject:viewController];
37
-  
38
-  if (tabBarController.selectedIndex != selectedIndex) {
39
-    NSDictionary *body = @{
40
-                           @"selectedTabIndex": @(selectedIndex),
41
-                           @"unselectedTabIndex": @(tabBarController.selectedIndex)
42
-                           };
43
-
44
-    if ([self.modalTabIndices containsObject:@(selectedIndex)]) {
45
-      [RCCTabBarController sendScreenTabModalEvent:viewController body:body];
46
-      return NO;
47
-    }
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
+    });
48 29
     
49
-    else {
50
-      [RCCTabBarController sendScreenTabChangedEvent:viewController body:body];
51
-
52
-      [[[RCCManager sharedInstance] getBridge].eventDispatcher sendAppEventWithName:@"bottomTabSelected" body:body];
53
-    }
54
-
55
-    if ([viewController isKindOfClass:[UINavigationController class]]) {
56
-      UINavigationController *navigationController = (UINavigationController*)viewController;
57
-      UIViewController *topViewController = navigationController.topViewController;
58
-
59
-      if ([topViewController isKindOfClass:[RCCViewController class]]) {
60
-        RCCViewController *topRCCViewController = (RCCViewController*)topViewController;
61
-        topRCCViewController.commandType = COMMAND_TYPE_BOTTOME_TAB_SELECTED;
62
-        topRCCViewController.timestamp = [RCTHelpers getTimestampString];
63
-      }
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];
64 51
     }
65
-  } else {
66
-    [RCCTabBarController sendScreenTabPressedEvent:viewController body:nil];
67
-  }
68
-  
69
-  
70
-  
71
-  return YES;
52
+    
53
+    
54
+    
55
+    return YES;
72 56
 }
73 57
 
74 58
 - (UIImage *)image:(UIImage*)image withColor:(UIColor *)color1 {
@@ -86,105 +70,59 @@
86 70
     return newImage;
87 71
 }
88 72
 
89
-- (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children globalProps:(NSDictionary*)globalProps bridge:(RCTBridge *)bridge
90
-{
91
-  self = [super init];
92
-  if (!self) return nil;
93
-  
94
-  self.delegate = self;
95
-  
96
-  self.tabBar.translucent = YES; // default
97
-  
98
-  UIColor *buttonColor = nil;
99
-  UIColor *selectedButtonColor = nil;
100
-  UIColor *labelColor = nil;
101
-  UIColor *selectedLabelColor = nil;
102
-  NSDictionary *tabsStyle = props[@"style"];
103
-  if (tabsStyle)
104
-  {
105
-    NSString *tabBarButtonColor = tabsStyle[@"tabBarButtonColor"];
106
-    if (tabBarButtonColor)
107
-    {
108
-      UIColor *color = tabBarButtonColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarButtonColor] : nil;
109
-      self.tabBar.tintColor = color;
110
-      buttonColor = color;
111
-      selectedButtonColor = color;
112
-    }
113
-    NSString *tabBarSelectedButtonColor = tabsStyle[@"tabBarSelectedButtonColor"];
114
-    if (tabBarSelectedButtonColor)
115
-    {
116
-      UIColor *color = tabBarSelectedButtonColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarSelectedButtonColor] : nil;
117
-      self.tabBar.tintColor = color;
118
-      selectedButtonColor = color;
119
-    }
120
-    NSString *tabBarLabelColor = tabsStyle[@"tabBarLabelColor"];
121
-    if(tabBarLabelColor) {
122
-      UIColor *color = tabBarLabelColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarLabelColor] : nil;
123
-      labelColor = color;
124
-    }
125
-    NSString *tabBarSelectedLabelColor = tabsStyle[@"tabBarSelectedLabelColor"];
126
-    if(tabBarLabelColor) {
127
-      UIColor *color = tabBarSelectedLabelColor != (id)[NSNull null] ? [RCTConvert UIColor:
128
-                                                                        tabBarSelectedLabelColor] : nil;
129
-      selectedLabelColor = color;
130
-    }
131
-    NSString *tabBarBackgroundColor = tabsStyle[@"tabBarBackgroundColor"];
132
-    if (tabBarBackgroundColor)
133
-    {
134
-      UIColor *color = tabBarBackgroundColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarBackgroundColor] : nil;
135
-      self.tabBar.barTintColor = color;
136
-    }
137
-
138
-    NSString *tabBarTranslucent = tabsStyle[@"tabBarTranslucent"];
139
-    if (tabBarTranslucent)
140
-    {
141
-      self.tabBar.translucent = [tabBarTranslucent boolValue] ? YES : NO;
142
-    }
143
-
144
-    NSString *tabBarHideShadow = tabsStyle[@"tabBarHideShadow"];
145
-    if (tabBarHideShadow)
146
-    {
147
-      self.tabBar.clipsToBounds = [tabBarHideShadow boolValue] ? YES : NO;
148
-    }
149
-  }
150
-  
151
-  NSMutableArray *viewControllers = [NSMutableArray array];
152
-  NSMutableSet *modalTabs = [NSMutableSet new];
153
-  
154
-  // go over all the tab bar items
155
-  for (NSDictionary *tabItemLayout in children)
156
-  {
157
-    // make sure the layout is valid
158
-    if (![tabItemLayout[@"type"] isEqualToString:@"TabBarControllerIOS.Item"]) continue;
159
-    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;
160 76
     
161 77
     self.delegate = self;
162 78
     
163
-    // create the tab icon and title
164
-    NSString *title = tabItemLayout[@"props"][@"title"];
165
-    id isModal = tabItemLayout[@"props"][@"modal"];
166
-    if (isModal && isModal != (id)[NSNull null]) {
167
-      BOOL isModalBool = [RCTConvert BOOL:isModal];
168
-      if (isModalBool) {
169
-        [modalTabs addObject:@([viewControllers count])];
170
-      }
171
-    }
172
-    UIImage *iconImage = nil;
173
-    id icon = tabItemLayout[@"props"][@"icon"];
174
-    if (icon)
175
-    {
176
-      iconImage = [RCTConvert UIImage:icon];
177
-      if (buttonColor)
178
-      {
179
-        iconImage = [[self image:iconImage withColor:buttonColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
180
-      }
181
-    }
182
-    UIImage *iconImageSelected = nil;
183
-    id selectedIcon = tabItemLayout[@"props"][@"selectedIcon"];
184
-    if (selectedIcon) {
185
-      iconImageSelected = [RCTConvert UIImage:selectedIcon];
186
-    } else {
187
-      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
+        }
188 126
     }
189 127
     
190 128
     NSMutableArray *viewControllers = [NSMutableArray array];
@@ -274,23 +212,7 @@
274 212
     
275 213
     [self setRotation:props];
276 214
     
277
-    [viewControllers addObject:viewController];
278
-  }
279
-  
280
-  // replace the tabs
281
-  self.viewControllers = viewControllers;
282
-  self.modalTabIndices = [modalTabs copy];
283
-
284
-  NSNumber *initialTab = tabsStyle[@"initialTabIndex"];
285
-  if (initialTab)
286
-  {
287
-    NSInteger initialTabIndex = initialTab.integerValue;
288
-    [self setSelectedIndex:initialTabIndex];
289
-  }
290
-  
291
-  [self setRotation:props];
292
-  
293
-  return self;
215
+    return self;
294 216
 }
295 217
 
296 218
 - (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actionParams bridge:(RCTBridge *)bridge completion:(void (^)(void))completion {
@@ -425,10 +347,6 @@
425 347
     [RCCTabBarController sendTabEvent:@"bottomTabReselected" controller:viewController body:body];
426 348
 }
427 349
 
428
-+(void)sendScreenTabModalEvent:(UIViewController*)viewController body:(NSDictionary*)body{
429
-  [RCCTabBarController sendTabEvent:@"modalTabSelected" controller:viewController body:body];
430
-}
431
-
432 350
 +(void)sendTabEvent:(NSString *)event controller:(UIViewController*)viewController body:(NSDictionary*)body{
433 351
     if ([viewController.view isKindOfClass:[RCTRootView class]]){
434 352
         RCTRootView *rootView = (RCTRootView *)viewController.view;