react-native-navigation的迁移库

RNNBasePresenter.m 4.1KB

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