react-native-navigation的迁移库

RNNViewControllerPresenter.m 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #import "RNNViewControllerPresenter.h"
  2. #import "UIViewController+RNNOptions.h"
  3. #import "UITabBarController+RNNOptions.h"
  4. #import "RNNNavigationButtons.h"
  5. #import "RCTConvert+Modal.h"
  6. @interface RNNViewControllerPresenter()
  7. @property (nonatomic, strong) RNNNavigationButtons* navigationButtons;
  8. @end
  9. @implementation RNNViewControllerPresenter
  10. - (void)applyOptions:(RNNNavigationOptions *)initialOptions {
  11. [super applyOptions:initialOptions];
  12. RNNNavigationOptions* options = [initialOptions withDefault:self.defaultOptions];
  13. UIViewController* viewController = self.bindedViewController;
  14. [viewController rnn_setBackgroundImage:[options.backgroundImage getWithDefaultValue:nil]];
  15. [viewController rnn_setModalPresentationStyle:[RCTConvert UIModalPresentationStyle:[options.modalPresentationStyle getWithDefaultValue:@"fullScreen"]]];
  16. [viewController rnn_setModalTransitionStyle:[RCTConvert UIModalTransitionStyle:[options.modalTransitionStyle getWithDefaultValue:@"coverVertical"]]];
  17. [viewController rnn_setDrawBehindTopBar:[options.topBar.drawBehind getWithDefaultValue:NO]];
  18. [viewController rnn_setNavigationItemTitle:[options.topBar.title.text getWithDefaultValue:nil]];
  19. [viewController rnn_setTopBarPrefersLargeTitle:[options.topBar.largeTitle.visible getWithDefaultValue:NO]];
  20. [viewController rnn_setDrawBehindTabBar:[options.bottomTabs.drawBehind getWithDefaultValue:NO]];
  21. [viewController rnn_setTabBarItemBadge:[options.bottomTab.badge getWithDefaultValue:nil]];
  22. [viewController rnn_setTabBarItemBadgeColor:[options.bottomTab.badgeColor getWithDefaultValue:nil]];
  23. [viewController rnn_setStatusBarBlur:[options.statusBar.blur getWithDefaultValue:NO]];
  24. [viewController rnn_setStatusBarStyle:[options.statusBar.style getWithDefaultValue:@"default"] animated:[options.statusBar.animate getWithDefaultValue:YES]];
  25. [viewController rnn_setBackButtonVisible:[options.topBar.backButton.visible getWithDefaultValue:YES]];
  26. if (options.layout.backgroundColor.hasValue) {
  27. [viewController rnn_setBackgroundColor:options.layout.backgroundColor.get];
  28. }
  29. if (options.topBar.searchBar.hasValue) {
  30. [viewController rnn_setSearchBarWithPlaceholder:[options.topBar.searchBarPlaceholder getWithDefaultValue:@""]];
  31. }
  32. if ((options.topBar.leftButtons || options.topBar.rightButtons) && !_navigationButtons) {
  33. _navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:(RNNRootViewController*)viewController];
  34. [_navigationButtons applyLeftButtons:options.topBar.leftButtons rightButtons:options.topBar.rightButtons defaultLeftButtonStyle:options.topBar.leftButtonStyle defaultRightButtonStyle:options.topBar.rightButtonStyle];
  35. }
  36. }
  37. - (void)mergeOptions:(RNNNavigationOptions *)options {
  38. [super mergeOptions:options];
  39. RNNNavigationOptions* withDefault = (RNNNavigationOptions *)[options withDefault:self.defaultOptions];
  40. UIViewController* viewController = self.bindedViewController;
  41. if (options.backgroundImage.hasValue) {
  42. [viewController rnn_setBackgroundImage:options.backgroundImage.get];
  43. }
  44. if (options.modalPresentationStyle.hasValue) {
  45. [viewController rnn_setModalPresentationStyle:[RCTConvert UIModalPresentationStyle:options.modalPresentationStyle.get]];
  46. }
  47. if (options.modalTransitionStyle.hasValue) {
  48. [viewController rnn_setModalTransitionStyle:[RCTConvert UIModalTransitionStyle:options.modalTransitionStyle.get]];
  49. }
  50. if (options.topBar.searchBar.hasValue) {
  51. [viewController rnn_setSearchBarWithPlaceholder:[withDefault.topBar.searchBarPlaceholder getWithDefaultValue:@""]];
  52. }
  53. if (options.topBar.drawBehind.hasValue) {
  54. [viewController rnn_setDrawBehindTopBar:options.topBar.drawBehind.get];
  55. }
  56. if (options.topBar.title.text.hasValue) {
  57. [viewController rnn_setNavigationItemTitle:options.topBar.title.text.get];
  58. }
  59. if (options.topBar.largeTitle.visible.hasValue) {
  60. [viewController rnn_setTopBarPrefersLargeTitle:options.topBar.largeTitle.visible.get];
  61. }
  62. if (options.bottomTabs.drawBehind.hasValue) {
  63. [viewController rnn_setDrawBehindTabBar:options.bottomTabs.drawBehind.get];
  64. }
  65. if (options.bottomTab.badge.hasValue) {
  66. [viewController rnn_setTabBarItemBadge:options.bottomTab.badge.get];
  67. }
  68. if (options.bottomTab.badgeColor.hasValue) {
  69. [viewController rnn_setTabBarItemBadgeColor:options.bottomTab.badgeColor.get];
  70. }
  71. if (options.layout.backgroundColor.hasValue) {
  72. [viewController rnn_setBackgroundColor:options.layout.backgroundColor.get];
  73. }
  74. if (options.bottomTab.visible.hasValue) {
  75. [viewController.tabBarController rnn_setCurrentTabIndex:[viewController.tabBarController.viewControllers indexOfObject:viewController]];
  76. }
  77. if (options.statusBar.blur.hasValue) {
  78. [viewController rnn_setStatusBarBlur:options.statusBar.blur.get];
  79. }
  80. if (options.statusBar.style.hasValue) {
  81. [viewController rnn_setStatusBarStyle:options.statusBar.style.get animated:[withDefault.statusBar.animate getWithDefaultValue:YES]];
  82. }
  83. if (options.topBar.backButton.visible.hasValue) {
  84. [viewController rnn_setBackButtonVisible:options.topBar.backButton.visible.get];
  85. }
  86. if (options.topBar.leftButtons || options.topBar.rightButtons) {
  87. _navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:(RNNRootViewController*)viewController];
  88. [_navigationButtons applyLeftButtons:options.topBar.leftButtons rightButtons:options.topBar.rightButtons defaultLeftButtonStyle:withDefault.topBar.leftButtonStyle defaultRightButtonStyle:withDefault.topBar.rightButtonStyle];
  89. }
  90. }
  91. @end