소스 검색

Support navigatorButtons

Guy Carmeli 8 년 전
부모
커밋
a2a892d660

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/activities/SingleScreenActivity.java 파일 보기

@@ -26,7 +26,7 @@ public class SingleScreenActivity extends BaseReactActivity {
26 26
         setContentView(R.layout.single_screen_activity);
27 27
         mToolbar = (RnnToolBar) findViewById(R.id.toolbar);
28 28
 
29
-        Screen screen = (Screen) getIntent().getSerializableExtra(EXTRA_SCREEN);
29
+        final Screen screen = (Screen) getIntent().getSerializableExtra(EXTRA_SCREEN);
30 30
         mNavigatorId = screen.navigatorId;
31 31
 
32 32
         mScreenStack = new ScreenStack(this);
@@ -39,7 +39,7 @@ public class SingleScreenActivity extends BaseReactActivity {
39 39
         contentFrame.post(new Runnable() {
40 40
             @Override
41 41
             public void run() {
42
-                setupToolbar(getCurrentScreen());
42
+                setupToolbar(screen);
43 43
             }
44 44
         });
45 45
     }

+ 12
- 2
android/app/src/main/java/com/reactnativenavigation/core/objects/Screen.java 파일 보기

@@ -30,6 +30,7 @@ public class Screen extends JsonObject implements Serializable {
30 30
     public static final String KEY_NAVIGATOR_ID = "navigatorID";
31 31
     public static final String KEY_NAVIGATOR_EVENT_ID = "navigatorEventID";
32 32
     private static final String KEY_ICON = "icon";
33
+    private static final String KEY_NAVIGATOR_BUTTONS = "navigatorButtons";
33 34
     private static final String KEY_RIGHT_BUTTONS = "rightButtons";
34 35
     private static final String KEY_TOOL_BAR_STYLE = "navigatorStyle";
35 36
     private static final String KEY_STATUS_BAR_COLOR = "statusBarColor";
@@ -90,8 +91,8 @@ public class Screen extends JsonObject implements Serializable {
90 91
 
91 92
     private ArrayList<Button> getButtons(ReadableMap screen) {
92 93
         ArrayList<Button> ret = new ArrayList<>();
93
-        if (screen.hasKey(KEY_RIGHT_BUTTONS)) {
94
-            ReadableArray rightButtons = screen.getArray(KEY_RIGHT_BUTTONS);
94
+        if (hasButtons(screen)) {
95
+            ReadableArray rightButtons = getRightButtons(screen);
95 96
             for (int i = 0; i < rightButtons.size(); i++) {
96 97
                 ret.add(new Button(rightButtons.getMap(i)));
97 98
             }
@@ -99,6 +100,15 @@ public class Screen extends JsonObject implements Serializable {
99 100
         return ret;
100 101
     }
101 102
 
103
+    private boolean hasButtons(ReadableMap screen) {
104
+        return screen.hasKey(KEY_RIGHT_BUTTONS) || screen.hasKey(KEY_NAVIGATOR_BUTTONS);
105
+    }
106
+
107
+    private ReadableArray getRightButtons(ReadableMap screen) {
108
+        return screen.hasKey(KEY_RIGHT_BUTTONS) ? screen.getArray(KEY_RIGHT_BUTTONS) :
109
+                screen.getMap(KEY_NAVIGATOR_BUTTONS).getArray(KEY_RIGHT_BUTTONS);
110
+    }
111
+
102 112
     public Drawable getIcon(Context ctx) {
103 113
         return IconUtils.getIcon(ctx, icon);
104 114
     }

+ 4
- 2
src/platformSpecific.android.js 파일 보기

@@ -110,8 +110,10 @@ function addNavigatorButtons(screen) {
110 110
   Object.assign(screen, Screen.navigatorButtons);
111 111
 
112 112
   // Get image uri from image id
113
-  if (screen.rightButtons) {
114
-    screen.rightButtons.forEach(function(button) {
113
+  const rightButtons = screen.rightButtons ? screen.rightButtons : screen.navigatorButtons ?
114
+    screen.navigatorButtons.rightButtons : null;
115
+  if (rightButtons) {
116
+    rightButtons.forEach(function(button) {
115 117
       if (button.icon) {
116 118
         const icon = resolveAssetSource(button.icon);
117 119
         if (icon) {