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.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.edgesForExtendedLayout |= UIRectEdgeBottom;
  23. } else {
  24. viewController.edgesForExtendedLayout &= ~UIRectEdgeBottom;
  25. }
  26. }
  27. if (self.backgroundColor) {
  28. viewController.tabBarController.tabBar.barTintColor = [RCTConvert UIColor:self.backgroundColor];
  29. } else {
  30. viewController.tabBarController.tabBar.barTintColor = nil;
  31. }
  32. if (self.translucent) {
  33. viewController.tabBarController.tabBar.translucent = [self.translucent boolValue];
  34. } else {
  35. viewController.tabBarController.tabBar.translucent = NO;
  36. }
  37. if (self.hideShadow) {
  38. viewController.tabBarController.tabBar.clipsToBounds = [self.hideShadow boolValue];
  39. }
  40. if (self.tabBarTextFont) {
  41. NSMutableDictionary* tabBarTitleTextAttributes = [NSMutableDictionary new];
  42. tabBarTitleTextAttributes[NSFontAttributeName] = self.tabBarTextFont;
  43. for (UITabBarItem* item in viewController.tabBarController.tabBar.items) {
  44. [item setTitleTextAttributes:tabBarTitleTextAttributes forState:UIControlStateNormal];
  45. }
  46. }
  47. if (self.tabColor) {
  48. viewController.tabBarController.tabBar.unselectedItemTintColor = [RCTConvert UIColor:self.tabColor];
  49. }
  50. if (self.selectedTabColor) {
  51. viewController.tabBarController.tabBar.tintColor = [RCTConvert UIColor:self.selectedTabColor];
  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