react-native-navigation的迁移库

RNNBottomTabOptions.m 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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)mergeWith:(NSDictionary *)otherOptions {
  29. for (id key in otherOptions) {
  30. [self setValue:[otherOptions objectForKey:key] forKey:key];
  31. }
  32. }
  33. -(void)resetOptions {
  34. self.title = nil;
  35. self.badge = nil;
  36. self.visible = nil;
  37. self.icon = nil;
  38. self.testID = nil;
  39. }
  40. @end