react-native-navigation的迁移库

RNNSideMenuController.m 4.4KB

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