react-native-navigation的迁移库

RNNSideMenuController.m 4.7KB

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