Browse Source

Add NPE check when setting back button

Guy Carmeli 8 years ago
parent
commit
ea4ed29b3c

+ 3
- 1
android/app/src/main/java/com/reactnativenavigation/utils/ContextProvider.java View File

1
 package com.reactnativenavigation.utils;
1
 package com.reactnativenavigation.utils;
2
 
2
 
3
+import android.support.annotation.Nullable;
4
+
3
 import com.reactnativenavigation.activities.BaseReactActivity;
5
 import com.reactnativenavigation.activities.BaseReactActivity;
4
 
6
 
5
 import java.lang.ref.WeakReference;
7
 import java.lang.ref.WeakReference;
19
     /**
21
     /**
20
      * Returns the currently resumed activity or {@code null} if there is none.
22
      * Returns the currently resumed activity or {@code null} if there is none.
21
      */
23
      */
22
-    public static BaseReactActivity getActivityContext() {
24
+    public static @Nullable BaseReactActivity getActivityContext() {
23
         return sActivityWR != null ? sActivityWR.get() : null;
25
         return sActivityWR != null ? sActivityWR.get() : null;
24
     }
26
     }
25
 
27
 

+ 7
- 2
android/app/src/main/java/com/reactnativenavigation/views/RnnToolBar.java View File

212
 
212
 
213
     @SuppressWarnings({"ConstantConditions"})
213
     @SuppressWarnings({"ConstantConditions"})
214
     public void setNavUpButton(Screen screen) {
214
     public void setNavUpButton(Screen screen) {
215
-        ActionBar actionBar = ContextProvider.getActivityContext().getSupportActionBar();
215
+        BaseReactActivity context = ContextProvider.getActivityContext();
216
+        if (context == null) {
217
+            return;
218
+        }
219
+
220
+        ActionBar actionBar = context.getSupportActionBar();
216
         if (actionBar == null) {
221
         if (actionBar == null) {
217
             return;
222
             return;
218
         }
223
         }
226
             navArrow = (DrawerArrowDrawable) this.getNavigationIcon();
231
             navArrow = (DrawerArrowDrawable) this.getNavigationIcon();
227
         } else {
232
         } else {
228
             if (isBack && !screen.backButtonHidden) {
233
             if (isBack && !screen.backButtonHidden) {
229
-                navArrow = new DrawerArrowDrawable(ContextProvider.getActivityContext());
234
+                navArrow = new DrawerArrowDrawable(context);
230
             } else if (hasDrawer) {
235
             } else if (hasDrawer) {
231
                 navIcon = mDrawerIcon;
236
                 navIcon = mDrawerIcon;
232
             }
237
             }