react-native-navigation的迁移库

RNNViewControllerPresenter.m 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. BOOL hideNavBarOnFocusSearchBar = YES;
  27. if (options.topBar.hideNavBarOnFocusSearchBar.hasValue) {
  28. hideNavBarOnFocusSearchBar = options.topBar.hideNavBarOnFocusSearchBar.get;
  29. }
  30. [viewController rnn_setSearchBarWithPlaceholder:[options.topBar.searchBarPlaceholder getWithDefaultValue:@""] hideNavBarOnFocusSearchBar: hideNavBarOnFocusSearchBar];
  31. }
  32. }
  33. - (void)applyOptionsOnInit:(RNNNavigationOptions *)options {
  34. [super applyOptionsOnInit:options];
  35. UIViewController* viewController = self.bindedViewController;
  36. [viewController rnn_setModalPresentationStyle:[RCTConvert UIModalPresentationStyle:[options.modalPresentationStyle getWithDefaultValue:@"fullScreen"]]];
  37. [viewController rnn_setModalTransitionStyle:[RCTConvert UIModalTransitionStyle:[options.modalTransitionStyle getWithDefaultValue:@"coverVertical"]]];
  38. [viewController rnn_setDrawBehindTopBar:[options.topBar.drawBehind getWithDefaultValue:NO]];
  39. [viewController rnn_setDrawBehindTabBar:[options.bottomTabs.drawBehind getWithDefaultValue:NO] || ![options.bottomTabs.visible getWithDefaultValue:YES]];
  40. if ((options.topBar.leftButtons || options.topBar.rightButtons)) {
  41. [_navigationButtons applyLeftButtons:options.topBar.leftButtons rightButtons:options.topBar.rightButtons defaultLeftButtonStyle:options.topBar.leftButtonStyle defaultRightButtonStyle:options.topBar.rightButtonStyle];
  42. }
  43. }
  44. - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions {
  45. [super mergeOptions:newOptions currentOptions:currentOptions defaultOptions:defaultOptions];
  46. UIViewController* viewController = self.bindedViewController;
  47. if (newOptions.backgroundImage.hasValue) {
  48. [viewController rnn_setBackgroundImage:newOptions.backgroundImage.get];
  49. }
  50. if (newOptions.modalPresentationStyle.hasValue) {
  51. [viewController rnn_setModalPresentationStyle:[RCTConvert UIModalPresentationStyle:newOptions.modalPresentationStyle.get]];
  52. }
  53. if (newOptions.modalTransitionStyle.hasValue) {
  54. [viewController rnn_setModalTransitionStyle:[RCTConvert UIModalTransitionStyle:newOptions.modalTransitionStyle.get]];
  55. }
  56. if (newOptions.topBar.searchBar.hasValue) {
  57. BOOL hideNavBarOnFocusSearchBar = YES;
  58. if (newOptions.topBar.hideNavBarOnFocusSearchBar.hasValue) {
  59. hideNavBarOnFocusSearchBar = newOptions.topBar.hideNavBarOnFocusSearchBar.get;
  60. }
  61. [viewController rnn_setSearchBarWithPlaceholder:[newOptions.topBar.searchBarPlaceholder getWithDefaultValue:@""] hideNavBarOnFocusSearchBar:hideNavBarOnFocusSearchBar];
  62. }
  63. if (newOptions.topBar.drawBehind.hasValue) {
  64. [viewController rnn_setDrawBehindTopBar:newOptions.topBar.drawBehind.get];
  65. }
  66. if (newOptions.topBar.title.text.hasValue) {
  67. [viewController rnn_setNavigationItemTitle:newOptions.topBar.title.text.get];
  68. }
  69. if (newOptions.topBar.largeTitle.visible.hasValue) {
  70. [viewController rnn_setTopBarPrefersLargeTitle:newOptions.topBar.largeTitle.visible.get];
  71. }
  72. if (newOptions.bottomTabs.drawBehind.hasValue) {
  73. [viewController rnn_setDrawBehindTabBar:newOptions.bottomTabs.drawBehind.get];
  74. }
  75. if (newOptions.bottomTab.badgeColor.hasValue) {
  76. [viewController rnn_setTabBarItemBadgeColor:newOptions.bottomTab.badgeColor.get];
  77. }
  78. if (newOptions.layout.backgroundColor.hasValue) {
  79. [viewController rnn_setBackgroundColor:newOptions.layout.backgroundColor.get];
  80. }
  81. if (newOptions.bottomTab.visible.hasValue) {
  82. [viewController.tabBarController rnn_setCurrentTabIndex:[viewController.tabBarController.viewControllers indexOfObject:viewController]];
  83. }
  84. if (newOptions.statusBar.blur.hasValue) {
  85. [viewController rnn_setStatusBarBlur:newOptions.statusBar.blur.get];
  86. }
  87. if (newOptions.statusBar.style.hasValue) {
  88. [viewController rnn_setStatusBarStyle:newOptions.statusBar.style.get animated:[newOptions.statusBar.animate getWithDefaultValue:YES]];
  89. }
  90. if (newOptions.topBar.backButton.visible.hasValue) {
  91. [viewController rnn_setBackButtonVisible:newOptions.topBar.backButton.visible.get];
  92. }
  93. if (newOptions.topBar.leftButtons || newOptions.topBar.rightButtons) {
  94. RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
  95. [_navigationButtons applyLeftButtons:newOptions.topBar.leftButtons rightButtons:newOptions.topBar.rightButtons defaultLeftButtonStyle:buttonsResolvedOptions.topBar.leftButtonStyle defaultRightButtonStyle:buttonsResolvedOptions.topBar.rightButtonStyle];
  96. }
  97. if (newOptions.overlay.interceptTouchOutside.hasValue) {
  98. RCTRootView* rootView = (RCTRootView*)viewController.view;
  99. rootView.passThroughTouches = !newOptions.overlay.interceptTouchOutside.get;
  100. }
  101. }
  102. @end