react-native-navigation的迁移库

RNNNavigationOptions.m 1.9KB

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