react-native-navigation的迁移库

RNNBottomTabOptions.m 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. [viewController.navigationController setTabBarItem:tabItem];
  14. }
  15. if (self.badge) {
  16. NSString *badge = [RCTConvert NSString:self.badge];
  17. if (viewController.navigationController) {
  18. viewController.navigationController.tabBarItem.badgeValue = badge;
  19. } else {
  20. viewController.tabBarItem.badgeValue = badge;
  21. }
  22. }
  23. if (self.visible) {
  24. [viewController.tabBarController setSelectedIndex:[viewController.tabBarController.viewControllers indexOfObject:viewController]];
  25. }
  26. [self resetOptions];
  27. }
  28. -(void)resetOptions {
  29. self.title = nil;
  30. self.badge = nil;
  31. self.visible = nil;
  32. self.icon = nil;
  33. self.testID = nil;
  34. }
  35. @end