react-native-navigation的迁移库

RNNSideMenuController.m 4.2KB

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