Преглед на файлове

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 години
родител
ревизия
2d52d4b7e8
променени са 1 файла, в които са добавени 14 реда и са изтрити 1 реда
  1. 14
    1
      android/app/src/main/java/com/reactnativenavigation/views/RnnToolBar.java

+ 14
- 1
android/app/src/main/java/com/reactnativenavigation/views/RnnToolBar.java Целия файл

362
             for (int i = 0; i < size; i++) {
362
             for (int i = 0; i < size; i++) {
363
                 Button button = mNewButtons.get(i);
363
                 Button button = mNewButtons.get(i);
364
                 MenuItem item = menu.add(Menu.NONE, button.getItemId(), size - i - 1, button.title);
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
                 // Set button icon
367
                 // Set button icon
368
                 if (button.hasIcon()) {
368
                 if (button.hasIcon()) {
415
                 mToolbarWR.clear();
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
 }