Browse Source

Keep button order

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

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

34
 import java.util.ArrayList;
34
 import java.util.ArrayList;
35
 import java.util.Collections;
35
 import java.util.Collections;
36
 import java.util.HashMap;
36
 import java.util.HashMap;
37
+import java.util.LinkedHashMap;
37
 import java.util.List;
38
 import java.util.List;
38
 import java.util.Map;
39
 import java.util.Map;
39
 
40
 
242
 
243
 
243
     private List<TitleBarButtonController> getOrCreateButtonControllers(@Nullable Map<String, TitleBarButtonController> currentButtons, @Nullable List<Button> buttons) {
244
     private List<TitleBarButtonController> getOrCreateButtonControllers(@Nullable Map<String, TitleBarButtonController> currentButtons, @Nullable List<Button> buttons) {
244
         if (buttons == null) return null;
245
         if (buttons == null) return null;
245
-        Map<String, TitleBarButtonController> result = new HashMap<>();
246
+        Map<String, TitleBarButtonController> result = new LinkedHashMap<>();
246
         for (Button b : buttons) {
247
         for (Button b : buttons) {
247
             result.put(b.instanceId, currentButtons != null && currentButtons.containsKey(b.instanceId) ? currentButtons.get(b.instanceId) : createButtonController(b));
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 View File

8
 import android.support.annotation.RestrictTo;
8
 import android.support.annotation.RestrictTo;
9
 import android.support.v7.widget.ActionMenuView;
9
 import android.support.v7.widget.ActionMenuView;
10
 import android.support.v7.widget.Toolbar;
10
 import android.support.v7.widget.Toolbar;
11
+import android.view.Menu;
11
 import android.view.MenuItem;
12
 import android.view.MenuItem;
12
 import android.widget.ImageButton;
13
 import android.widget.ImageButton;
13
 import android.widget.TextView;
14
 import android.widget.TextView;
115
     }
116
     }
116
 
117
 
117
     public void addToMenu(Toolbar toolbar, int position) {
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
         if (button.showAsAction.hasValue()) menuItem.setShowAsAction(button.showAsAction.get());
120
         if (button.showAsAction.hasValue()) menuItem.setShowAsAction(button.showAsAction.get());
120
         menuItem.setEnabled(button.enabled.isTrueOrUndefined());
121
         menuItem.setEnabled(button.enabled.isTrueOrUndefined());
121
         menuItem.setOnMenuItemClickListener(this);
122
         menuItem.setOnMenuItemClickListener(this);