Selaa lähdekoodia

Support defining MenuItem action from JS

Supported actions:

1. never - Never show this item as a button in an Action Bar.

2. always - Always show this item as a button in an Action Bar.
Use sparingly! If too many items are set to always show in the Action
Bar it can crowd the Action Bar and degrade the user experience on
devices with smaller screens. A good rule of thumb is to have no more
than 2 items set to always show at a time.

3. withText - When this item is in the action bar, always show it
with a text label even if it also has an icon specified.

4. ifRoom (default) - Show this item as a button in an Action Bar if
the system decides there is room for it.
Guy Carmeli 8 vuotta sitten
vanhempi
commit
2d52d4b7e8

+ 14
- 1
android/app/src/main/java/com/reactnativenavigation/views/RnnToolBar.java Näytä tiedosto

@@ -362,7 +362,7 @@ public class RnnToolBar extends Toolbar {
362 362
             for (int i = 0; i < size; i++) {
363 363
                 Button button = mNewButtons.get(i);
364 364
                 MenuItem item = menu.add(Menu.NONE, button.getItemId(), size - i - 1, button.title);
365
-                item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
365
+                item.setShowAsAction(getMenuItemShowAction(button.showAsAction));
366 366
 
367 367
                 // Set button icon
368 368
                 if (button.hasIcon()) {
@@ -415,5 +415,18 @@ public class RnnToolBar extends Toolbar {
415 415
                 mToolbarWR.clear();
416 416
             }
417 417
         }
418
+
419
+        private int getMenuItemShowAction(String action) {
420
+            switch (action) {
421
+                case "never":
422
+                    return MenuItem.SHOW_AS_ACTION_NEVER;
423
+                case "always":
424
+                    return MenuItem.SHOW_AS_ACTION_ALWAYS;
425
+                case "withText":
426
+                    return MenuItem.SHOW_AS_ACTION_WITH_TEXT;
427
+                default:
428
+                    return MenuItem.SHOW_AS_ACTION_IF_ROOM;
429
+            }
430
+        }
418 431
     }
419 432
 }