react-native-navigation的迁移库

ScreenParamsParser.java 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package com.reactnativenavigation.params.parsers;
  2. import android.graphics.drawable.Drawable;
  3. import android.os.Bundle;
  4. import com.reactnativenavigation.params.NavigationParams;
  5. import com.reactnativenavigation.params.ScreenParams;
  6. import com.reactnativenavigation.params.PageParams;
  7. import com.reactnativenavigation.react.ImageLoader;
  8. import java.util.List;
  9. public class ScreenParamsParser extends Parser {
  10. private static final String KEY_TITLE = "title";
  11. private static final String KEY_SUBTITLE = "subtitle";
  12. private static final String KEY_SCREEN_ID = "screenId";
  13. private static final String KEY_NAVIGATION_PARAMS = "navigationParams";
  14. private static final String STYLE_PARAMS = "styleParams";
  15. private static final String TOP_TABS = "topTabs";
  16. private static final String FRAGMENT_CREATOR_CLASS_NAME = "fragmentCreatorClassName";
  17. private static final String FRAGMENT_CREATOR_PASS_PROPS = "fragmentCreatorPassProps";
  18. private static final String OVERRIDE_BACK_PRESS = "overrideBackPress";
  19. @SuppressWarnings("ConstantConditions")
  20. public static ScreenParams parse(Bundle params) {
  21. ScreenParams result = new ScreenParams();
  22. result.screenId = params.getString(KEY_SCREEN_ID);
  23. assertKeyExists(params, KEY_NAVIGATION_PARAMS);
  24. result.navigationParams = new NavigationParams(params.getBundle(KEY_NAVIGATION_PARAMS));
  25. result.styleParams = new StyleParamsParser(params.getBundle(STYLE_PARAMS)).parse();
  26. result.title = params.getString(KEY_TITLE);
  27. result.subtitle = params.getString(KEY_SUBTITLE);
  28. result.rightButtons = ButtonParser.parseRightButton(params);
  29. result.overrideBackPressInJs = params.getBoolean(OVERRIDE_BACK_PRESS, false);
  30. result.leftButton = ButtonParser.parseLeftButton(params);
  31. result.topTabParams = parseTopTabs(params);
  32. if (hasKey(params, FRAGMENT_CREATOR_CLASS_NAME)) {
  33. result.fragmentCreatorClassName = params.getString(FRAGMENT_CREATOR_CLASS_NAME);
  34. result.fragmentCreatorPassProps = params.getBundle(FRAGMENT_CREATOR_PASS_PROPS);
  35. }
  36. result.fabParams = ButtonParser.parseFab(params, result.navigationParams.navigatorEventId, result.navigationParams.screenInstanceId);
  37. result.tabLabel = getTabLabel(params);
  38. result.tabIcon = getTabIcon(params);
  39. result.animateScreenTransitions = params.getBoolean("animated", true);
  40. return result;
  41. }
  42. private static Drawable getTabIcon(Bundle params) {
  43. Drawable tabIcon = null;
  44. if (hasKey(params, "icon")) {
  45. tabIcon = ImageLoader.loadImage(params.getString("icon"));
  46. }
  47. return tabIcon;
  48. }
  49. private static String getTabLabel(Bundle params) {
  50. String tabLabel = null;
  51. if (hasKey(params, "label")) {
  52. tabLabel = params.getString("label");
  53. }
  54. return tabLabel;
  55. }
  56. private static List<PageParams> parseTopTabs(Bundle params) {
  57. List<PageParams> topTabParams = null;
  58. if (hasKey(params, TOP_TABS)) {
  59. topTabParams = new TopTabParamsParser().parse(params.getBundle(TOP_TABS));
  60. }
  61. return topTabParams;
  62. }
  63. List<ScreenParams> parseTabs(Bundle params) {
  64. return parseBundle(params, new ParseStrategy<ScreenParams>() {
  65. @Override
  66. public ScreenParams parse(Bundle screen) {
  67. return ScreenParamsParser.parse(screen);
  68. }
  69. });
  70. }
  71. }