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
 
72
 
73
     @Override
73
     @Override
74
     public boolean handleBack(CommandListener listener) {
74
     public boolean handleBack(CommandListener listener) {
75
+        if (modalStack.isEmpty() && root == null) return false;
75
         if (modalStack.isEmpty()) return root.handleBack(listener);
76
         if (modalStack.isEmpty()) return root.handleBack(listener);
76
         return modalStack.handleBack(listener, root);
77
         return modalStack.handleBack(listener, root);
77
     }
78
     }

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

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