react-native-navigation的迁移库

RNNNavigationController.m 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #import "RNNNavigationController.h"
  2. #import "RNNRootViewController.h"
  3. #import "InteractivePopGestureDelegate.h"
  4. const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;
  5. @implementation RNNNavigationController
  6. - (void)viewDidLayoutSubviews {
  7. [super viewDidLayoutSubviews];
  8. [self.presenter applyOptionsOnViewDidLayoutSubviews:self.resolveOptions];
  9. }
  10. - (UIViewController *)getCurrentChild {
  11. return self.topViewController;
  12. }
  13. - (CGFloat)getTopBarHeight {
  14. return self.navigationBar.frame.size.height;
  15. }
  16. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  17. return self.getCurrentChild.supportedInterfaceOrientations;
  18. }
  19. - (UINavigationController *)navigationController {
  20. return self;
  21. }
  22. - (UIStatusBarStyle)preferredStatusBarStyle {
  23. return self.getCurrentChild.preferredStatusBarStyle;
  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:[RNNRootViewController class]]) {
  32. RNNRootViewController *rnnController = (RNNRootViewController *)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