Procházet zdrojové kódy

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 před 6 roky
rodič
revize
f5ae71c6af

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

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

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/utils/ViewUtils.java Zobrazit soubor

@@ -49,7 +49,7 @@ public class ViewUtils {
49 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 53
         return findChildrenByClass(root, clazz, child -> true);
54 54
     }
55 55
 

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

@@ -2,6 +2,7 @@ package com.reactnativenavigation.viewcontrollers;
2 2
 
3 3
 import android.app.Activity;
4 4
 import android.graphics.Typeface;
5
+import android.support.v7.widget.ActionMenuView;
5 6
 import android.support.v7.widget.Toolbar;
6 7
 import android.util.Log;
7 8
 import android.view.Gravity;
@@ -494,6 +495,9 @@ public class StackOptionsPresenterTest extends BaseTest {
494 495
 
495 496
     private TopBar mockTopBar() {
496 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 501
         when(topBar.getContext()).then(invocation -> activity);
498 502
         return topBar;
499 503
     }