react-native-navigation的迁移库

RNNBottomTabOptions.m 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #import "RNNBottomTabOptions.h"
  2. @implementation RNNBottomTabOptions
  3. -(instancetype)initWithDict:(NSDictionary *)tabItemDict {
  4. self = [super init];
  5. [self mergeWith:tabItemDict];
  6. self.tag = [tabItemDict[@"tag"] integerValue];
  7. return self;
  8. }
  9. - (void)applyOn:(UIViewController *)viewController {
  10. if (self.title || self.icon) {
  11. UIImage *iconImage = nil;
  12. if (self.disableIconTint) {
  13. iconImage = [[RCTConvert UIImage:self.icon] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  14. } else {
  15. iconImage = [RCTConvert UIImage:self.icon];
  16. }
  17. UITabBarItem* tabItem = [[UITabBarItem alloc] initWithTitle:self.title image:iconImage tag:self.tag];
  18. tabItem.accessibilityIdentifier = self.testID;
  19. if (self.iconInsets && ![self.iconInsets isKindOfClass:[NSNull class]]) {
  20. id topInset = self.iconInsets[@"top"];
  21. id leftInset = self.iconInsets[@"left"];
  22. id bottomInset = self.iconInsets[@"bottom"];
  23. id rightInset = self.iconInsets[@"right"];
  24. CGFloat top = topInset != (id)[NSNull null] ? [RCTConvert CGFloat:topInset] : 0;
  25. CGFloat left = topInset != (id)[NSNull null] ? [RCTConvert CGFloat:leftInset] : 0;
  26. CGFloat bottom = topInset != (id)[NSNull null] ? [RCTConvert CGFloat:bottomInset] : 0;
  27. CGFloat right = topInset != (id)[NSNull null] ? [RCTConvert CGFloat:rightInset] : 0;
  28. tabItem.imageInsets = UIEdgeInsetsMake(top, left, bottom, right);
  29. }
  30. [viewController.navigationController setTabBarItem:tabItem];
  31. }
  32. if (self.selectedIcon) {
  33. UIImage *selectedIconImage = nil;
  34. if (self.disableSelectedIconTint) {
  35. selectedIconImage = [[RCTConvert UIImage:self.selectedIcon] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  36. } else {
  37. selectedIconImage = [RCTConvert UIImage:self.selectedIcon];
  38. }
  39. if (viewController.navigationController) {
  40. viewController.navigationController.tabBarItem.selectedImage = selectedIconImage;
  41. } else {
  42. viewController.tabBarItem.selectedImage = selectedIconImage;
  43. }
  44. }
  45. if (self.badge) {
  46. NSString *badge = nil;
  47. if (self.badge != nil && ![self.badge isEqual:[NSNull null]]) {
  48. badge = [RCTConvert NSString:self.badge];
  49. }
  50. if (viewController.navigationController) {
  51. viewController.navigationController.tabBarItem.badgeValue = badge;
  52. } else {
  53. viewController.tabBarItem.badgeValue = badge;
  54. }
  55. }
  56. if (self.visible) {
  57. [viewController.tabBarController setSelectedIndex:[viewController.tabBarController.viewControllers indexOfObject:viewController]];
  58. }
  59. [self resetOptions];
  60. }
  61. -(void)resetOptions {
  62. self.title = nil;
  63. self.badge = nil;
  64. self.visible = nil;
  65. self.icon = nil;
  66. self.testID = nil;
  67. self.iconInsets = nil;
  68. }
  69. @end