react-native-navigation的迁移库

RNNViewControllerPresenter.m 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_setDrawBehindTopBar:[options.topBar.drawBehind getWithDefaultValue:NO]];
  16. [viewController rnn_setNavigationItemTitle:[options.topBar.title.text getWithDefaultValue:nil]];
  17. [viewController rnn_setTopBarPrefersLargeTitle:[options.topBar.largeTitle.visible getWithDefaultValue:NO]];
  18. [viewController rnn_setDrawBehindTabBar:[options.bottomTabs.drawBehind getWithDefaultValue:NO] || ![options.bottomTabs.visible getWithDefaultValue:YES]];
  19. [viewController rnn_setTabBarItemBadgeColor:[options.bottomTab.badgeColor getWithDefaultValue:nil]];
  20. [viewController rnn_setStatusBarBlur:[options.statusBar.blur getWithDefaultValue:NO]];
  21. [viewController rnn_setStatusBarStyle:[options.statusBar.style getWithDefaultValue:@"default"] animated:[options.statusBar.animate getWithDefaultValue:YES]];
  22. [viewController rnn_setBackButtonVisible:[options.topBar.backButton.visible getWithDefaultValue:YES]];
  23. if (options.layout.backgroundColor.hasValue) {
  24. [viewController rnn_setBackgroundColor:options.layout.backgroundColor.get];
  25. }
  26. if (options.topBar.searchBar.hasValue) {
  27. [viewController rnn_setSearchBarWithPlaceholder:[options.topBar.searchBarPlaceholder getWithDefaultValue:@""]];
  28. }
  29. if ((options.topBar.leftButtons || options.topBar.rightButtons) && !_navigationButtons) {
  30. _navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:(RNNRootViewController*)viewController];
  31. [_navigationButtons applyLeftButtons:options.topBar.leftButtons rightButtons:options.topBar.rightButtons defaultLeftButtonStyle:options.topBar.leftButtonStyle defaultRightButtonStyle:options.topBar.rightButtonStyle];
  32. }
  33. }
  34. - (void)applyOptionsOnInit:(RNNNavigationOptions *)options {
  35. [super applyOptionsOnInit:options];
  36. UIViewController* viewController = self.bindedViewController;
  37. [viewController rnn_setModalPresentationStyle:[RCTConvert UIModalPresentationStyle:[options.modalPresentationStyle getWithDefaultValue:@"fullScreen"]]];
  38. [viewController rnn_setModalTransitionStyle:[RCTConvert UIModalTransitionStyle:[options.modalTransitionStyle getWithDefaultValue:@"coverVertical"]]];
  39. }
  40. - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
  41. [super mergeOptions:options resolvedOptions:resolvedOptions];
  42. RNNNavigationOptions* withDefault = (RNNNavigationOptions *)[options withDefault:self.defaultOptions];
  43. UIViewController* viewController = self.bindedViewController;
  44. if (options.backgroundImage.hasValue) {
  45. [viewController rnn_setBackgroundImage:options.backgroundImage.get];
  46. }
  47. if (options.modalPresentationStyle.hasValue) {
  48. [viewController rnn_setModalPresentationStyle:[RCTConvert UIModalPresentationStyle:options.modalPresentationStyle.get]];
  49. }
  50. if (options.modalTransitionStyle.hasValue) {
  51. [viewController rnn_setModalTransitionStyle:[RCTConvert UIModalTransitionStyle:options.modalTransitionStyle.get]];
  52. }
  53. if (options.topBar.searchBar.hasValue) {
  54. [viewController rnn_setSearchBarWithPlaceholder:[withDefault.topBar.searchBarPlaceholder getWithDefaultValue:@""]];
  55. }
  56. if (options.topBar.drawBehind.hasValue) {
  57. [viewController rnn_setDrawBehindTopBar:options.topBar.drawBehind.get];
  58. }
  59. if (options.topBar.title.text.hasValue) {
  60. [viewController rnn_setNavigationItemTitle:options.topBar.title.text.get];
  61. }
  62. if (options.topBar.largeTitle.visible.hasValue) {
  63. [viewController rnn_setTopBarPrefersLargeTitle:options.topBar.largeTitle.visible.get];
  64. }
  65. if (options.bottomTabs.drawBehind.hasValue) {
  66. [viewController rnn_setDrawBehindTabBar:options.bottomTabs.drawBehind.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. RNNNavigationOptions* buttonsResolvedOptions = (RNNNavigationOptions *)[[resolvedOptions overrideOptions:options] withDefault:self.defaultOptions];
  88. _navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:(RNNRootViewController*)viewController];
  89. [_navigationButtons applyLeftButtons:options.topBar.leftButtons rightButtons:options.topBar.rightButtons defaultLeftButtonStyle:buttonsResolvedOptions.topBar.leftButtonStyle defaultRightButtonStyle:buttonsResolvedOptions.topBar.rightButtonStyle];
  90. }
  91. }
  92. @end