react-native-navigation的迁移库

RNNSideMenuController.m 5.0KB

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