react-native-navigation的迁移库

RNNSideMenuController.m 3.6KB

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