Browse Source

Null check tabTestId

Guy Carmeli 6 years ago
parent
commit
770a001ba9

+ 13
- 0
lib/android/app/src/main/java/com/reactnativenavigation/utils/ObjectUtils.java View File

1
+package com.reactnativenavigation.utils;
2
+
3
+import android.support.annotation.Nullable;
4
+
5
+public class ObjectUtils {
6
+    public interface Action<T> {
7
+        void performOn(T obj);
8
+    }
9
+
10
+    public static <T> void perform(@Nullable T obj, Action<T> action) {
11
+        if (obj != null) action.performOn(obj);
12
+    }
13
+}

+ 7
- 5
lib/android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java View File

4
 import android.content.Context;
4
 import android.content.Context;
5
 import android.support.annotation.ColorInt;
5
 import android.support.annotation.ColorInt;
6
 import android.support.annotation.IntRange;
6
 import android.support.annotation.IntRange;
7
-import android.view.View;
8
 
7
 
9
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
8
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
10
 import com.reactnativenavigation.BuildConfig;
9
 import com.reactnativenavigation.BuildConfig;
11
 import com.reactnativenavigation.parse.params.Text;
10
 import com.reactnativenavigation.parse.params.Text;
12
 import com.reactnativenavigation.utils.CompatUtils;
11
 import com.reactnativenavigation.utils.CompatUtils;
13
 
12
 
13
+import static com.reactnativenavigation.utils.ObjectUtils.perform;
14
+
14
 @SuppressLint("ViewConstructor")
15
 @SuppressLint("ViewConstructor")
15
 public class BottomTabs extends AHBottomNavigation {
16
 public class BottomTabs extends AHBottomNavigation {
16
     public BottomTabs(Context context) {
17
     public BottomTabs(Context context) {
20
     }
21
     }
21
 
22
 
22
     public void setTabTestId(int index, Text testId) {
23
     public void setTabTestId(int index, Text testId) {
23
-        if (!testId.hasValue()) return;
24
-        View view = getViewAtPosition(index);
25
-        view.setTag(testId.get());
26
-        if (BuildConfig.DEBUG) view.setContentDescription(testId.get());
24
+        if (!testId.hasValue() ) return;
25
+        perform(getViewAtPosition(index), view -> {
26
+            view.setTag(testId.get());
27
+            if (BuildConfig.DEBUG) view.setContentDescription(testId.get());
28
+        });
27
     }
29
     }
28
 
30
 
29
     public void setBadge(int bottomTabIndex, String badge) {
31
     public void setBadge(int bottomTabIndex, String badge) {