Browse Source

Don't show title on button long press is title is undefined

Fixes #1007
Guy Carmeli 7 years ago
parent
commit
354f60d124

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/views/ContextualMenuButton.java View File

2
 
2
 
3
 import android.view.Menu;
3
 import android.view.Menu;
4
 import android.view.MenuItem;
4
 import android.view.MenuItem;
5
-import android.view.View;
5
+import android.view.ViewGroup;
6
 
6
 
7
 import com.reactnativenavigation.params.ContextualMenuButtonParams;
7
 import com.reactnativenavigation.params.ContextualMenuButtonParams;
8
 
8
 
14
         void onClick(int index);
14
         void onClick(int index);
15
     }
15
     }
16
 
16
 
17
-    ContextualMenuButton(Menu menu, View parent, ContextualMenuButtonParams contextualMenuButtonParams, ContextualButtonClickListener contextualButtonClickListener) {
17
+    ContextualMenuButton(Menu menu, ViewGroup parent, ContextualMenuButtonParams contextualMenuButtonParams, ContextualButtonClickListener contextualButtonClickListener) {
18
         super(menu, parent, contextualMenuButtonParams, null);
18
         super(menu, parent, contextualMenuButtonParams, null);
19
         this.contextualMenuButtonParams = contextualMenuButtonParams;
19
         this.contextualMenuButtonParams = contextualMenuButtonParams;
20
         this.contextualButtonClickListener = contextualButtonClickListener;
20
         this.contextualButtonClickListener = contextualButtonClickListener;

+ 22
- 5
android/app/src/main/java/com/reactnativenavigation/views/TitleBarButton.java View File

2
 
2
 
3
 import android.support.annotation.NonNull;
3
 import android.support.annotation.NonNull;
4
 import android.support.annotation.Nullable;
4
 import android.support.annotation.Nullable;
5
+import android.support.v7.widget.ActionMenuView;
5
 import android.text.SpannableStringBuilder;
6
 import android.text.SpannableStringBuilder;
6
 import android.text.TextUtils;
7
 import android.text.TextUtils;
7
 import android.view.Menu;
8
 import android.view.Menu;
8
 import android.view.MenuItem;
9
 import android.view.MenuItem;
9
 import android.view.View;
10
 import android.view.View;
11
+import android.view.ViewGroup;
10
 import android.widget.TextView;
12
 import android.widget.TextView;
11
 
13
 
12
 import com.reactnativenavigation.NavigationApplication;
14
 import com.reactnativenavigation.NavigationApplication;
19
 class TitleBarButton implements MenuItem.OnMenuItemClickListener {
21
 class TitleBarButton implements MenuItem.OnMenuItemClickListener {
20
 
22
 
21
     protected final Menu menu;
23
     protected final Menu menu;
22
-    protected final View parent;
23
-    TitleBarButtonParams buttonParams;
24
+    protected final ViewGroup parent;
25
+    private TitleBarButtonParams buttonParams;
24
     @Nullable protected String navigatorEventId;
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
         this.menu = menu;
29
         this.menu = menu;
28
         this.parent = parent;
30
         this.parent = parent;
29
         this.buttonParams = buttonParams;
31
         this.buttonParams = buttonParams;
37
         if (buttonParams.hasComponent()) {
39
         if (buttonParams.hasComponent()) {
38
             item.setActionView(new TitleBarButtonComponent(parent.getContext(), buttonParams.componentName, buttonParams.componentProps));
40
             item.setActionView(new TitleBarButtonComponent(parent.getContext(), buttonParams.componentName, buttonParams.componentProps));
39
         }
41
         }
40
-        setIcon(item);
42
+        setIcon(item, index);
41
         setColor();
43
         setColor();
42
         setFont();
44
         setFont();
43
         item.setOnMenuItemClickListener(this);
45
         item.setOnMenuItemClickListener(this);
54
         return menu.add(Menu.NONE, Menu.NONE, index, title);
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
         if (hasIcon()) {
60
         if (hasIcon()) {
59
             item.setIcon(buttonParams.icon);
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
     private void setColor() {
80
     private void setColor() {
64
         if (!hasColor() || disableIconTint()) {
81
         if (!hasColor() || disableIconTint()) {
65
             return;
82
             return;