react-native-navigation的迁移库

RNNSideMenuController.m 5.0KB

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