react-native-navigation的迁移库

RNNBottomTabOptions.m 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. UITabBarItem* tabItem = [[UITabBarItem alloc] initWithTitle:self.title image:[RCTConvert UIImage:self.icon] tag:self.tag];
  12. tabItem.accessibilityIdentifier = self.testID;
  13. if (self.iconInsets && ![self.iconInsets isKindOfClass:[NSNull class]]) {
  14. id topInset = self.iconInsets[@"top"];
  15. id leftInset = self.iconInsets[@"left"];
  16. id bottomInset = self.iconInsets[@"bottom"];
  17. id rightInset = self.iconInsets[@"right"];
  18. CGFloat top = topInset != (id)[NSNull null] ? [RCTConvert CGFloat:topInset] : 0;
  19. CGFloat left = topInset != (id)[NSNull null] ? [RCTConvert CGFloat:leftInset] : 0;
  20. CGFloat bottom = topInset != (id)[NSNull null] ? [RCTConvert CGFloat:bottomInset] : 0;
  21. CGFloat right = topInset != (id)[NSNull null] ? [RCTConvert CGFloat:rightInset] : 0;
  22. tabItem.imageInsets = UIEdgeInsetsMake(top, left, bottom, right);
  23. }
  24. [viewController.navigationController setTabBarItem:tabItem];
  25. }
  26. if (self.badge) {
  27. NSString *badge = nil;
  28. if (self.badge != nil && ![self.badge isEqual:[NSNull null]]) {
  29. badge = [RCTConvert NSString:self.badge];
  30. }
  31. if (viewController.navigationController) {
  32. viewController.navigationController.tabBarItem.badgeValue = badge;
  33. } else {
  34. viewController.tabBarItem.badgeValue = badge;
  35. }
  36. }
  37. if (self.visible) {
  38. [viewController.tabBarController setSelectedIndex:[viewController.tabBarController.viewControllers indexOfObject:viewController]];
  39. }
  40. [self resetOptions];
  41. }
  42. -(void)resetOptions {
  43. self.title = nil;
  44. self.badge = nil;
  45. self.visible = nil;
  46. self.icon = nil;
  47. self.testID = nil;
  48. self.iconInsets = nil;
  49. }
  50. @end