소스 검색

Add NPE check when setting back button

Guy Carmeli 8 년 전
부모
커밋
ea4ed29b3c

+ 3
- 1
android/app/src/main/java/com/reactnativenavigation/utils/ContextProvider.java 파일 보기

@@ -1,5 +1,7 @@
1 1
 package com.reactnativenavigation.utils;
2 2
 
3
+import android.support.annotation.Nullable;
4
+
3 5
 import com.reactnativenavigation.activities.BaseReactActivity;
4 6
 
5 7
 import java.lang.ref.WeakReference;
@@ -19,7 +21,7 @@ public class ContextProvider {
19 21
     /**
20 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 25
         return sActivityWR != null ? sActivityWR.get() : null;
24 26
     }
25 27
 

+ 7
- 2
android/app/src/main/java/com/reactnativenavigation/views/RnnToolBar.java 파일 보기

@@ -212,7 +212,12 @@ public class RnnToolBar extends Toolbar {
212 212
 
213 213
     @SuppressWarnings({"ConstantConditions"})
214 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 221
         if (actionBar == null) {
217 222
             return;
218 223
         }
@@ -226,7 +231,7 @@ public class RnnToolBar extends Toolbar {
226 231
             navArrow = (DrawerArrowDrawable) this.getNavigationIcon();
227 232
         } else {
228 233
             if (isBack && !screen.backButtonHidden) {
229
-                navArrow = new DrawerArrowDrawable(ContextProvider.getActivityContext());
234
+                navArrow = new DrawerArrowDrawable(context);
230 235
             } else if (hasDrawer) {
231 236
                 navIcon = mDrawerIcon;
232 237
             }