react-native-navigation的迁移库

RNNNavigationController.m 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #import "RNNNavigationController.h"
  2. #import "RNNRootViewController.h"
  3. const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;
  4. @implementation RNNNavigationController
  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. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  20. return self.getCurrentChild.supportedInterfaceOrientations;
  21. }
  22. - (UINavigationController *)navigationController {
  23. return self;
  24. }
  25. - (UIStatusBarStyle)preferredStatusBarStyle {
  26. return self.getCurrentChild.preferredStatusBarStyle;
  27. }
  28. - (UIModalPresentationStyle)modalPresentationStyle {
  29. return self.getCurrentChild.modalPresentationStyle;
  30. }
  31. - (UIViewController *)popViewControllerAnimated:(BOOL)animated {
  32. if (self.viewControllers.count > 1) {
  33. UIViewController *controller = self.viewControllers[self.viewControllers.count - 2];
  34. if ([controller isKindOfClass:[RNNRootViewController class]]) {
  35. RNNRootViewController *rnnController = (RNNRootViewController *)controller;
  36. [self.presenter applyOptionsBeforePopping:rnnController.resolveOptions];
  37. }
  38. }
  39. return [super popViewControllerAnimated:animated];
  40. }
  41. - (UIViewController *)childViewControllerForStatusBarStyle {
  42. return self.topViewController;
  43. }
  44. - (void)setTopBarBackgroundColor:(UIColor *)backgroundColor {
  45. if (backgroundColor) {
  46. CGFloat bgColorAlpha = CGColorGetAlpha(backgroundColor.CGColor);
  47. if (bgColorAlpha == 0.0) {
  48. if (![self.navigationBar viewWithTag:TOP_BAR_TRANSPARENT_TAG]){
  49. UIView *transparentView = [[UIView alloc] initWithFrame:CGRectZero];
  50. transparentView.backgroundColor = [UIColor clearColor];
  51. transparentView.tag = TOP_BAR_TRANSPARENT_TAG;
  52. [self.navigationBar insertSubview:transparentView atIndex:0];
  53. }
  54. self.navigationBar.translucent = YES;
  55. [self.navigationBar setBackgroundColor:[UIColor clearColor]];
  56. self.navigationBar.shadowImage = [UIImage new];
  57. [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
  58. } else {
  59. self.navigationBar.barTintColor = backgroundColor;
  60. UIView *transparentView = [self.navigationBar viewWithTag:TOP_BAR_TRANSPARENT_TAG];
  61. if (transparentView){
  62. [transparentView removeFromSuperview];
  63. }
  64. }
  65. } else {
  66. UIView *transparentView = [self.navigationBar viewWithTag:TOP_BAR_TRANSPARENT_TAG];
  67. if (transparentView){
  68. [transparentView removeFromSuperview];
  69. }
  70. self.navigationBar.barTintColor = nil;
  71. }
  72. }
  73. @end