react-native-navigation的迁移库

TitleBarButtonParamsParser.java 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package com.reactnativenavigation.params.parsers;
  2. import android.os.Bundle;
  3. import com.reactnativenavigation.params.AppStyle;
  4. import com.reactnativenavigation.params.BaseTitleBarButtonParams;
  5. import com.reactnativenavigation.params.TitleBarButtonParams;
  6. import com.reactnativenavigation.react.ImageLoader;
  7. import java.util.List;
  8. public class TitleBarButtonParamsParser extends Parser {
  9. public List<TitleBarButtonParams> parseButtons(Bundle params) {
  10. return parseBundle(params, new ParseStrategy<TitleBarButtonParams>() {
  11. @Override
  12. public TitleBarButtonParams parse(Bundle button) {
  13. return parseSingleButton(button);
  14. }
  15. });
  16. }
  17. public TitleBarButtonParams parseSingleButton(Bundle bundle) {
  18. TitleBarButtonParams result = new TitleBarButtonParams();
  19. result.label = bundle.getString("title");
  20. if (hasKey(bundle, "icon")) {
  21. result.icon = ImageLoader.loadImage(bundle.getString("icon"));
  22. }
  23. result.color = getColor(bundle, "color", AppStyle.appStyle.titleBarButtonColor);
  24. result.disabledColor =
  25. getColor(bundle, "titleBarDisabledButtonColor", AppStyle.appStyle.titleBarDisabledButtonColor);
  26. result.showAsAction = parseShowAsAction(bundle.getString("showAsAction"));
  27. result.enabled = bundle.getBoolean("enabled", true);
  28. result.hint = bundle.getString("hint", "");
  29. result.eventId = bundle.getString("id");
  30. return result;
  31. }
  32. BaseTitleBarButtonParams.ShowAsAction parseShowAsAction(String showAsAction) {
  33. if (showAsAction == null) {
  34. return BaseTitleBarButtonParams.ShowAsAction.IfRoom;
  35. }
  36. switch (showAsAction) {
  37. case "always":
  38. return BaseTitleBarButtonParams.ShowAsAction.Always;
  39. case "never":
  40. return BaseTitleBarButtonParams.ShowAsAction.Never;
  41. case "withText":
  42. return BaseTitleBarButtonParams.ShowAsAction.WithText;
  43. case "ifRoom":
  44. default:
  45. return BaseTitleBarButtonParams.ShowAsAction.IfRoom;
  46. }
  47. }
  48. }