Browse Source

Search for textual buttons only in ActionMenuView instead of the entire ToolBar

This prevents a rare bug where the title would be styled as a button if both contained the same text
Guy Carmeli 6 years ago
parent
commit
f5ae71c6af

+ 4
- 1
lib/android/app/src/main/java/com/reactnativenavigation/utils/ButtonOptionsPresenter.java View File

6
 import android.graphics.Typeface;
6
 import android.graphics.Typeface;
7
 import android.graphics.drawable.Drawable;
7
 import android.graphics.drawable.Drawable;
8
 import android.support.annotation.NonNull;
8
 import android.support.annotation.NonNull;
9
+import android.support.v7.widget.ActionMenuView;
9
 import android.support.v7.widget.Toolbar;
10
 import android.support.v7.widget.Toolbar;
10
 import android.text.Spannable;
11
 import android.text.Spannable;
11
 import android.text.SpannableString;
12
 import android.text.SpannableString;
20
 
21
 
21
 public class ButtonOptionsPresenter {
22
 public class ButtonOptionsPresenter {
22
     private final Toolbar toolbar;
23
     private final Toolbar toolbar;
24
+    private final ActionMenuView actionMenuView;
23
     private Button button;
25
     private Button button;
24
 
26
 
25
     public ButtonOptionsPresenter(Toolbar toolbar, Button button) {
27
     public ButtonOptionsPresenter(Toolbar toolbar, Button button) {
26
         this.toolbar = toolbar;
28
         this.toolbar = toolbar;
29
+        actionMenuView = ViewUtils.findChildrenByClass(toolbar, ActionMenuView.class).get(0);
27
         this.button = button;
30
         this.button = button;
28
     }
31
     }
29
 
32
 
77
     private ArrayList<View> findActualTextViewInMenu() {
80
     private ArrayList<View> findActualTextViewInMenu() {
78
         ArrayList<View> outViews = new ArrayList<>();
81
         ArrayList<View> outViews = new ArrayList<>();
79
         if (button.text.hasValue()) {
82
         if (button.text.hasValue()) {
80
-            toolbar.findViewsWithText(outViews, button.text.get(), View.FIND_VIEWS_WITH_TEXT);
83
+            actionMenuView.findViewsWithText(outViews, button.text.get(), View.FIND_VIEWS_WITH_TEXT);
81
         }
84
         }
82
         return outViews;
85
         return outViews;
83
     }
86
     }

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/utils/ViewUtils.java View File

49
         return ret;
49
         return ret;
50
     }
50
     }
51
 
51
 
52
-    public static <T> List<T> findChildrenByClass(ViewGroup root, Class clazz) {
52
+    public static <T> List<T> findChildrenByClass(ViewGroup root, Class<T> clazz) {
53
         return findChildrenByClass(root, clazz, child -> true);
53
         return findChildrenByClass(root, clazz, child -> true);
54
     }
54
     }
55
 
55
 

+ 4
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackOptionsPresenterTest.java View File

2
 
2
 
3
 import android.app.Activity;
3
 import android.app.Activity;
4
 import android.graphics.Typeface;
4
 import android.graphics.Typeface;
5
+import android.support.v7.widget.ActionMenuView;
5
 import android.support.v7.widget.Toolbar;
6
 import android.support.v7.widget.Toolbar;
6
 import android.util.Log;
7
 import android.util.Log;
7
 import android.view.Gravity;
8
 import android.view.Gravity;
494
 
495
 
495
     private TopBar mockTopBar() {
496
     private TopBar mockTopBar() {
496
         TopBar topBar = mock(TopBar.class);
497
         TopBar topBar = mock(TopBar.class);
498
+        Toolbar toolbar = new Toolbar(activity);
499
+        toolbar.addView(new ActionMenuView(activity));
500
+        when(topBar.getTitleBar()).then(invocation -> toolbar);
497
         when(topBar.getContext()).then(invocation -> activity);
501
         when(topBar.getContext()).then(invocation -> activity);
498
         return topBar;
502
         return topBar;
499
     }
503
     }