react-native-navigation的迁移库

RNNBottomTabsOptions.m 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.visible) {
  13. [((RNNTabBarController *)viewController.tabBarController) setTabBarHidden:![self.visible boolValue] animated:[self.animate boolValue]];
  14. } else {
  15. [((RNNTabBarController *)viewController.tabBarController) setTabBarHidden:NO animated:NO];
  16. }
  17. if (self.testID) {
  18. viewController.tabBarController.tabBar.accessibilityIdentifier = self.testID;
  19. }
  20. if (self.drawBehind) {
  21. if ([self.drawBehind boolValue]) {
  22. [viewController setExtendedLayoutIncludesOpaqueBars:YES];
  23. viewController.edgesForExtendedLayout |= UIRectEdgeBottom;
  24. } else {
  25. [viewController setExtendedLayoutIncludesOpaqueBars:NO];
  26. viewController.edgesForExtendedLayout &= ~UIRectEdgeBottom;
  27. }
  28. }
  29. if (self.backgroundColor) {
  30. viewController.tabBarController.tabBar.barTintColor = [RCTConvert UIColor:self.backgroundColor];
  31. } else {
  32. viewController.tabBarController.tabBar.barTintColor = nil;
  33. }
  34. if (self.translucent) {
  35. viewController.tabBarController.tabBar.translucent = [self.translucent boolValue];
  36. } else {
  37. viewController.tabBarController.tabBar.translucent = NO;
  38. }
  39. if (self.hideShadow) {
  40. viewController.tabBarController.tabBar.clipsToBounds = [self.hideShadow boolValue];
  41. }
  42. if (self.tabBarTextFont) {
  43. NSMutableDictionary* tabBarTitleTextAttributes = [NSMutableDictionary new];
  44. tabBarTitleTextAttributes[NSFontAttributeName] = self.tabBarTextFont;
  45. for (UITabBarItem* item in viewController.tabBarController.tabBar.items) {
  46. [item setTitleTextAttributes:tabBarTitleTextAttributes forState:UIControlStateNormal];
  47. }
  48. }
  49. if (self.tabColor) {
  50. viewController.tabBarController.tabBar.unselectedItemTintColor = [RCTConvert UIColor:self.tabColor];
  51. }
  52. if (self.selectedTabColor) {
  53. viewController.tabBarController.tabBar.tintColor = [RCTConvert UIColor:self.selectedTabColor];
  54. }
  55. [self resetOptions];
  56. }
  57. -(UIFont *)tabBarTextFont {
  58. if (self.fontFamily) {
  59. return [UIFont fontWithName:self.fontFamily size:self.tabBarTextFontSizeValue];
  60. }
  61. else if (self.fontSize) {
  62. return [UIFont systemFontOfSize:self.tabBarTextFontSizeValue];
  63. }
  64. else {
  65. return nil;
  66. }
  67. }
  68. -(CGFloat)tabBarTextFontSizeValue {
  69. return self.fontSize ? [self.fontSize floatValue] : 10;
  70. }
  71. - (void)resetOptions {
  72. self.currentTabId = nil;
  73. self.currentTabIndex = nil;
  74. }
  75. @end