react-native-navigation的迁移库

RNNSideMenuController.m 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // RNNSideMenuController.m
  3. // ReactNativeNavigation
  4. //
  5. // Created by Ran Greenberg on 09/02/2017.
  6. // Copyright © 2017 Wix. All rights reserved.
  7. //
  8. #import "RNNSideMenuController.h"
  9. #import "RNNSideMenuChildVC.h"
  10. #import "MMDrawerController.h"
  11. @interface RNNSideMenuController ()
  12. @property (readwrite) RNNSideMenuChildVC *center;
  13. @property (readwrite) RNNSideMenuChildVC *left;
  14. @property (readwrite) RNNSideMenuChildVC *right;
  15. @property (readwrite) MMDrawerController *sideMenu;
  16. @end
  17. @implementation RNNSideMenuController
  18. - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo childViewControllers:(NSArray *)childViewControllers options:(RNNNavigationOptions *)options presenter:(RNNBasePresenter *)presenter {
  19. self = [super init];
  20. self.presenter = presenter;
  21. self.options = options;
  22. self.layoutInfo = layoutInfo;
  23. [self bindChildViewControllers:childViewControllers];
  24. // Fixes #3697
  25. [self setExtendedLayoutIncludesOpaqueBars:YES];
  26. self.edgesForExtendedLayout |= UIRectEdgeBottom;
  27. return self;
  28. }
  29. - (void)bindChildViewControllers:(NSArray<UIViewController<RNNLayoutProtocol> *> *)viewControllers {
  30. [self setControllers:viewControllers];
  31. self.sideMenu = [[MMDrawerController alloc] initWithCenterViewController:self.center leftDrawerViewController:self.left rightDrawerViewController:self.right];
  32. self.sideMenu.openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
  33. self.sideMenu.closeDrawerGestureModeMask = MMCloseDrawerGestureModeAll;
  34. [self addChildViewController:self.sideMenu];
  35. [self.sideMenu.view setFrame:self.view.bounds];
  36. [self.view addSubview:self.sideMenu.view];
  37. [self.view bringSubviewToFront:self.sideMenu.view];
  38. }
  39. -(void)showSideMenu:(MMDrawerSide)side animated:(BOOL)animated {
  40. [self.sideMenu openDrawerSide:side animated:animated completion:nil];
  41. }
  42. -(void)hideSideMenu:(MMDrawerSide)side animated:(BOOL)animated {
  43. [self.sideMenu closeDrawerAnimated:animated completion:nil];
  44. }
  45. -(void)setControllers:(NSArray*)controllers {
  46. for (id controller in controllers) {
  47. if ([controller isKindOfClass:[RNNSideMenuChildVC class]]) {
  48. RNNSideMenuChildVC *child = (RNNSideMenuChildVC*)controller;
  49. if (child.type == RNNSideMenuChildTypeCenter) {
  50. self.center = child;
  51. }
  52. else if(child.type == RNNSideMenuChildTypeLeft) {
  53. self.left = child;
  54. }
  55. else if(child.type == RNNSideMenuChildTypeRight) {
  56. self.right = child;
  57. }
  58. }
  59. else {
  60. @throw [NSException exceptionWithName:@"UnknownSideMenuControllerType" reason:[@"Unknown side menu type " stringByAppendingString:[controller description]] userInfo:nil];
  61. }
  62. }
  63. }
  64. - (UIStatusBarStyle)preferredStatusBarStyle {
  65. return self.openedViewController.preferredStatusBarStyle;
  66. }
  67. - (UIViewController *)openedViewController {
  68. switch (self.sideMenu.openSide) {
  69. case MMDrawerSideNone:
  70. return self.center;
  71. case MMDrawerSideLeft:
  72. return self.left;
  73. case MMDrawerSideRight:
  74. return self.right;
  75. default:
  76. return self.center;
  77. break;
  78. }
  79. }
  80. - (UIViewController<RNNLayoutProtocol> *)getLeafViewController {
  81. return [self.center getLeafViewController];
  82. }
  83. - (void)willMoveToParentViewController:(UIViewController *)parent {
  84. [_presenter present:self.options onViewControllerDidLoad:self];
  85. }
  86. @end