react-native-navigation的迁移库

RNNViewControllerPresenter.m 5.8KB

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