react-native-navigation的迁移库

RNNSideMenuController.m 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #import "RNNSideMenuController.h"
  2. #import "RNNSideMenuChildVC.h"
  3. #import "MMDrawerController.h"
  4. #import "MMDrawerVisualState.h"
  5. @interface RNNSideMenuController ()
  6. @property (readwrite) RNNSideMenuChildVC *center;
  7. @property (readwrite) RNNSideMenuChildVC *left;
  8. @property (readwrite) RNNSideMenuChildVC *right;
  9. @end
  10. @implementation RNNSideMenuController
  11. - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo childViewControllers:(NSArray *)childViewControllers options:(RNNNavigationOptions *)options presenter:(RNNViewControllerPresenter *)presenter {
  12. [self setControllers:childViewControllers];
  13. self = [super initWithCenterViewController:self.center leftDrawerViewController:self.left rightDrawerViewController:self.right];
  14. self.presenter = presenter;
  15. [self.presenter bindViewController:self];
  16. self.options = options;
  17. self.layoutInfo = layoutInfo;
  18. self.openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
  19. self.closeDrawerGestureModeMask = MMCloseDrawerGestureModeAll;
  20. // Fixes #3697
  21. [self setExtendedLayoutIncludesOpaqueBars:YES];
  22. self.edgesForExtendedLayout |= UIRectEdgeBottom;
  23. return self;
  24. }
  25. - (void)willMoveToParentViewController:(UIViewController *)parent {
  26. if (parent) {
  27. [_presenter applyOptionsOnWillMoveToParentViewController:self.options];
  28. }
  29. }
  30. - (UITabBarItem *)tabBarItem {
  31. return self.center.tabBarItem;
  32. }
  33. - (void)onChildWillAppear {
  34. [_presenter applyOptions:self.resolveOptions];
  35. [((UIViewController<RNNParentProtocol> *)self.parentViewController) onChildWillAppear];
  36. }
  37. - (RNNNavigationOptions *)resolveOptions {
  38. return (RNNNavigationOptions *)[self.getCurrentChild.resolveOptions.copy mergeOptions:self.options];
  39. }
  40. - (void)mergeOptions:(RNNNavigationOptions *)options {
  41. [_presenter mergeOptions:options resolvedOptions:self.resolveOptions];
  42. [((UIViewController<RNNLayoutProtocol> *)self.parentViewController) mergeOptions:options];
  43. }
  44. - (void)setAnimationType:(NSString *)animationType {
  45. MMDrawerControllerDrawerVisualStateBlock animationTypeStateBlock = nil;
  46. if ([animationType isEqualToString:@"door"]) animationTypeStateBlock = [MMDrawerVisualState swingingDoorVisualStateBlock];
  47. else if ([animationType isEqualToString:@"parallax"]) animationTypeStateBlock = [MMDrawerVisualState parallaxVisualStateBlockWithParallaxFactor:2.0];
  48. else if ([animationType isEqualToString:@"slide"]) animationTypeStateBlock = [MMDrawerVisualState slideVisualStateBlock];
  49. else if ([animationType isEqualToString:@"slide-and-scale"]) animationTypeStateBlock = [MMDrawerVisualState slideAndScaleVisualStateBlock];
  50. if (animationTypeStateBlock) {
  51. [self setDrawerVisualStateBlock:animationTypeStateBlock];
  52. }
  53. }
  54. - (void)side:(MMDrawerSide)side width:(double)width {
  55. switch (side) {
  56. case MMDrawerSideRight:
  57. self.maximumRightDrawerWidth = width;
  58. break;
  59. case MMDrawerSideLeft:
  60. self.maximumLeftDrawerWidth = width;
  61. default:
  62. break;
  63. }
  64. }
  65. - (void)side:(MMDrawerSide)side visible:(BOOL)visible {
  66. if (visible) {
  67. [self showSideMenu:side animated:YES];
  68. } else {
  69. [self hideSideMenu:side animated:YES];
  70. }
  71. }
  72. -(void)showSideMenu:(MMDrawerSide)side animated:(BOOL)animated {
  73. [self openDrawerSide:side animated:animated completion:nil];
  74. }
  75. -(void)hideSideMenu:(MMDrawerSide)side animated:(BOOL)animated {
  76. [self closeDrawerAnimated:animated completion:nil];
  77. }
  78. - (void)side:(MMDrawerSide)side enabled:(BOOL)enabled {
  79. switch (side) {
  80. case MMDrawerSideRight:
  81. self.rightSideEnabled = enabled;
  82. break;
  83. case MMDrawerSideLeft:
  84. self.leftSideEnabled = enabled;
  85. default:
  86. break;
  87. }
  88. self.openDrawerGestureModeMask = enabled ? MMOpenDrawerGestureModeAll : MMOpenDrawerGestureModeNone;
  89. }
  90. -(void)setControllers:(NSArray*)controllers {
  91. for (id controller in controllers) {
  92. if ([controller isKindOfClass:[RNNSideMenuChildVC class]]) {
  93. RNNSideMenuChildVC *child = (RNNSideMenuChildVC*)controller;
  94. if (child.type == RNNSideMenuChildTypeCenter) {
  95. self.center = child;
  96. }
  97. else if(child.type == RNNSideMenuChildTypeLeft) {
  98. self.left = child;
  99. }
  100. else if(child.type == RNNSideMenuChildTypeRight) {
  101. self.right = child;
  102. }
  103. }
  104. else {
  105. @throw [NSException exceptionWithName:@"UnknownSideMenuControllerType" reason:[@"Unknown side menu type " stringByAppendingString:[controller description]] userInfo:nil];
  106. }
  107. }
  108. }
  109. - (UIStatusBarStyle)preferredStatusBarStyle {
  110. return self.openedViewController.preferredStatusBarStyle;
  111. }
  112. - (UIViewController *)openedViewController {
  113. switch (self.openSide) {
  114. case MMDrawerSideNone:
  115. return self.center;
  116. case MMDrawerSideLeft:
  117. return self.left;
  118. case MMDrawerSideRight:
  119. return self.right;
  120. default:
  121. return self.center;
  122. break;
  123. }
  124. }
  125. - (UIViewController<RNNLayoutProtocol> *)getCurrentChild {
  126. return [self.center getCurrentChild];
  127. }
  128. @end