react-native-navigation的迁移库

RNNNavigationOptions.m 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.topBarTextColor = [navigationOptions objectForKey:@"topBarTextColor"];
  13. self.screenBackgroundColor = [navigationOptions objectForKey:@"screenBackgroundColor"];
  14. self.topBarTextFontFamily = [navigationOptions objectForKey:@"topBarTextFontFamily"];
  15. self.topBarHidden = [navigationOptions objectForKey:@"topBarHidden"];
  16. self.topBarHideOnScroll = [navigationOptions objectForKey:@"topBarHideOnScroll"];
  17. self.topBarButtonColor = [navigationOptions objectForKey:@"topBarButtonColor"];
  18. self.topBarTranslucent = [navigationOptions objectForKey:@"topBarTranslucent"];
  19. self.setTabBadge = [navigationOptions objectForKey:@"setTabBadge"];
  20. return self;
  21. }
  22. -(void)mergeWith:(NSDictionary *)otherOptions {
  23. for (id key in otherOptions) {
  24. [self setValue:[otherOptions objectForKey:key] forKey:key];
  25. }
  26. }
  27. -(void)applyOn:(UIViewController*)viewController {
  28. if (self.topBarBackgroundColor) {
  29. UIColor* backgroundColor = [RCTConvert UIColor:self.topBarBackgroundColor];
  30. viewController.navigationController.navigationBar.barTintColor = backgroundColor;
  31. } else {
  32. viewController.navigationController.navigationBar.barTintColor = nil;
  33. }
  34. if (self.title) {
  35. viewController.navigationItem.title = self.title;
  36. }
  37. if (self.topBarTextColor) {
  38. UIColor* textColor = [RCTConvert UIColor:self.topBarTextColor];
  39. NSMutableDictionary* navigationBarTitleTextAttributes = [NSMutableDictionary dictionaryWithDictionary:@{NSForegroundColorAttributeName: textColor}];
  40. if (self.topBarTextFontFamily) {
  41. [navigationBarTitleTextAttributes addEntriesFromDictionary:@{NSFontAttributeName: [UIFont fontWithName:self.topBarTextFontFamily size:20]}];
  42. }
  43. viewController.navigationController.navigationBar.titleTextAttributes = navigationBarTitleTextAttributes;
  44. } else if (self.topBarTextFontFamily){
  45. viewController.navigationController.navigationBar.titleTextAttributes = @{NSFontAttributeName: [UIFont fontWithName:self.topBarTextFontFamily size:20]};
  46. }
  47. if (self.screenBackgroundColor) {
  48. UIColor* screenColor = [RCTConvert UIColor:self.screenBackgroundColor];
  49. viewController.view.backgroundColor = screenColor;
  50. }
  51. if (self.topBarHidden){
  52. if ([self.topBarHidden boolValue]) {
  53. [viewController.navigationController setNavigationBarHidden:YES animated:YES];
  54. } else {
  55. [viewController.navigationController setNavigationBarHidden:NO animated:YES];
  56. }
  57. }
  58. if (self.topBarHideOnScroll) {
  59. BOOL topBarHideOnScrollBool = [self.topBarHideOnScroll boolValue];
  60. if (topBarHideOnScrollBool) {
  61. viewController.navigationController.hidesBarsOnSwipe = YES;
  62. } else {
  63. viewController.navigationController.hidesBarsOnSwipe = NO;
  64. }
  65. }
  66. if (self.topBarButtonColor) {
  67. UIColor* buttonColor = [RCTConvert UIColor:self.topBarButtonColor];
  68. viewController.navigationController.navigationBar.tintColor = buttonColor;
  69. } else {
  70. viewController.navigationController.navigationBar.tintColor = nil;
  71. if (self.setTabBadge) {
  72. NSString *badge = [RCTConvert NSString:self.setTabBadge];
  73. if (viewController.navigationController) {
  74. viewController.navigationController.tabBarItem.badgeValue = badge;
  75. } else {
  76. viewController.tabBarItem.badgeValue = badge;
  77. }
  78. }
  79. if (self.topBarTranslucent) {
  80. if ([self.topBarTranslucent boolValue]) {
  81. viewController.navigationController.navigationBar.translucent = YES;
  82. } else {
  83. viewController.navigationController.navigationBar.translucent = NO;
  84. }
  85. }
  86. }
  87. }
  88. @end