react-native-navigation的迁移库

RNNSideMenuController.m 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. - (UIStatusBarStyle)preferredStatusBarStyle {
  107. return self.openedViewController.preferredStatusBarStyle;
  108. }
  109. - (UIViewController<RNNLayoutProtocol> *)getCurrentChild {
  110. return self.openedViewController;
  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. }
  123. }
  124. - (RNNNavigationOptions *)resolveOptions {
  125. RNNNavigationOptions * options = super.resolveOptions;
  126. if (self.openedViewController != self.center) {
  127. [options.sideMenu mergeOptions:self.center.resolveOptions.sideMenu];
  128. }
  129. return options;
  130. }
  131. @end