Browse Source

Added 'bottomTabPressed' navigation event (#955)

* Added an additional navigation event for the press of an already selected tab

* Renamed new navigation event to bottomTabReselected
Aiden Montgomery 7 years ago
parent
commit
6c9a3eaf01

+ 7
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java View File

317
     @Override
317
     @Override
318
     public boolean onTabSelected(int position, boolean wasSelected) {
318
     public boolean onTabSelected(int position, boolean wasSelected) {
319
         if (wasSelected) {
319
         if (wasSelected) {
320
+            sendTabReselectedEventToJs();
320
             return false;
321
             return false;
321
         }
322
         }
322
         
323
         
333
         NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("bottomTabSelected", navigatorEventId, data);
334
         NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("bottomTabSelected", navigatorEventId, data);
334
     }
335
     }
335
 
336
 
337
+    private void sendTabReselectedEventToJs() {
338
+        WritableMap data = Arguments.createMap();
339
+        String navigatorEventId = getCurrentScreenStack().peek().getNavigatorEventId();
340
+        NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("bottomTabReselected", navigatorEventId, data);
341
+    }
342
+
336
     private void showNewStack(int position) {
343
     private void showNewStack(int position) {
337
         showStackAndUpdateStyle(screenStacks[position]);
344
         showStackAndUpdateStyle(screenStacks[position]);
338
         currentStackIndex = position;
345
         currentStackIndex = position;

+ 12
- 3
ios/RCCTabBarController.m View File

29
   
29
   
30
   if (tabBarController.selectedIndex != [tabBarController.viewControllers indexOfObject:viewController]) {
30
   if (tabBarController.selectedIndex != [tabBarController.viewControllers indexOfObject:viewController]) {
31
     [RCCTabBarController sendScreenTabChangedEvent:viewController];
31
     [RCCTabBarController sendScreenTabChangedEvent:viewController];
32
+  } else {
33
+    [RCCTabBarController sendScreenTabPressedEvent:viewController];
32
   }
34
   }
33
 
35
 
34
   return YES;
36
   return YES;
257
 }
259
 }
258
 
260
 
259
 +(void)sendScreenTabChangedEvent:(UIViewController*)viewController {
261
 +(void)sendScreenTabChangedEvent:(UIViewController*)viewController {
262
+  [RCCTabBarController sendTabEvent:@"bottomTabSelected" controller:viewController];
263
+}
264
+
265
++(void)sendScreenTabPressedEvent:(UIViewController*)viewController {
266
+  [RCCTabBarController sendTabEvent:@"bottomTabReselected" controller:viewController];
267
+}
268
+
269
++(void)sendTabEvent:(NSString *)event controller:(UIViewController*)viewController {
260
   if ([viewController.view isKindOfClass:[RCTRootView class]]){
270
   if ([viewController.view isKindOfClass:[RCTRootView class]]){
261
     RCTRootView *rootView = (RCTRootView *)viewController.view;
271
     RCTRootView *rootView = (RCTRootView *)viewController.view;
262
     
272
     
266
       
276
       
267
       [[[RCCManager sharedInstance] getBridge].eventDispatcher sendAppEventWithName:rootView.appProperties[@"navigatorEventID"] body:@
277
       [[[RCCManager sharedInstance] getBridge].eventDispatcher sendAppEventWithName:rootView.appProperties[@"navigatorEventID"] body:@
268
        {
278
        {
269
-         @"id": @"bottomTabSelected",
279
+         @"id": event,
270
          @"navigatorID": navigatorID,
280
          @"navigatorID": navigatorID,
271
          @"screenInstanceID": screenInstanceID
281
          @"screenInstanceID": screenInstanceID
272
        }];
282
        }];
276
   if ([viewController isKindOfClass:[UINavigationController class]]) {
286
   if ([viewController isKindOfClass:[UINavigationController class]]) {
277
     UINavigationController *navigationController = (UINavigationController*)viewController;
287
     UINavigationController *navigationController = (UINavigationController*)viewController;
278
     UIViewController *topViewController = [navigationController topViewController];
288
     UIViewController *topViewController = [navigationController topViewController];
279
-    [RCCTabBarController sendScreenTabChangedEvent:topViewController];
289
+    [RCCTabBarController sendTabEvent:event controller:topViewController];
280
   }
290
   }
281
 }
291
 }
282
 
292
 
283
-
284
 @end
293
 @end