react-native-navigation的迁移库

RNNBasePresenter.m 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions {
  30. UIViewController* viewController = self.boundViewController;
  31. RNNNavigationOptions *withDefault = [initialOptions withDefault:[self defaultOptions]];
  32. if (@available(iOS 13.0, *)) {
  33. viewController.modalInPresentation = ![withDefault.modal.swipeToDismiss getWithDefaultValue:YES];
  34. }
  35. UIApplication.sharedApplication.delegate.window.backgroundColor = [withDefault.window.backgroundColor getWithDefaultValue:nil];
  36. }
  37. - (void)applyOptionsOnViewDidLayoutSubviews:(RNNNavigationOptions *)options {
  38. }
  39. - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
  40. }
  41. - (void)applyOptions:(RNNNavigationOptions *)options {
  42. }
  43. - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
  44. RNNNavigationOptions* withDefault = (RNNNavigationOptions *) [[resolvedOptions withDefault:_defaultOptions] overrideOptions:options];
  45. if (options.window.backgroundColor.hasValue) {
  46. UIApplication.sharedApplication.delegate.window.backgroundColor = withDefault.window.backgroundColor.get;
  47. }
  48. }
  49. - (void)renderComponents:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
  50. if (readyBlock) {
  51. readyBlock();
  52. readyBlock = nil;
  53. }
  54. }
  55. - (void)viewDidLayoutSubviews {
  56. }
  57. - (UIStatusBarStyle)getStatusBarStyle:(RNNNavigationOptions *)resolvedOptions {
  58. RNNNavigationOptions *withDefault = [resolvedOptions withDefault:[self defaultOptions]];
  59. NSString* statusBarStyle = [withDefault.statusBar.style getWithDefaultValue:@"default"];
  60. if ([statusBarStyle isEqualToString:@"light"]) {
  61. return UIStatusBarStyleLightContent;
  62. } else if (@available(iOS 13.0, *)) {
  63. if ([statusBarStyle isEqualToString:@"dark"]) {
  64. return UIStatusBarStyleDarkContent;
  65. } else {
  66. return UIStatusBarStyleDefault;
  67. }
  68. } else {
  69. return UIStatusBarStyleDefault;
  70. }
  71. }
  72. - (UINavigationItem *)currentNavigationItem {
  73. return self.boundViewController.getCurrentChild.navigationItem;
  74. }
  75. - (UIInterfaceOrientationMask)getOrientation:(RNNNavigationOptions *)options {
  76. return [options withDefault:[self defaultOptions]].layout.supportedOrientations;
  77. }
  78. - (BOOL)isStatusBarVisibility:(UINavigationController *)stack resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
  79. RNNNavigationOptions *withDefault = [resolvedOptions withDefault:[self defaultOptions]];
  80. if (withDefault.statusBar.visible.hasValue) {
  81. return ![withDefault.statusBar.visible get];
  82. } else if ([withDefault.statusBar.hideWithTopBar getWithDefaultValue:NO]) {
  83. return stack.isNavigationBarHidden;
  84. }
  85. return NO;
  86. }
  87. @end