react-native-navigation的迁移库

RNNSideMenuController.m 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. - (UIViewController *)getLeafViewController {
  73. return self.center;
  74. }
  75. - (void)mergeOptions:(RNNOptions *)options {
  76. [self.center mergeOptions:options];
  77. }
  78. - (void)waitForReactViewRender:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock {
  79. [self.center waitForReactViewRender:wait perform:readyBlock];
  80. }
  81. - (NSString *)componentId {
  82. return _center.componentId;
  83. }
  84. @end