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 6 years ago
parent
commit
3073f295fb

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

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