react-native-navigation的迁移库

BottomTabs.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package com.reactnativenavigation.views;
  2. import android.content.Context;
  3. import android.graphics.Color;
  4. import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
  5. import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
  6. import com.reactnativenavigation.animation.VisibilityAnimator;
  7. import com.reactnativenavigation.params.AppStyle;
  8. import com.reactnativenavigation.params.ScreenParams;
  9. import com.reactnativenavigation.params.StyleParams;
  10. import com.reactnativenavigation.utils.ViewUtils;
  11. import java.util.List;
  12. public class BottomTabs extends AHBottomNavigation {
  13. private VisibilityAnimator visibilityAnimator;
  14. public BottomTabs(Context context) {
  15. super(context);
  16. setForceTint(true);
  17. setId(ViewUtils.generateViewId());
  18. createVisibilityAnimator();
  19. setStyle();
  20. }
  21. public void addTabs(List<ScreenParams> params, OnTabSelectedListener onTabSelectedListener) {
  22. for (ScreenParams screenParams : params) {
  23. AHBottomNavigationItem item = new AHBottomNavigationItem(screenParams.tabLabel, screenParams.tabIcon,
  24. Color.GRAY);
  25. addItem(item);
  26. setOnTabSelectedListener(onTabSelectedListener);
  27. }
  28. }
  29. public void setStyleFromScreen(StyleParams params) {
  30. if (params.bottomTabsColor.hasColor()) {
  31. setBackgroundColor(params.bottomTabsColor);
  32. }
  33. if (params.bottomTabsButtonColor.hasColor()) {
  34. setInactiveColor(params.bottomTabsButtonColor.getColor());
  35. }
  36. if (params.selectedBottomTabsButtonColor.hasColor()) {
  37. setAccentColor(params.selectedBottomTabsButtonColor.getColor());
  38. }
  39. setForceTitlesDisplay(params.forceTitlesDisplay);
  40. setVisibility(params.bottomTabsHidden, true);
  41. }
  42. public void setVisibility(boolean hidden, boolean animated) {
  43. if (visibilityAnimator != null) {
  44. visibilityAnimator.setVisible(!hidden, animated);
  45. } else {
  46. setVisibility(hidden);
  47. }
  48. }
  49. private void setBackgroundColor(StyleParams.Color bottomTabsColor) {
  50. if (bottomTabsColor.hasColor()) {
  51. setDefaultBackgroundColor(bottomTabsColor.getColor());
  52. } else {
  53. setDefaultBackgroundColor(Color.WHITE);
  54. }
  55. }
  56. private void setVisibility(boolean bottomTabsHidden) {
  57. setVisibility(bottomTabsHidden ? GONE : VISIBLE);
  58. }
  59. private void createVisibilityAnimator() {
  60. ViewUtils.runOnPreDraw(this, new Runnable() {
  61. @Override
  62. public void run() {
  63. visibilityAnimator = new VisibilityAnimator(BottomTabs.this,
  64. VisibilityAnimator.HideDirection.Down,
  65. getHeight());
  66. }
  67. });
  68. }
  69. private void setStyle() {
  70. if (hasBadgeBackgroundColor()) {
  71. setNotificationBackgroundColor(AppStyle.appStyle.bottomTabBadgeBackgroundColor.getColor());
  72. }
  73. if (hasBadgeTextColor()) {
  74. setNotificationTextColor(AppStyle.appStyle.bottomTabBadgeTextColor.getColor());
  75. }
  76. }
  77. private boolean hasBadgeTextColor() {
  78. return AppStyle.appStyle.bottomTabBadgeTextColor != null && AppStyle.appStyle.bottomTabBadgeTextColor.hasColor();
  79. }
  80. private boolean hasBadgeBackgroundColor() {
  81. return AppStyle.appStyle.bottomTabBadgeBackgroundColor != null && AppStyle.appStyle.bottomTabBadgeBackgroundColor.hasColor();
  82. }
  83. }