react-native-navigation的迁移库

RNNSideMenuController.m 5.1KB

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