react-native-navigation的迁移库

RNNTopBarOptions.m 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #import "RNNTopBarOptions.h"
  2. #import "RNNNavigationButtons.h"
  3. #import "RNNCustomTitleView.h"
  4. @interface RNNTopBarOptions ()
  5. @property (nonatomic, strong) RNNNavigationButtons* navigationButtons;
  6. @end
  7. @implementation RNNTopBarOptions
  8. - (instancetype)initWithDict:(NSDictionary *)dict {
  9. self = [super initWithDict:dict];
  10. self.title.subtitle = self.subtitle;
  11. return self;
  12. }
  13. - (void)mergeWith:(NSDictionary *)otherOptions {
  14. [super mergeWith:otherOptions];
  15. self.title.subtitle = self.subtitle;
  16. }
  17. - (void)applyOn:(UIViewController*)viewController {
  18. [self.title applyOn:viewController];
  19. [self.largeTitle applyOn:viewController];
  20. [self.backButton applyOn:viewController];
  21. if (@available(iOS 11.0, *)) {
  22. if ([self.searchBar boolValue] && !viewController.navigationItem.searchController) {
  23. UISearchController *search = [[UISearchController alloc]initWithSearchResultsController:nil];
  24. search.dimsBackgroundDuringPresentation = NO;
  25. if ([viewController conformsToProtocol:@protocol(UISearchResultsUpdating)]) {
  26. [search setSearchResultsUpdater:((UIViewController <UISearchResultsUpdating> *) viewController)];
  27. }
  28. search.searchBar.delegate = (id<UISearchBarDelegate>)viewController;
  29. if (self.searchBarPlaceholder) {
  30. search.searchBar.placeholder = self.searchBarPlaceholder;
  31. }
  32. viewController.navigationItem.searchController = search;
  33. viewController.navigationItem.hidesSearchBarWhenScrolling = [self.searchBarHiddenWhenScrolling boolValue];
  34. // Fixes #3450, otherwise, UIKit will infer the presentation context to be the root most view controller
  35. viewController.definesPresentationContext = YES;
  36. }
  37. }
  38. if (self.drawBehind) {
  39. if ([self.drawBehind boolValue]) {
  40. viewController.edgesForExtendedLayout |= UIRectEdgeTop;
  41. } else {
  42. viewController.edgesForExtendedLayout &= ~UIRectEdgeTop;
  43. }
  44. } else {
  45. viewController.edgesForExtendedLayout = UIRectEdgeAll;
  46. }
  47. if (self.rightButtons || self.leftButtons) {
  48. _navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:(RNNRootViewController*)viewController];
  49. [_navigationButtons applyLeftButtons:self.leftButtons rightButtons:self.rightButtons defaultLeftButtonStyle:self.leftButtonStyle defaultRightButtonStyle:self.rightButtonStyle];
  50. }
  51. [self applyOnNavigationController:viewController.navigationController];
  52. self.rightButtons = nil;
  53. self.leftButtons = nil;
  54. }
  55. - (void)applyOnNavigationController:(UINavigationController *)navigationController {
  56. if (self.testID) {
  57. navigationController.navigationBar.accessibilityIdentifier = self.testID;
  58. }
  59. if (self.visible) {
  60. [navigationController setNavigationBarHidden:![self.visible boolValue] animated:[self.animate boolValue]];
  61. } else {
  62. [navigationController setNavigationBarHidden:NO animated:NO];
  63. }
  64. if (self.hideOnScroll) {
  65. navigationController.hidesBarsOnSwipe = [self.hideOnScroll boolValue];
  66. } else {
  67. navigationController.hidesBarsOnSwipe = NO;
  68. }
  69. if (self.noBorder) {
  70. if ([self.noBorder boolValue]) {
  71. navigationController.navigationBar
  72. .shadowImage = [[UIImage alloc] init];
  73. } else {
  74. navigationController.navigationBar
  75. .shadowImage = nil;
  76. }
  77. }
  78. if (self.barStyle) {
  79. navigationController.navigationBar.barStyle = [RCTConvert UIBarStyle:self.barStyle];
  80. } else {
  81. navigationController.navigationBar.barStyle = UIBarStyleDefault;
  82. }
  83. [self.background applyOnNavigationController:navigationController];
  84. }
  85. - (void)setRightButtonColor:(NSNumber *)rightButtonColor {
  86. _rightButtonColor = rightButtonColor;
  87. _rightButtonStyle.color = rightButtonColor;
  88. }
  89. - (void)setRightButtonDisabledColor:(NSNumber *)rightButtonDisabledColor {
  90. _rightButtonDisabledColor = rightButtonDisabledColor;
  91. _rightButtonStyle.disabledColor = rightButtonDisabledColor;
  92. }
  93. - (void)setLeftButtonColor:(NSNumber *)leftButtonColor {
  94. _leftButtonColor = leftButtonColor;
  95. _leftButtonStyle.color = leftButtonColor;
  96. }
  97. - (void)setLeftButtonDisabledColor:(NSNumber *)leftButtonDisabledColor {
  98. _leftButtonDisabledColor = leftButtonDisabledColor;
  99. _leftButtonStyle.disabledColor = leftButtonDisabledColor;
  100. }
  101. - (void)setRightButtons:(id)rightButtons {
  102. if ([rightButtons isKindOfClass:[NSArray class]]) {
  103. _rightButtons = rightButtons;
  104. } else if ([rightButtons isKindOfClass:[NSDictionary class]]) {
  105. if (rightButtons[@"id"]) {
  106. _rightButtons = @[rightButtons];
  107. } else {
  108. [_rightButtonStyle mergeWith:rightButtons];
  109. }
  110. } else {
  111. _rightButtons = rightButtons;
  112. }
  113. }
  114. - (void)setLeftButtons:(id)leftButtons {
  115. if ([leftButtons isKindOfClass:[NSArray class]]) {
  116. _leftButtons = leftButtons;
  117. } else if ([leftButtons isKindOfClass:[NSDictionary class]]) {
  118. if (leftButtons[@"id"]) {
  119. _leftButtons = @[leftButtons];
  120. } else {
  121. [_leftButtonStyle mergeWith:leftButtons];
  122. }
  123. } else {
  124. _leftButtons = leftButtons;
  125. }
  126. }
  127. @end