Browse Source

Reject promise if push fails

Guy Carmeli 7 years ago
parent
commit
edd1dddc71

+ 12
- 3
android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java View File

@@ -383,7 +383,7 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
383 383
                     EventBus.instance.post(new ScreenChangedEvent(params));
384 384
                 }
385 385
             }
386
-        });
386
+        }, onPushComplete);
387 387
     }
388 388
 
389 389
     @Override
@@ -445,13 +445,22 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
445 445
     }
446 446
 
447 447
     private void performOnStack(String navigatorId, Task<ScreenStack> task) {
448
+        performOnStack(navigatorId, task, null);
449
+    }
450
+
451
+    private void performOnStack(String navigatorId, Task<ScreenStack> task, @Nullable Promise onPushComplete) {
448 452
         try {
449 453
             ScreenStack screenStack = getScreenStack(navigatorId);
450 454
             task.run(screenStack);
451 455
         } catch (ScreenStackNotFoundException e) {
456
+            if (onPushComplete != null) {
457
+                onPushComplete.reject("Navigation", "Could not perform action on stack [" + navigatorId + "]." +
458
+                                                    "This should not have happened, it probably means a navigator action" +
459
+                                                    "was called from an unmounted tab.");
460
+            }
452 461
             Log.e("Navigation", "Could not perform action on stack [" + navigatorId + "]." +
453
-                                      "This should not have happened, it probably means a navigator action" +
454
-                                      "was called from an unmounted tab.");
462
+                                "This should not have happened, it probably means a navigator action" +
463
+                                "was called from an unmounted tab.");
455 464
         }
456 465
     }
457 466