react-native-navigation的迁移库

RNNNavigationOptions.m 4.1KB

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