Browse Source

Handle back only if root exists (#3791)

This commit fixes a crash when hardware back button was pressed before root was set.
Guy Carmeli 6 years ago
parent
commit
ac10df86fd
No account linked to committer's email address

+ 1
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/Navigator.java View File

@@ -72,6 +72,7 @@ public class Navigator extends ParentController {
72 72
 
73 73
     @Override
74 74
     public boolean handleBack(CommandListener listener) {
75
+        if (modalStack.isEmpty() && root == null) return false;
75 76
         if (modalStack.isEmpty()) return root.handleBack(listener);
76 77
         return modalStack.handleBack(listener, root);
77 78
     }

+ 2
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java View File

@@ -279,6 +279,8 @@ public class NavigatorTest extends BaseTest {
279 279
 
280 280
     @Test
281 281
     public void handleBack_DelegatesToRoot() {
282
+        assertThat(uut.handleBack(new CommandListenerAdapter())).isFalse();
283
+
282 284
         ViewController root = spy(child1);
283 285
         uut.setRoot(root, new CommandListenerAdapter());
284 286
         when(root.handleBack(any(CommandListener.class))).thenReturn(true);