소스 검색

Handle NPE when showing Overlay before setRoot is called

Rejecting the promise is a temporary solution, Overlay should not be coupled to root.
Guy Carmeli 5 년 전
부모
커밋
e4db9e6419
1개의 변경된 파일6개의 추가작업 그리고 1개의 파일을 삭제
  1. 6
    1
      lib/android/app/src/main/java/com/reactnativenavigation/presentation/OverlayManager.java

+ 6
- 1
lib/android/app/src/main/java/com/reactnativenavigation/presentation/OverlayManager.java 파일 보기

@@ -1,5 +1,6 @@
1 1
 package com.reactnativenavigation.presentation;
2 2
 
3
+import android.support.annotation.Nullable;
3 4
 import android.view.ViewGroup;
4 5
 
5 6
 import com.reactnativenavigation.utils.CommandListener;
@@ -10,7 +11,11 @@ import java.util.HashMap;
10 11
 public class OverlayManager {
11 12
     private final HashMap<String, ViewController> overlayRegistry = new HashMap<>();
12 13
 
13
-    public void show(ViewGroup root, ViewController overlay, CommandListener listener) {
14
+    public void show(@Nullable ViewGroup root, ViewController overlay, CommandListener listener) {
15
+        if (root == null) {
16
+            listener.onError("Can't show Overlay before setRoot is called. This will be resolved in #3899");
17
+            return;
18
+        }
14 19
         overlayRegistry.put(overlay.getId(), overlay);
15 20
         overlay.setOnAppearedListener(() -> listener.onSuccess(overlay.getId()));
16 21
         root.addView(overlay.getView());