react-native-navigation的迁移库

RNNStackController.m 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #import "RNNStackController.h"
  2. #import "RNNComponentViewController.h"
  3. @implementation RNNStackController {
  4. UIViewController* _presentedViewController;
  5. }
  6. - (instancetype)init {
  7. self = [super init];
  8. self.delegate = self;
  9. return self;
  10. }
  11. - (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {
  12. [super setDefaultOptions:defaultOptions];
  13. [self.presenter setDefaultOptions:defaultOptions];
  14. }
  15. - (void)viewDidLayoutSubviews {
  16. [super viewDidLayoutSubviews];
  17. [self.presenter applyOptionsOnViewDidLayoutSubviews:self.resolveOptions];
  18. }
  19. - (UIViewController *)getCurrentChild {
  20. return self.topViewController;
  21. }
  22. - (UINavigationController *)navigationController {
  23. return self;
  24. }
  25. - (UIStatusBarStyle)preferredStatusBarStyle {
  26. return [_presenter getStatusBarStyle:self.resolveOptions];
  27. }
  28. - (UIModalPresentationStyle)modalPresentationStyle {
  29. return self.getCurrentChild.modalPresentationStyle;
  30. }
  31. - (UIViewController *)popViewControllerAnimated:(BOOL)animated {
  32. [self prepareForPop];
  33. return [super popViewControllerAnimated:animated];
  34. }
  35. - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
  36. if ([self.viewControllers indexOfObject:_presentedViewController] < 0) {
  37. [self sendScreenPoppedEvent:_presentedViewController];
  38. }
  39. _presentedViewController = viewController;
  40. }
  41. - (void)sendScreenPoppedEvent:(UIViewController *)poppedScreen {
  42. [self.eventEmitter sendScreenPoppedEvent:poppedScreen.layoutInfo.componentId];
  43. }
  44. - (void)prepareForPop {
  45. if (self.viewControllers.count > 1) {
  46. UIViewController *controller = self.viewControllers[self.viewControllers.count - 2];
  47. if ([controller isKindOfClass:[RNNComponentViewController class]]) {
  48. RNNComponentViewController *rnnController = (RNNComponentViewController *)controller;
  49. [self.presenter applyOptionsBeforePopping:rnnController.resolveOptions];
  50. }
  51. }
  52. }
  53. - (UIViewController *)childViewControllerForStatusBarStyle {
  54. return self.topViewController;
  55. }
  56. @end