Browse Source

Address possible NPE in detachView and attachView

Guy Carmeli 5 years ago
parent
commit
f2f5eaf2d4

+ 4
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ViewController.java View File

51
     private final Activity activity;
51
     private final Activity activity;
52
     private final String id;
52
     private final String id;
53
     private YellowBoxDelegate yellowBoxDelegate;
53
     private YellowBoxDelegate yellowBoxDelegate;
54
-    protected T view;
54
+    @Nullable protected T view;
55
     @Nullable private ParentController<T> parentController;
55
     @Nullable private ParentController<T> parentController;
56
     private boolean isShown;
56
     private boolean isShown;
57
     private boolean isDestroyed;
57
     private boolean isDestroyed;
164
     }
164
     }
165
 
165
 
166
     public void detachView() {
166
     public void detachView() {
167
+        if (view == null || view.getParent() == null) return;
167
         ((ViewManager) view.getParent()).removeView(view);
168
         ((ViewManager) view.getParent()).removeView(view);
168
     }
169
     }
169
 
170
 
170
     public void attachView(ViewGroup parent, int index) {
171
     public void attachView(ViewGroup parent, int index) {
172
+        if (view == null) return;
171
         if (view.getParent() == null) parent.addView(view, index);
173
         if (view.getParent() == null) parent.addView(view, index);
172
     }
174
     }
173
 
175
 
294
     }
296
     }
295
 
297
 
296
     public List<Element> getElements() {
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
 }