Sfoglia il codice sorgente

Keep button order

When saving buttons by screen, buttons were stored in a HashMap which doesn't maintain
order.
Closes #3916
Guy Carmeli 6 anni fa
parent
commit
a2394dcc17

+ 2
- 1
lib/android/app/src/main/java/com/reactnativenavigation/presentation/StackOptionsPresenter.java Vedi File

@@ -34,6 +34,7 @@ import com.reactnativenavigation.views.topbar.TopBar;
34 34
 import java.util.ArrayList;
35 35
 import java.util.Collections;
36 36
 import java.util.HashMap;
37
+import java.util.LinkedHashMap;
37 38
 import java.util.List;
38 39
 import java.util.Map;
39 40
 
@@ -242,7 +243,7 @@ public class StackOptionsPresenter {
242 243
 
243 244
     private List<TitleBarButtonController> getOrCreateButtonControllers(@Nullable Map<String, TitleBarButtonController> currentButtons, @Nullable List<Button> buttons) {
244 245
         if (buttons == null) return null;
245
-        Map<String, TitleBarButtonController> result = new HashMap<>();
246
+        Map<String, TitleBarButtonController> result = new LinkedHashMap<>();
246 247
         for (Button b : buttons) {
247 248
             result.put(b.instanceId, currentButtons != null && currentButtons.containsKey(b.instanceId) ? currentButtons.get(b.instanceId) : createButtonController(b));
248 249
         }

+ 2
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/TitleBarButtonController.java Vedi File

@@ -8,6 +8,7 @@ import android.support.annotation.NonNull;
8 8
 import android.support.annotation.RestrictTo;
9 9
 import android.support.v7.widget.ActionMenuView;
10 10
 import android.support.v7.widget.Toolbar;
11
+import android.view.Menu;
11 12
 import android.view.MenuItem;
12 13
 import android.widget.ImageButton;
13 14
 import android.widget.TextView;
@@ -115,7 +116,7 @@ public class TitleBarButtonController extends ViewController<TitleBarReactButton
115 116
     }
116 117
 
117 118
     public void addToMenu(Toolbar toolbar, int position) {
118
-        MenuItem menuItem = toolbar.getMenu().add(0, position, position, button.text.get(""));
119
+        MenuItem menuItem = toolbar.getMenu().add(Menu.NONE, position, position, button.text.get(""));
119 120
         if (button.showAsAction.hasValue()) menuItem.setShowAsAction(button.showAsAction.get());
120 121
         menuItem.setEnabled(button.enabled.isTrueOrUndefined());
121 122
         menuItem.setOnMenuItemClickListener(this);