react-native-navigation的迁移库

RNNSideMenuController.m 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 optionsResolver:(RNNParentOptionsResolver *)optionsResolver presenter:(RNNBasePresenter *)presenter {
  19. self = [super init];
  20. self.presenter = presenter;
  21. self.options = options;
  22. self.layoutInfo = layoutInfo;
  23. self.optionsResolver = optionsResolver;
  24. [self bindChildViewControllers:childViewControllers];
  25. // Fixes #3697
  26. [self setExtendedLayoutIncludesOpaqueBars:YES];
  27. self.edgesForExtendedLayout |= UIRectEdgeBottom;
  28. return self;
  29. }
  30. - (void)bindChildViewControllers:(NSArray<UIViewController<RNNLayoutProtocol> *> *)viewControllers {
  31. [self setControllers:viewControllers];
  32. self.sideMenu = [[MMDrawerController alloc] initWithCenterViewController:self.center leftDrawerViewController:self.left rightDrawerViewController:self.right];
  33. self.sideMenu.openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
  34. self.sideMenu.closeDrawerGestureModeMask = MMCloseDrawerGestureModeAll;
  35. [self addChildViewController:self.sideMenu];
  36. [self.sideMenu.view setFrame:self.view.bounds];
  37. [self.view addSubview:self.sideMenu.view];
  38. [self.view bringSubviewToFront:self.sideMenu.view];
  39. }
  40. -(void)showSideMenu:(MMDrawerSide)side animated:(BOOL)animated {
  41. [self.sideMenu openDrawerSide:side animated:animated completion:nil];
  42. }
  43. -(void)hideSideMenu:(MMDrawerSide)side animated:(BOOL)animated {
  44. [self.sideMenu closeDrawerAnimated:animated completion:nil];
  45. }
  46. -(void)setControllers:(NSArray*)controllers {
  47. for (id controller in controllers) {
  48. if ([controller isKindOfClass:[RNNSideMenuChildVC class]]) {
  49. RNNSideMenuChildVC *child = (RNNSideMenuChildVC*)controller;
  50. if (child.type == RNNSideMenuChildTypeCenter) {
  51. self.center = child;
  52. }
  53. else if(child.type == RNNSideMenuChildTypeLeft) {
  54. self.left = child;
  55. }
  56. else if(child.type == RNNSideMenuChildTypeRight) {
  57. self.right = child;
  58. }
  59. }
  60. else {
  61. @throw [NSException exceptionWithName:@"UnknownSideMenuControllerType" reason:[@"Unknown side menu type " stringByAppendingString:[controller description]] userInfo:nil];
  62. }
  63. }
  64. }
  65. - (UIStatusBarStyle)preferredStatusBarStyle {
  66. return self.openedViewController.preferredStatusBarStyle;
  67. }
  68. - (UIViewController *)openedViewController {
  69. switch (self.sideMenu.openSide) {
  70. case MMDrawerSideNone:
  71. return self.center;
  72. case MMDrawerSideLeft:
  73. return self.left;
  74. case MMDrawerSideRight:
  75. return self.right;
  76. default:
  77. return self.center;
  78. break;
  79. }
  80. }
  81. - (UIViewController<RNNLayoutProtocol> *)getLeafViewController {
  82. return [self.center getLeafViewController];
  83. }
  84. - (void)willMoveToParentViewController:(UIViewController *)parent {
  85. [_optionsResolver resolve:self with:self.childViewControllers];
  86. [_presenter present:self.options onViewControllerDidLoad:self];
  87. }
  88. - (void)mergeOptions:(RNNNavigationOptions *)options {
  89. [self.options mergeOptions:options overrideOptions:YES];
  90. [self.presenter present:self.options onViewControllerWillAppear:self];
  91. }
  92. @end