Browse Source

Add TopBar buttons in reverse order to match iOS ordering

Guy Carmeli 6 years ago
parent
commit
79cfc6045f

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/TopBarButtonController.java View File

106
         });
106
         });
107
     }
107
     }
108
 
108
 
109
-    public void addToMenu(Toolbar toolbar) {
110
-        MenuItem menuItem = toolbar.getMenu().add(button.title.get(""));
109
+    public void addToMenu(Toolbar toolbar, int position) {
110
+        MenuItem menuItem = toolbar.getMenu().add(0, position, position, button.title.get(""));
111
         menuItem.setShowAsAction(button.showAsAction);
111
         menuItem.setShowAsAction(button.showAsAction);
112
         menuItem.setEnabled(button.enabled.isTrueOrUndefined());
112
         menuItem.setEnabled(button.enabled.isTrueOrUndefined());
113
         menuItem.setOnMenuItemClickListener(this);
113
         menuItem.setOnMenuItemClickListener(this);

+ 3
- 3
lib/android/app/src/main/java/com/reactnativenavigation/views/TitleBar.java View File

113
     public void setRightButtons(List<Button> rightButtons) {
113
     public void setRightButtons(List<Button> rightButtons) {
114
         if (rightButtons == null) return;
114
         if (rightButtons == null) return;
115
         clearRightButtons();
115
         clearRightButtons();
116
-        for (Button button : rightButtons) {
117
-            TopBarButtonController controller = createButtonController(button);
116
+        for (int i = 0; i < rightButtons.size(); i++) {
117
+            TopBarButtonController controller = createButtonController(rightButtons.get(i));
118
             rightButtonControllers.add(controller);
118
             rightButtonControllers.add(controller);
119
-            controller.addToMenu(this);
119
+            controller.addToMenu(this, rightButtons.size() - i - 1);
120
         }
120
         }
121
     }
121
     }
122
 
122
 

+ 6
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TitleBarTest.java View File

114
         verify(buttonControllers.get(leftButton.id), times(1)).destroy();
114
         verify(buttonControllers.get(leftButton.id), times(1)).destroy();
115
     }
115
     }
116
 
116
 
117
+    @Test
118
+    public void setRightButtons_buttonsAreAddedInReverseOrderToMatchOrderOnIOs() throws Exception {
119
+        uut.setButtons(new ArrayList<>(), rightButtons(textButton, customButton));
120
+        assertThat(uut.getMenu().getItem(1).getTitle()).isEqualTo(textButton.title.get());
121
+    }
122
+
117
     private List<Button> leftButton(Button leftButton) {
123
     private List<Button> leftButton(Button leftButton) {
118
         return Collections.singletonList(leftButton);
124
         return Collections.singletonList(leftButton);
119
     }
125
     }