Browse Source

Use leftButtons api on Android like in iOS

This commit closes #224 and fixes #252. Calling `setButtons` with
`leftButton` object still works for now but is deprecated and will be
removed in future version.
Guy Carmeli 8 years ago
parent
commit
eb8579c24e
1 changed files with 25 additions and 5 deletions
  1. 25
    5
      src/deprecated/platformSpecificDeprecated.android.js

+ 25
- 5
src/deprecated/platformSpecificDeprecated.android.js View File

228
       }
228
       }
229
     });
229
     });
230
   }
230
   }
231
-  if (params.leftButton) {
232
-    if (params.leftButton.icon) {
233
-      const icon = resolveAssetSource(params.leftButton.icon);
231
+  const leftButton = getLeftButton(params);
232
+  if (leftButton) {
233
+    if (leftButton.icon) {
234
+      const icon = resolveAssetSource(leftButton.icon);
234
       if (icon) {
235
       if (icon) {
235
-        params.leftButton.icon = icon.uri;
236
+        leftButton.icon = icon.uri;
236
       }
237
       }
237
     }
238
     }
238
   }
239
   }
239
-  newPlatformSpecific.setScreenTitleBarButtons(navigator.screenInstanceID, navigatorEventID, params.rightButtons, params.leftButton);
240
+  newPlatformSpecific.setScreenTitleBarButtons(navigator.screenInstanceID, navigatorEventID, params.rightButtons, leftButton);
240
 }
241
 }
241
 
242
 
242
 function navigatorSetTabBadge(navigator, params) {
243
 function navigatorSetTabBadge(navigator, params) {
375
 }
376
 }
376
 
377
 
377
 function getLeftButton(screen) {
378
 function getLeftButton(screen) {
379
+  const leftButton = getLeftButtonDeprecated(screen);
380
+  if (leftButton) {
381
+    console.warn('leftButton is deprecated. Instead, please use leftButtons like on iOS.');
382
+    return leftButton;
383
+  }
384
+
385
+  if (screen.navigatorButtons && screen.navigatorButtons.leftButtons) {
386
+    return screen.navigatorButtons.leftButtons[0];
387
+  }
388
+
389
+
390
+  if (screen.leftButtons) {
391
+    return screen.leftButtons[0];
392
+  }
393
+
394
+  return null;
395
+}
396
+
397
+function getLeftButtonDeprecated(screen) {
378
   if (screen.navigatorButtons && screen.navigatorButtons.leftButton) {
398
   if (screen.navigatorButtons && screen.navigatorButtons.leftButton) {
379
     return screen.navigatorButtons.leftButton;
399
     return screen.navigatorButtons.leftButton;
380
   }
400
   }