react-native-navigation的迁移库

RNNBottomTabsOptions.m 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #import "RNNBottomTabsOptions.h"
  2. #import "RNNTabBarController.h"
  3. extern const NSInteger BLUR_TOPBAR_TAG;
  4. @implementation RNNBottomTabsOptions
  5. - (void)applyOn:(UIViewController *)viewController {
  6. if (self.currentTabIndex) {
  7. [viewController.tabBarController setSelectedIndex:[self.currentTabIndex unsignedIntegerValue]];
  8. }
  9. if (self.currentTabId) {
  10. [(RNNTabBarController*)viewController.tabBarController setSelectedIndexByComponentID:self.currentTabId];
  11. }
  12. if (self.hidden) {
  13. [((RNNTabBarController *)viewController.tabBarController) setTabBarHidden:[self.hidden boolValue] animated:[self.animateHide boolValue]];
  14. }
  15. if (self.testID) {
  16. viewController.tabBarController.tabBar.accessibilityIdentifier = self.testID;
  17. }
  18. if (self.drawUnder) {
  19. if ([self.drawUnder boolValue]) {
  20. viewController.edgesForExtendedLayout |= UIRectEdgeBottom;
  21. } else {
  22. viewController.edgesForExtendedLayout &= ~UIRectEdgeBottom;
  23. }
  24. }
  25. if (self.backgroundColor) {
  26. viewController.tabBarController.tabBar.barTintColor = [RCTConvert UIColor:self.backgroundColor];
  27. }
  28. if (self.translucent) {
  29. viewController.tabBarController.tabBar.translucent = [self.translucent boolValue];
  30. }
  31. if (self.hideShadow) {
  32. viewController.tabBarController.tabBar.clipsToBounds = [self.hideShadow boolValue];
  33. }
  34. if (self.tabBarTextFont || self.textColor) {
  35. NSMutableDictionary* tabBarTitleTextAttributes = [NSMutableDictionary new];
  36. if (self.textColor) {
  37. tabBarTitleTextAttributes[NSForegroundColorAttributeName] = [RCTConvert UIColor:self.textColor];
  38. }
  39. if (self.tabBarTextFont) {
  40. tabBarTitleTextAttributes[NSFontAttributeName] = self.tabBarTextFont;
  41. }
  42. for (UITabBarItem* item in viewController.tabBarController.tabBar.items) {
  43. [item setTitleTextAttributes:tabBarTitleTextAttributes forState:UIControlStateNormal];
  44. }
  45. }
  46. if (self.selectedTextColor){
  47. for (UITabBarItem* item in viewController.tabBarController.tabBar.items) {
  48. NSMutableDictionary* tabBarTitleTextAttributes = [NSMutableDictionary new];
  49. tabBarTitleTextAttributes[NSForegroundColorAttributeName] = [RCTConvert UIColor:self.selectedTextColor];
  50. [item setTitleTextAttributes:tabBarTitleTextAttributes forState:UIControlStateSelected];
  51. }
  52. }
  53. [self resetOptions];
  54. }
  55. -(UIFont *)tabBarTextFont {
  56. if (self.fontFamily) {
  57. return [UIFont fontWithName:self.fontFamily size:self.tabBarTextFontSizeValue];
  58. }
  59. else if (self.fontSize) {
  60. return [UIFont systemFontOfSize:self.tabBarTextFontSizeValue];
  61. }
  62. else {
  63. return nil;
  64. }
  65. }
  66. -(CGFloat)tabBarTextFontSizeValue {
  67. return self.fontSize ? [self.fontSize floatValue] : 10;
  68. }
  69. - (void)resetOptions {
  70. self.currentTabId = nil;
  71. self.currentTabIndex = nil;
  72. }
  73. @end