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,6 +317,7 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
317 317
     @Override
318 318
     public boolean onTabSelected(int position, boolean wasSelected) {
319 319
         if (wasSelected) {
320
+            sendTabReselectedEventToJs();
320 321
             return false;
321 322
         }
322 323
         
@@ -333,6 +334,12 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
333 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 343
     private void showNewStack(int position) {
337 344
         showStackAndUpdateStyle(screenStacks[position]);
338 345
         currentStackIndex = position;

+ 12
- 3
ios/RCCTabBarController.m View File

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