Browse Source

added tab selected event (#605)

* added tab selected event

* changed event name to `bottomTabSelected`
Ran 7 years ago
parent
commit
762b6d3056
1 changed files with 27 additions and 0 deletions
  1. 27
    0
      ios/RCCTabBarController.m

+ 27
- 0
ios/RCCTabBarController.m View File

@@ -20,6 +20,8 @@
20 20
     [[[RCCManager sharedInstance].getBridge uiManager] configureNextLayoutAnimation:nil withCallback:^(NSArray* arr){} errorCallback:^(NSArray* arr){}];
21 21
   });
22 22
   
23
+  [RCCTabBarController sendScreenTabChangedEvent:viewController];
24
+  
23 25
   return YES;
24 26
 }
25 27
 
@@ -237,4 +239,29 @@
237 239
     }
238 240
 }
239 241
 
242
++(void)sendScreenTabChangedEvent:(UIViewController*)viewController {
243
+  if ([viewController.view isKindOfClass:[RCTRootView class]]){
244
+    RCTRootView *rootView = (RCTRootView *)viewController.view;
245
+    
246
+    if (rootView.appProperties && rootView.appProperties[@"navigatorEventID"]) {
247
+      NSString *navigatorID = rootView.appProperties[@"navigatorID"];
248
+      NSString *screenInstanceID = rootView.appProperties[@"screenInstanceID"];
249
+      
250
+      [[[RCCManager sharedInstance] getBridge].eventDispatcher sendAppEventWithName:rootView.appProperties[@"navigatorEventID"] body:@
251
+       {
252
+         @"id": @"bottomTabSelected",
253
+         @"navigatorID": navigatorID,
254
+         @"screenInstanceID": screenInstanceID
255
+       }];
256
+    }
257
+  }
258
+  
259
+  if ([viewController isKindOfClass:[UINavigationController class]]) {
260
+    UINavigationController *navigationController = (UINavigationController*)viewController;
261
+    UIViewController *topViewController = [navigationController topViewController];
262
+    [RCCTabBarController sendScreenTabChangedEvent:topViewController];
263
+  }
264
+}
265
+
266
+
240 267
 @end