react-native-navigation的迁移库

RNNSideMenuController.m 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 = MMOpenDrawerGestureModeAll;
  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. @end