Browse Source

Check if tab exists before applying tab options

Child options are applied when a child appears, meaning it's attached to hierarchy.
Going over the Wix app crash logs, a few users experienced a crash where apparently
BottomTabs options were applied for a child component, and a corresponding tab wasn't found.
I'm not sure how this happens and wasn't able to reproduce the crash.

Hopefully I'll have more information in the future but for now I've added a simple check to ensure
options are applied only if a tab is found.
Guy Carmeli 5 years ago
parent
commit
3073f295fb

+ 8
- 5
lib/android/app/src/main/java/com/reactnativenavigation/presentation/BottomTabsOptionsPresenter.java View File

@@ -1,6 +1,7 @@
1 1
 package com.reactnativenavigation.presentation;
2 2
 
3 3
 import android.graphics.Color;
4
+import android.support.annotation.IntRange;
4 5
 import android.view.ViewGroup;
5 6
 import android.view.ViewGroup.MarginLayoutParams;
6 7
 
@@ -53,16 +54,18 @@ public class BottomTabsOptionsPresenter {
53 54
     }
54 55
 
55 56
     public void applyChildOptions(Options options, Component child) {
56
-        Options withDefaultOptions = options.copy().withDefaultOptions(defaultOptions);
57
-        applyBottomTabsOptions(withDefaultOptions.bottomTabsOptions, withDefaultOptions.animations);
58 57
         int tabIndex = bottomTabFinder.findByComponent(child);
59
-        applyDrawBehind(withDefaultOptions.bottomTabsOptions, tabIndex);
58
+        if (tabIndex >= 0) {
59
+            Options withDefaultOptions = options.copy().withDefaultOptions(defaultOptions);
60
+            applyBottomTabsOptions(withDefaultOptions.bottomTabsOptions, withDefaultOptions.animations);
61
+            applyDrawBehind(withDefaultOptions.bottomTabsOptions, tabIndex);
62
+        }
60 63
     }
61 64
 
62 65
     public void mergeChildOptions(Options options, Component child) {
63 66
         mergeBottomTabsOptions(options.bottomTabsOptions, options.animations);
64 67
         int tabIndex = bottomTabFinder.findByComponent(child);
65
-        mergeDrawBehind(options.bottomTabsOptions, tabIndex);
68
+        if (tabIndex >= 0) mergeDrawBehind(options.bottomTabsOptions, tabIndex);
66 69
     }
67 70
 
68 71
     private void mergeBottomTabsOptions(BottomTabsOptions options, AnimationsOptions animations) {
@@ -99,7 +102,7 @@ public class BottomTabsOptionsPresenter {
99 102
         }
100 103
     }
101 104
 
102
-    private void applyDrawBehind(BottomTabsOptions options, int tabIndex) {
105
+    private void applyDrawBehind(BottomTabsOptions options, @IntRange(from = 0) int tabIndex) {
103 106
         ViewGroup tab = tabs.get(tabIndex).getView();
104 107
         MarginLayoutParams lp = (MarginLayoutParams) tab.getLayoutParams();
105 108
         if (options.drawBehind.isTrue()) {