react-native-navigation的迁移库

RNNViewControllerPresenter.m 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #import "RNNViewControllerPresenter.h"
  2. #import "UIViewController+RNNOptions.h"
  3. #import "UITabBarController+RNNOptions.h"
  4. #import "RNNNavigationButtons.h"
  5. #import "RCTConvert+Modal.h"
  6. #import "RNNReactView.h"
  7. @interface RNNViewControllerPresenter()
  8. @property (nonatomic, strong) RNNNavigationButtons* navigationButtons;
  9. @end
  10. @implementation RNNViewControllerPresenter
  11. - (void)applyOptions:(RNNNavigationOptions *)initialOptions {
  12. [super applyOptions:initialOptions];
  13. RNNNavigationOptions* options = [initialOptions withDefault:self.defaultOptions];
  14. UIViewController* viewController = self.bindedViewController;
  15. [viewController rnn_setBackgroundImage:[options.backgroundImage getWithDefaultValue:nil]];
  16. [viewController rnn_setNavigationItemTitle:[options.topBar.title.text getWithDefaultValue:nil]];
  17. [viewController rnn_setTopBarPrefersLargeTitle:[options.topBar.largeTitle.visible getWithDefaultValue:NO]];
  18. [viewController rnn_setTabBarItemBadgeColor:[options.bottomTab.badgeColor getWithDefaultValue:nil]];
  19. [viewController rnn_setStatusBarBlur:[options.statusBar.blur getWithDefaultValue:NO]];
  20. [viewController rnn_setStatusBarStyle:[options.statusBar.style getWithDefaultValue:@"default"] animated:[options.statusBar.animate getWithDefaultValue:YES]];
  21. [viewController rnn_setBackButtonVisible:[options.topBar.backButton.visible getWithDefaultValue:YES]];
  22. [viewController rnn_setInterceptTouchOutside:[options.overlay.interceptTouchOutside 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. [viewController rnn_setDrawBehindTopBar:[options.topBar.drawBehind getWithDefaultValue:NO]];
  40. [viewController rnn_setDrawBehindTabBar:[options.bottomTabs.drawBehind getWithDefaultValue:NO] || ![options.bottomTabs.visible getWithDefaultValue:YES]];
  41. }
  42. - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
  43. [super mergeOptions:options resolvedOptions:resolvedOptions];
  44. RNNNavigationOptions* withDefault = (RNNNavigationOptions *)[options withDefault:self.defaultOptions];
  45. UIViewController* viewController = self.bindedViewController;
  46. if (options.backgroundImage.hasValue) {
  47. [viewController rnn_setBackgroundImage:options.backgroundImage.get];
  48. }
  49. if (options.modalPresentationStyle.hasValue) {
  50. [viewController rnn_setModalPresentationStyle:[RCTConvert UIModalPresentationStyle:options.modalPresentationStyle.get]];
  51. }
  52. if (options.modalTransitionStyle.hasValue) {
  53. [viewController rnn_setModalTransitionStyle:[RCTConvert UIModalTransitionStyle:options.modalTransitionStyle.get]];
  54. }
  55. if (options.topBar.searchBar.hasValue) {
  56. [viewController rnn_setSearchBarWithPlaceholder:[withDefault.topBar.searchBarPlaceholder getWithDefaultValue:@""]];
  57. }
  58. if (options.topBar.drawBehind.hasValue) {
  59. [viewController rnn_setDrawBehindTopBar:options.topBar.drawBehind.get];
  60. }
  61. if (options.topBar.title.text.hasValue) {
  62. [viewController rnn_setNavigationItemTitle:options.topBar.title.text.get];
  63. }
  64. if (options.topBar.largeTitle.visible.hasValue) {
  65. [viewController rnn_setTopBarPrefersLargeTitle:options.topBar.largeTitle.visible.get];
  66. }
  67. if (options.bottomTabs.drawBehind.hasValue) {
  68. [viewController rnn_setDrawBehindTabBar:options.bottomTabs.drawBehind.get];
  69. }
  70. if (options.bottomTab.badgeColor.hasValue) {
  71. [viewController rnn_setTabBarItemBadgeColor:options.bottomTab.badgeColor.get];
  72. }
  73. if (options.layout.backgroundColor.hasValue) {
  74. [viewController rnn_setBackgroundColor:options.layout.backgroundColor.get];
  75. }
  76. if (options.bottomTab.visible.hasValue) {
  77. [viewController.tabBarController rnn_setCurrentTabIndex:[viewController.tabBarController.viewControllers indexOfObject:viewController]];
  78. }
  79. if (options.statusBar.blur.hasValue) {
  80. [viewController rnn_setStatusBarBlur:options.statusBar.blur.get];
  81. }
  82. if (options.statusBar.style.hasValue) {
  83. [viewController rnn_setStatusBarStyle:options.statusBar.style.get animated:[withDefault.statusBar.animate getWithDefaultValue:YES]];
  84. }
  85. if (options.topBar.backButton.visible.hasValue) {
  86. [viewController rnn_setBackButtonVisible:options.topBar.backButton.visible.get];
  87. }
  88. if (options.topBar.leftButtons || options.topBar.rightButtons) {
  89. RNNNavigationOptions* buttonsResolvedOptions = (RNNNavigationOptions *)[[resolvedOptions overrideOptions:options] withDefault:self.defaultOptions];
  90. _navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:(RNNRootViewController*)viewController];
  91. [_navigationButtons applyLeftButtons:options.topBar.leftButtons rightButtons:options.topBar.rightButtons defaultLeftButtonStyle:buttonsResolvedOptions.topBar.leftButtonStyle defaultRightButtonStyle:buttonsResolvedOptions.topBar.rightButtonStyle];
  92. }
  93. if (options.overlay.interceptTouchOutside.hasValue) {
  94. RCTRootView* rootView = (RCTRootView*)viewController.view;
  95. rootView.passThroughTouches = !options.overlay.interceptTouchOutside.get;
  96. }
  97. }
  98. @end