react-native-navigation的迁移库

RNNSideMenuController.m 4.9KB

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