react-native-navigation的迁移库

RNNBottomTabsOptions.m 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. }
  15. if (self.testID) {
  16. viewController.tabBarController.tabBar.accessibilityIdentifier = self.testID;
  17. }
  18. if (self.drawBehind) {
  19. if ([self.drawBehind 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) {
  35. NSMutableDictionary* tabBarTitleTextAttributes = [NSMutableDictionary new];
  36. tabBarTitleTextAttributes[NSFontAttributeName] = self.tabBarTextFont;
  37. for (UITabBarItem* item in viewController.tabBarController.tabBar.items) {
  38. [item setTitleTextAttributes:tabBarTitleTextAttributes forState:UIControlStateNormal];
  39. }
  40. }
  41. if (self.tabColor) {
  42. viewController.tabBarController.tabBar.unselectedItemTintColor = [RCTConvert UIColor:self.tabColor];
  43. }
  44. if (self.selectedTabColor) {
  45. viewController.tabBarController.tabBar.tintColor = [RCTConvert UIColor:self.selectedTabColor];
  46. }
  47. [self resetOptions];
  48. }
  49. -(UIFont *)tabBarTextFont {
  50. if (self.fontFamily) {
  51. return [UIFont fontWithName:self.fontFamily size:self.tabBarTextFontSizeValue];
  52. }
  53. else if (self.fontSize) {
  54. return [UIFont systemFontOfSize:self.tabBarTextFontSizeValue];
  55. }
  56. else {
  57. return nil;
  58. }
  59. }
  60. -(CGFloat)tabBarTextFontSizeValue {
  61. return self.fontSize ? [self.fontSize floatValue] : 10;
  62. }
  63. - (void)resetOptions {
  64. self.currentTabId = nil;
  65. self.currentTabIndex = nil;
  66. }
  67. @end