Pārlūkot izejas kodu

Add TopBar buttons in reverse order to match iOS ordering

Guy Carmeli 6 gadus atpakaļ
vecāks
revīzija
79cfc6045f

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/TopBarButtonController.java Parādīt failu

@@ -106,8 +106,8 @@ public class TopBarButtonController extends ViewController<TopBarReactButtonView
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 111
         menuItem.setShowAsAction(button.showAsAction);
112 112
         menuItem.setEnabled(button.enabled.isTrueOrUndefined());
113 113
         menuItem.setOnMenuItemClickListener(this);

+ 3
- 3
lib/android/app/src/main/java/com/reactnativenavigation/views/TitleBar.java Parādīt failu

@@ -113,10 +113,10 @@ public class TitleBar extends Toolbar {
113 113
     public void setRightButtons(List<Button> rightButtons) {
114 114
         if (rightButtons == null) return;
115 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 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 Parādīt failu

@@ -114,6 +114,12 @@ public class TitleBarTest extends BaseTest {
114 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 123
     private List<Button> leftButton(Button leftButton) {
118 124
         return Collections.singletonList(leftButton);
119 125
     }