react-native-navigation的迁移库

RNNSideMenuController.m 3.3KB

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