react-native-navigation的迁移库

RNNNavigationOptions.m 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. self = [super init];
  9. self.topBarBackgroundColor = [navigationOptions objectForKey:@"topBarBackgroundColor"];
  10. self.statusBarHidden = [navigationOptions objectForKey:@"statusBarHidden"];
  11. self.title = [navigationOptions objectForKey:@"title"];
  12. self.screenBackgroundColor = [navigationOptions objectForKey:@"screenBackgroundColor"];
  13. self.setTabBadge = [navigationOptions objectForKey:@"setTabBadge"];
  14. self.topBarTextFontFamily = [navigationOptions objectForKey:@"topBarTextFontFamily"];
  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. } else {
  27. viewController.navigationController.navigationBar.barTintColor = nil;
  28. }
  29. if (self.title) {
  30. viewController.navigationItem.title = self.title;
  31. }
  32. if (self.topBarTextColor) {
  33. UIColor* textColor = [RCTConvert UIColor:self.topBarTextColor];
  34. NSMutableDictionary* navigationBarTitleTextAttributes = [NSMutableDictionary dictionaryWithDictionary:@{NSForegroundColorAttributeName: textColor}];
  35. if (self.topBarTextFontFamily) {
  36. [navigationBarTitleTextAttributes addEntriesFromDictionary:@{NSFontAttributeName: [UIFont fontWithName:self.topBarTextFontFamily size:20]}];
  37. }
  38. viewController.navigationController.navigationBar.titleTextAttributes = navigationBarTitleTextAttributes;
  39. } else if (self.topBarTextFontFamily){
  40. viewController.navigationController.navigationBar.titleTextAttributes = @{NSFontAttributeName: [UIFont fontWithName:self.topBarTextFontFamily size:20]};
  41. }
  42. if (self.screenBackgroundColor) {
  43. UIColor* screenColor = [RCTConvert UIColor:self.screenBackgroundColor];
  44. viewController.view.backgroundColor = screenColor;
  45. }
  46. if (self.setTabBadge) {
  47. NSString *badge = [RCTConvert NSString:self.setTabBadge];
  48. if (viewController.navigationController) {
  49. viewController.navigationController.tabBarItem.badgeValue = badge;
  50. } else {
  51. viewController.tabBarItem.badgeValue = badge;
  52. }
  53. }
  54. }
  55. @end