react-native-navigation的迁移库

RNNSideMenuController.m 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. - (BOOL)isCustomTransitioned {
  57. return NO;
  58. }
  59. - (BOOL)isAnimated {
  60. return YES;
  61. }
  62. - (RNNOptions *)options {
  63. return nil;
  64. }
  65. - (NSString *)componentId {
  66. return _center.componentId;
  67. }
  68. @end