react-native-navigation的迁移库

RNNNavigationOptions.m 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #import "RNNNavigationOptions.h"
  2. #import <React/RCTConvert.h>
  3. @implementation RNNNavigationOptions
  4. -(instancetype)init {
  5. return [self initWithDict:@{}];
  6. }
  7. -(instancetype)initWithDict:(NSDictionary *)navigationOptions {
  8. if(self = [super init]) {
  9. self.topBarBackgroundColor = [navigationOptions objectForKey:@"topBarBackgroundColor"];
  10. self.statusBarHidden = [navigationOptions objectForKey:@"statusBarHidden"];
  11. self.title = [navigationOptions objectForKey:@"title"];
  12. self.topBarTextColor = [navigationOptions objectForKey:@"topBarTextColor"];
  13. self.setTabBadge = [navigationOptions objectForKey:@"setTabBadge"];
  14. }
  15. return self;
  16. }
  17. -(void)mergeWith:(NSDictionary *)otherOptions {
  18. for (id key in otherOptions) {
  19. [self setValue:[otherOptions objectForKey:key] forKey:key];
  20. }
  21. }
  22. -(void)applyOn:(UIViewController*)viewController{
  23. if (self.topBarBackgroundColor) {
  24. UIColor* backgroundColor = [RCTConvert UIColor:self.topBarBackgroundColor];
  25. viewController.navigationController.navigationBar.barTintColor = backgroundColor;
  26. }
  27. if (self.title) {
  28. viewController.navigationItem.title = self.title;
  29. }
  30. if (self.topBarTextColor) {
  31. UIColor* textColor = [RCTConvert UIColor:self.topBarTextColor];
  32. viewController.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:textColor};
  33. }
  34. if (self.setTabBadge) {
  35. NSString *badge = [RCTConvert NSString:self.setTabBadge];
  36. if (viewController.navigationController) {
  37. viewController.navigationController.tabBarItem.badgeValue = badge;
  38. }
  39. else {
  40. viewController.tabBarItem.badgeValue = badge;
  41. }
  42. }
  43. }
  44. @end