Преглед на файлове

Address possible NPE in detachView and attachView

Guy Carmeli преди 6 години
родител
ревизия
f2f5eaf2d4
променени са 1 файла, в които са добавени 4 реда и са изтрити 2 реда
  1. 4
    2
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ViewController.java

+ 4
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ViewController.java Целия файл

@@ -51,7 +51,7 @@ public abstract class ViewController<T extends ViewGroup> implements ViewTreeObs
51 51
     private final Activity activity;
52 52
     private final String id;
53 53
     private YellowBoxDelegate yellowBoxDelegate;
54
-    protected T view;
54
+    @Nullable protected T view;
55 55
     @Nullable private ParentController<T> parentController;
56 56
     private boolean isShown;
57 57
     private boolean isDestroyed;
@@ -164,10 +164,12 @@ public abstract class ViewController<T extends ViewGroup> implements ViewTreeObs
164 164
     }
165 165
 
166 166
     public void detachView() {
167
+        if (view == null || view.getParent() == null) return;
167 168
         ((ViewManager) view.getParent()).removeView(view);
168 169
     }
169 170
 
170 171
     public void attachView(ViewGroup parent, int index) {
172
+        if (view == null) return;
171 173
         if (view.getParent() == null) parent.addView(view, index);
172 174
     }
173 175
 
@@ -294,6 +296,6 @@ public abstract class ViewController<T extends ViewGroup> implements ViewTreeObs
294 296
     }
295 297
 
296 298
     public List<Element> getElements() {
297
-        return getView() instanceof IReactView ? ((IReactView) view).getElements() : Collections.EMPTY_LIST;
299
+        return getView() instanceof IReactView && view != null? ((IReactView) view).getElements() : Collections.EMPTY_LIST;
298 300
     }
299 301
 }