|
@@ -8,7 +8,6 @@ import android.text.TextUtils;
|
8
|
8
|
import android.view.Menu;
|
9
|
9
|
import android.view.MenuItem;
|
10
|
10
|
import android.view.View;
|
11
|
|
-import android.view.ViewGroup;
|
12
|
11
|
import android.widget.TextView;
|
13
|
12
|
|
14
|
13
|
import com.reactnativenavigation.NavigationApplication;
|
|
@@ -21,29 +20,28 @@ import java.util.ArrayList;
|
21
|
20
|
class TitleBarButton implements MenuItem.OnMenuItemClickListener {
|
22
|
21
|
|
23
|
22
|
protected final Menu menu;
|
24
|
|
- protected final ViewGroup parent;
|
|
23
|
+ private final ActionMenuView actionMenuView;
|
25
|
24
|
private TitleBarButtonParams buttonParams;
|
26
|
25
|
@Nullable protected String navigatorEventId;
|
27
|
26
|
|
28
|
|
- TitleBarButton(Menu menu, ViewGroup parent, TitleBarButtonParams buttonParams, @Nullable String navigatorEventId) {
|
|
27
|
+ TitleBarButton(Menu menu, ActionMenuView actionMenuView, TitleBarButtonParams buttonParams, @Nullable String navigatorEventId) {
|
29
|
28
|
this.menu = menu;
|
30
|
|
- this.parent = parent;
|
|
29
|
+ this.actionMenuView = actionMenuView;
|
31
|
30
|
this.buttonParams = buttonParams;
|
32
|
31
|
this.navigatorEventId = navigatorEventId;
|
33
|
32
|
}
|
34
|
33
|
|
35
|
|
- MenuItem addToMenu(int index) {
|
|
34
|
+ void addToMenu(int index) {
|
36
|
35
|
MenuItem item = createMenuItem(index);
|
37
|
36
|
item.setShowAsAction(buttonParams.showAsAction.action);
|
38
|
37
|
item.setEnabled(buttonParams.enabled);
|
39
|
38
|
if (buttonParams.hasComponent()) {
|
40
|
|
- item.setActionView(new TitleBarButtonComponent(parent.getContext(), buttonParams.componentName, buttonParams.componentProps));
|
|
39
|
+ item.setActionView(new TitleBarButtonComponent(actionMenuView.getContext(), buttonParams.componentName, buttonParams.componentProps));
|
41
|
40
|
}
|
42
|
41
|
setIcon(item, index);
|
43
|
42
|
setColor();
|
44
|
43
|
setFont();
|
45
|
44
|
item.setOnMenuItemClickListener(this);
|
46
|
|
- return item;
|
47
|
45
|
}
|
48
|
46
|
|
49
|
47
|
private MenuItem createMenuItem(int index) {
|
|
@@ -66,10 +64,9 @@ class TitleBarButton implements MenuItem.OnMenuItemClickListener {
|
66
|
64
|
}
|
67
|
65
|
|
68
|
66
|
private void dontShowLabelOnLongPress(final int index) {
|
69
|
|
- ViewUtils.runOnPreDraw(parent, new Runnable() {
|
|
67
|
+ ViewUtils.runOnPreDraw(actionMenuView, new Runnable() {
|
70
|
68
|
@Override
|
71
|
69
|
public void run() {
|
72
|
|
- ActionMenuView actionMenuView = ViewUtils.findChildByClass(parent, ActionMenuView.class);
|
73
|
70
|
if (actionMenuView != null && actionMenuView.getChildAt(index) != null) {
|
74
|
71
|
actionMenuView.getChildAt(index).setOnLongClickListener(null);
|
75
|
72
|
}
|
|
@@ -94,7 +91,7 @@ class TitleBarButton implements MenuItem.OnMenuItemClickListener {
|
94
|
91
|
}
|
95
|
92
|
|
96
|
93
|
private void setTextColor() {
|
97
|
|
- ViewUtils.runOnPreDraw(parent, new Runnable() {
|
|
94
|
+ ViewUtils.runOnPreDraw(actionMenuView, new Runnable() {
|
98
|
95
|
@Override
|
99
|
96
|
public void run() {
|
100
|
97
|
ArrayList<View> outViews = findActualTextViewInMenuByLabel();
|
|
@@ -114,7 +111,7 @@ class TitleBarButton implements MenuItem.OnMenuItemClickListener {
|
114
|
111
|
@NonNull
|
115
|
112
|
private ArrayList<View> findActualTextViewInMenuByLabel() {
|
116
|
113
|
ArrayList<View> outViews = new ArrayList<>();
|
117
|
|
- parent.findViewsWithText(outViews, buttonParams.label, View.FIND_VIEWS_WITH_TEXT);
|
|
114
|
+ actionMenuView.findViewsWithText(outViews, buttonParams.label, View.FIND_VIEWS_WITH_TEXT);
|
118
|
115
|
return outViews;
|
119
|
116
|
}
|
120
|
117
|
|