react-native-navigation的迁移库

RNNBasePresenter.m 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #import "RNNBasePresenter.h"
  2. #import "UIViewController+RNNOptions.h"
  3. #import "RNNTabBarItemCreator.h"
  4. #import "RNNReactComponentRegistry.h"
  5. #import "UIViewController+LayoutProtocol.h"
  6. #import "DotIndicatorOptions.h"
  7. @implementation RNNBasePresenter
  8. - (instancetype)initWithDefaultOptions:(RNNNavigationOptions *)defaultOptions {
  9. self = [super init];
  10. _defaultOptions = defaultOptions;
  11. return self;
  12. }
  13. - (instancetype)initWithComponentRegistry:(RNNReactComponentRegistry *)componentRegistry defaultOptions:(RNNNavigationOptions *)defaultOptions {
  14. self = [self initWithDefaultOptions:defaultOptions];
  15. _componentRegistry = componentRegistry;
  16. return self;
  17. }
  18. - (void)bindViewController:(UIViewController *)boundViewController {
  19. self.boundComponentId = boundViewController.layoutInfo.componentId;
  20. _boundViewController = boundViewController;
  21. }
  22. - (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {
  23. _defaultOptions = defaultOptions;
  24. }
  25. - (void)componentDidAppear {
  26. }
  27. - (void)componentDidDisappear {
  28. }
  29. - (void)willMoveToParentViewController:(UIViewController *)parent {
  30. if (parent) {
  31. [self applyOptionsOnWillMoveToParentViewController:self.boundViewController.resolveOptions];
  32. [self.boundViewController onChildAddToParent:self.boundViewController options:self.boundViewController.resolveOptions];
  33. }
  34. }
  35. - (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions {
  36. UIViewController* viewController = self.boundViewController;
  37. RNNNavigationOptions *withDefault = [initialOptions withDefault:[self defaultOptions]];
  38. if (@available(iOS 13.0, *)) {
  39. viewController.modalInPresentation = ![withDefault.modal.swipeToDismiss getWithDefaultValue:YES];
  40. }
  41. UIApplication.sharedApplication.delegate.window.backgroundColor = [withDefault.window.backgroundColor getWithDefaultValue:nil];
  42. }
  43. - (void)applyOptionsOnViewDidLayoutSubviews:(RNNNavigationOptions *)options {
  44. }
  45. - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
  46. }
  47. - (void)applyOptions:(RNNNavigationOptions *)options {
  48. }
  49. - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
  50. RNNNavigationOptions* withDefault = (RNNNavigationOptions *) [[resolvedOptions withDefault:_defaultOptions] overrideOptions:options];
  51. if (options.window.backgroundColor.hasValue) {
  52. UIApplication.sharedApplication.delegate.window.backgroundColor = withDefault.window.backgroundColor.get;
  53. }
  54. }
  55. - (void)renderComponents:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
  56. if (readyBlock) {
  57. readyBlock();
  58. readyBlock = nil;
  59. }
  60. }
  61. - (void)viewDidLayoutSubviews {
  62. }
  63. - (UIStatusBarStyle)getStatusBarStyle {
  64. RNNNavigationOptions *withDefault = [self.boundViewController.resolveOptions withDefault:[self defaultOptions]];
  65. NSString* statusBarStyle = [withDefault.statusBar.style getWithDefaultValue:@"default"];
  66. if ([statusBarStyle isEqualToString:@"light"]) {
  67. return UIStatusBarStyleLightContent;
  68. } else if (@available(iOS 13.0, *)) {
  69. if ([statusBarStyle isEqualToString:@"dark"]) {
  70. return UIStatusBarStyleDarkContent;
  71. } else {
  72. return UIStatusBarStyleDefault;
  73. }
  74. } else {
  75. return UIStatusBarStyleDefault;
  76. }
  77. }
  78. - (UINavigationItem *)currentNavigationItem {
  79. return self.boundViewController.getCurrentChild.navigationItem;
  80. }
  81. - (UIInterfaceOrientationMask)getOrientation {
  82. return [self.boundViewController.resolveOptions withDefault:self.defaultOptions].layout.supportedOrientations;
  83. }
  84. - (BOOL)getStatusBarVisibility {
  85. RNNNavigationOptions *withDefault = [self.boundViewController.resolveOptions withDefault:self.defaultOptions];
  86. if (withDefault.statusBar.visible.hasValue) {
  87. return ![withDefault.statusBar.visible get];
  88. } else if ([withDefault.statusBar.hideWithTopBar getWithDefaultValue:NO]) {
  89. return self.boundViewController.stack.isNavigationBarHidden;
  90. }
  91. return NO;
  92. }
  93. - (BOOL)hidesBottomBarWhenPushed {
  94. RNNNavigationOptions *withDefault = [self.boundViewController.topMostViewController.resolveOptions withDefault:self.defaultOptions];
  95. return ![withDefault.bottomTabs.visible getWithDefaultValue:YES];
  96. }
  97. @end