react-native-navigation的迁移库

RNNSideMenuController.m 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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;
  19. {
  20. self = [super init];
  21. [self setControllers:controllers];
  22. self.sideMenu = [[MMDrawerController alloc] initWithCenterViewController:self.center leftDrawerViewController:self.left rightDrawerViewController:self.right];
  23. self.sideMenu.openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
  24. self.sideMenu.closeDrawerGestureModeMask = MMCloseDrawerGestureModeAll;
  25. [self addChildViewController:self.sideMenu];
  26. [self.sideMenu.view setFrame:self.view.bounds];
  27. [self.view addSubview:self.sideMenu.view];
  28. [self.view bringSubviewToFront:self.sideMenu.view];
  29. return self;
  30. }
  31. -(void)showSideMenu:(MMDrawerSide)side animated:(BOOL)animated {
  32. [self.sideMenu openDrawerSide:side animated:animated completion:nil];
  33. }
  34. -(void)hideSideMenu:(MMDrawerSide)side animated:(BOOL)animated {
  35. [self.sideMenu closeDrawerAnimated:animated completion:nil];
  36. }
  37. -(void)setControllers:(NSArray*)controllers {
  38. for (id controller in controllers) {
  39. if ([controller isKindOfClass:[RNNSideMenuChildVC class]]) {
  40. RNNSideMenuChildVC *child = (RNNSideMenuChildVC*)controller;
  41. if (child.type == RNNSideMenuChildTypeCenter) {
  42. self.center = child;
  43. }
  44. else if(child.type == RNNSideMenuChildTypeLeft) {
  45. self.left = child;
  46. }
  47. else if(child.type == RNNSideMenuChildTypeRight) {
  48. self.right = child;
  49. }
  50. }
  51. else {
  52. @throw [NSException exceptionWithName:@"UnknownSideMenuControllerType" reason:[@"Unknown side menu type " stringByAppendingString:[controller description]] userInfo:nil];
  53. }
  54. }
  55. }
  56. - (UIStatusBarStyle)preferredStatusBarStyle {
  57. return self.openedViewController.preferredStatusBarStyle;
  58. }
  59. - (UIViewController *)openedViewController {
  60. switch (self.sideMenu.openSide) {
  61. case MMDrawerSideNone:
  62. return self.center;
  63. case MMDrawerSideLeft:
  64. return self.left;
  65. case MMDrawerSideRight:
  66. return self.right;
  67. default:
  68. return self.center;
  69. break;
  70. }
  71. }
  72. - (RNNRootViewController *)getLeafViewController {
  73. return [self.center getLeafViewController];
  74. }
  75. @end