react-native-navigation的迁移库

RNNStackController.m 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #import "RNNStackController.h"
  2. #import "RNNComponentViewController.h"
  3. const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;
  4. @implementation RNNStackController
  5. -(void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {
  6. [super setDefaultOptions:defaultOptions];
  7. [self.presenter setDefaultOptions:defaultOptions];
  8. }
  9. - (void)viewDidLayoutSubviews {
  10. [super viewDidLayoutSubviews];
  11. [self.presenter applyOptionsOnViewDidLayoutSubviews:self.resolveOptions];
  12. }
  13. - (UIViewController *)getCurrentChild {
  14. return self.topViewController;
  15. }
  16. - (CGFloat)getTopBarHeight {
  17. return self.navigationBar.frame.size.height;
  18. }
  19. - (UINavigationController *)navigationController {
  20. return self;
  21. }
  22. - (UIStatusBarStyle)preferredStatusBarStyle {
  23. return [_presenter getStatusBarStyle:self.resolveOptions];
  24. }
  25. - (UIModalPresentationStyle)modalPresentationStyle {
  26. return self.getCurrentChild.modalPresentationStyle;
  27. }
  28. - (UIViewController *)popViewControllerAnimated:(BOOL)animated {
  29. if (self.viewControllers.count > 1) {
  30. UIViewController *controller = self.viewControllers[self.viewControllers.count - 2];
  31. if ([controller isKindOfClass:[RNNComponentViewController class]]) {
  32. RNNComponentViewController *rnnController = (RNNComponentViewController *)controller;
  33. [self.presenter applyOptionsBeforePopping:rnnController.resolveOptions];
  34. }
  35. }
  36. return [super popViewControllerAnimated:animated];
  37. }
  38. - (UIViewController *)childViewControllerForStatusBarStyle {
  39. return self.topViewController;
  40. }
  41. - (void)setTopBarBackgroundColor:(UIColor *)backgroundColor {
  42. if (backgroundColor) {
  43. CGFloat bgColorAlpha = CGColorGetAlpha(backgroundColor.CGColor);
  44. if (bgColorAlpha == 0.0) {
  45. if (![self.navigationBar viewWithTag:TOP_BAR_TRANSPARENT_TAG]){
  46. UIView *transparentView = [[UIView alloc] initWithFrame:CGRectZero];
  47. transparentView.backgroundColor = [UIColor clearColor];
  48. transparentView.tag = TOP_BAR_TRANSPARENT_TAG;
  49. [self.navigationBar insertSubview:transparentView atIndex:0];
  50. }
  51. self.navigationBar.translucent = YES;
  52. [self.navigationBar setBackgroundColor:[UIColor clearColor]];
  53. self.navigationBar.shadowImage = [UIImage new];
  54. [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
  55. } else {
  56. self.navigationBar.barTintColor = backgroundColor;
  57. UIView *transparentView = [self.navigationBar viewWithTag:TOP_BAR_TRANSPARENT_TAG];
  58. if (transparentView){
  59. [transparentView removeFromSuperview];
  60. }
  61. }
  62. } else {
  63. UIView *transparentView = [self.navigationBar viewWithTag:TOP_BAR_TRANSPARENT_TAG];
  64. if (transparentView){
  65. [transparentView removeFromSuperview];
  66. }
  67. self.navigationBar.barTintColor = nil;
  68. }
  69. }
  70. @end