|
@@ -2,11 +2,13 @@ package com.reactnativenavigation.views;
|
2
|
2
|
|
3
|
3
|
import android.support.annotation.NonNull;
|
4
|
4
|
import android.support.annotation.Nullable;
|
|
5
|
+import android.support.v7.widget.ActionMenuView;
|
5
|
6
|
import android.text.SpannableStringBuilder;
|
6
|
7
|
import android.text.TextUtils;
|
7
|
8
|
import android.view.Menu;
|
8
|
9
|
import android.view.MenuItem;
|
9
|
10
|
import android.view.View;
|
|
11
|
+import android.view.ViewGroup;
|
10
|
12
|
import android.widget.TextView;
|
11
|
13
|
|
12
|
14
|
import com.reactnativenavigation.NavigationApplication;
|
|
@@ -19,11 +21,11 @@ import java.util.ArrayList;
|
19
|
21
|
class TitleBarButton implements MenuItem.OnMenuItemClickListener {
|
20
|
22
|
|
21
|
23
|
protected final Menu menu;
|
22
|
|
- protected final View parent;
|
23
|
|
- TitleBarButtonParams buttonParams;
|
|
24
|
+ protected final ViewGroup parent;
|
|
25
|
+ private TitleBarButtonParams buttonParams;
|
24
|
26
|
@Nullable protected String navigatorEventId;
|
25
|
27
|
|
26
|
|
- TitleBarButton(Menu menu, View parent, TitleBarButtonParams buttonParams, @Nullable String navigatorEventId) {
|
|
28
|
+ TitleBarButton(Menu menu, ViewGroup parent, TitleBarButtonParams buttonParams, @Nullable String navigatorEventId) {
|
27
|
29
|
this.menu = menu;
|
28
|
30
|
this.parent = parent;
|
29
|
31
|
this.buttonParams = buttonParams;
|
|
@@ -37,7 +39,7 @@ class TitleBarButton implements MenuItem.OnMenuItemClickListener {
|
37
|
39
|
if (buttonParams.hasComponent()) {
|
38
|
40
|
item.setActionView(new TitleBarButtonComponent(parent.getContext(), buttonParams.componentName, buttonParams.componentProps));
|
39
|
41
|
}
|
40
|
|
- setIcon(item);
|
|
42
|
+ setIcon(item, index);
|
41
|
43
|
setColor();
|
42
|
44
|
setFont();
|
43
|
45
|
item.setOnMenuItemClickListener(this);
|
|
@@ -54,12 +56,27 @@ class TitleBarButton implements MenuItem.OnMenuItemClickListener {
|
54
|
56
|
return menu.add(Menu.NONE, Menu.NONE, index, title);
|
55
|
57
|
}
|
56
|
58
|
|
57
|
|
- private void setIcon(MenuItem item) {
|
|
59
|
+ private void setIcon(MenuItem item, int index) {
|
58
|
60
|
if (hasIcon()) {
|
59
|
61
|
item.setIcon(buttonParams.icon);
|
|
62
|
+ if (TextUtils.isEmpty(buttonParams.label)) {
|
|
63
|
+ dontShowLabelOnLongPress(index);
|
|
64
|
+ }
|
60
|
65
|
}
|
61
|
66
|
}
|
62
|
67
|
|
|
68
|
+ private void dontShowLabelOnLongPress(final int index) {
|
|
69
|
+ ViewUtils.runOnPreDraw(parent, new Runnable() {
|
|
70
|
+ @Override
|
|
71
|
+ public void run() {
|
|
72
|
+ ActionMenuView actionMenuView = ViewUtils.findChildByClass(parent, ActionMenuView.class);
|
|
73
|
+ if (actionMenuView != null) {
|
|
74
|
+ actionMenuView.getChildAt(index).setOnLongClickListener(null);
|
|
75
|
+ }
|
|
76
|
+ }
|
|
77
|
+ });
|
|
78
|
+ }
|
|
79
|
+
|
63
|
80
|
private void setColor() {
|
64
|
81
|
if (!hasColor() || disableIconTint()) {
|
65
|
82
|
return;
|