react-native-navigation的迁移库

RNNViewControllerPresenter.m 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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] || ![options.bottomTabs.visible getWithDefaultValue:YES]];
  21. [viewController rnn_setTabBarItemBadgeColor:[options.bottomTab.badgeColor getWithDefaultValue:nil]];
  22. [viewController rnn_setStatusBarBlur:[options.statusBar.blur getWithDefaultValue:NO]];
  23. [viewController rnn_setStatusBarStyle:[options.statusBar.style getWithDefaultValue:@"default"] animated:[options.statusBar.animate getWithDefaultValue:YES]];
  24. [viewController rnn_setBackButtonVisible:[options.topBar.backButton.visible getWithDefaultValue:YES]];
  25. if (options.layout.backgroundColor.hasValue) {
  26. [viewController rnn_setBackgroundColor:options.layout.backgroundColor.get];
  27. }
  28. if (options.topBar.searchBar.hasValue) {
  29. [viewController rnn_setSearchBarWithPlaceholder:[options.topBar.searchBarPlaceholder getWithDefaultValue:@""]];
  30. }
  31. if ((options.topBar.leftButtons || options.topBar.rightButtons) && !_navigationButtons) {
  32. _navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:(RNNRootViewController*)viewController];
  33. [_navigationButtons applyLeftButtons:options.topBar.leftButtons rightButtons:options.topBar.rightButtons defaultLeftButtonStyle:options.topBar.leftButtonStyle defaultRightButtonStyle:options.topBar.rightButtonStyle];
  34. }
  35. }
  36. - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
  37. [super mergeOptions:options resolvedOptions:resolvedOptions];
  38. RNNNavigationOptions* withDefault = (RNNNavigationOptions *)[options withDefault:self.defaultOptions];
  39. UIViewController* viewController = self.bindedViewController;
  40. if (options.backgroundImage.hasValue) {
  41. [viewController rnn_setBackgroundImage:options.backgroundImage.get];
  42. }
  43. if (options.modalPresentationStyle.hasValue) {
  44. [viewController rnn_setModalPresentationStyle:[RCTConvert UIModalPresentationStyle:options.modalPresentationStyle.get]];
  45. }
  46. if (options.modalTransitionStyle.hasValue) {
  47. [viewController rnn_setModalTransitionStyle:[RCTConvert UIModalTransitionStyle:options.modalTransitionStyle.get]];
  48. }
  49. if (options.topBar.searchBar.hasValue) {
  50. [viewController rnn_setSearchBarWithPlaceholder:[withDefault.topBar.searchBarPlaceholder getWithDefaultValue:@""]];
  51. }
  52. if (options.topBar.drawBehind.hasValue) {
  53. [viewController rnn_setDrawBehindTopBar:options.topBar.drawBehind.get];
  54. }
  55. if (options.topBar.title.text.hasValue) {
  56. [viewController rnn_setNavigationItemTitle:options.topBar.title.text.get];
  57. }
  58. if (options.topBar.largeTitle.visible.hasValue) {
  59. [viewController rnn_setTopBarPrefersLargeTitle:options.topBar.largeTitle.visible.get];
  60. }
  61. if (options.bottomTabs.drawBehind.hasValue) {
  62. [viewController rnn_setDrawBehindTabBar:options.bottomTabs.drawBehind.get];
  63. }
  64. if (options.bottomTab.badgeColor.hasValue) {
  65. [viewController rnn_setTabBarItemBadgeColor:options.bottomTab.badgeColor.get];
  66. }
  67. if (options.layout.backgroundColor.hasValue) {
  68. [viewController rnn_setBackgroundColor:options.layout.backgroundColor.get];
  69. }
  70. if (options.bottomTab.visible.hasValue) {
  71. [viewController.tabBarController rnn_setCurrentTabIndex:[viewController.tabBarController.viewControllers indexOfObject:viewController]];
  72. }
  73. if (options.statusBar.blur.hasValue) {
  74. [viewController rnn_setStatusBarBlur:options.statusBar.blur.get];
  75. }
  76. if (options.statusBar.style.hasValue) {
  77. [viewController rnn_setStatusBarStyle:options.statusBar.style.get animated:[withDefault.statusBar.animate getWithDefaultValue:YES]];
  78. }
  79. if (options.topBar.backButton.visible.hasValue) {
  80. [viewController rnn_setBackButtonVisible:options.topBar.backButton.visible.get];
  81. }
  82. if (options.topBar.leftButtons || options.topBar.rightButtons) {
  83. RNNNavigationOptions* buttonsResolvedOptions = (RNNNavigationOptions *)[[resolvedOptions overrideOptions:options] withDefault:self.defaultOptions];
  84. _navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:(RNNRootViewController*)viewController];
  85. [_navigationButtons applyLeftButtons:options.topBar.leftButtons rightButtons:options.topBar.rightButtons defaultLeftButtonStyle:buttonsResolvedOptions.topBar.leftButtonStyle defaultRightButtonStyle:buttonsResolvedOptions.topBar.rightButtonStyle];
  86. }
  87. }
  88. @end