react-native-navigation的迁移库

RCCDrawerController.m 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #import "RCCDrawerController.h"
  2. #import "RCCViewController.h"
  3. #import "MMExampleDrawerVisualStateManager.h"
  4. #import "RCCDrawerHelper.h"
  5. #import <React/RCTConvert.h>
  6. #import "RCCManagerModule.h"
  7. #import "UIViewController+Rotation.h"
  8. #define RCCDRAWERCONTROLLER_ANIMATION_DURATION 0.33f
  9. @implementation RCCDrawerController
  10. @synthesize drawerStyle = _drawerStyle;
  11. -(UIInterfaceOrientationMask)supportedInterfaceOrientations {
  12. return [self supportedControllerOrientations];
  13. }
  14. - (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children globalProps:(NSDictionary*)globalProps bridge:(RCTBridge *)bridge
  15. {
  16. self.drawerStyle = props[@"style"];
  17. // center
  18. if ([children count] < 1) return nil;
  19. UIViewController *centerViewController = [RCCViewController controllerWithLayout:children[0] globalProps:globalProps bridge:bridge];
  20. // left
  21. UIViewController *leftViewController = nil;
  22. NSString *componentLeft = props[@"componentLeft"];
  23. NSDictionary *passPropsLeft = props[@"passPropsLeft"];
  24. if (componentLeft) leftViewController = [[RCCViewController alloc] initWithComponent:componentLeft passProps:passPropsLeft navigatorStyle:nil globalProps:globalProps bridge:bridge];
  25. // right
  26. UIViewController *rightViewController = nil;
  27. NSString *componentRight = props[@"componentRight"];
  28. NSDictionary *passPropsRight = props[@"passPropsRight"];
  29. if (componentRight) rightViewController = [[RCCViewController alloc] initWithComponent:componentRight passProps:passPropsRight navigatorStyle:nil globalProps:globalProps bridge:bridge];
  30. self = [super initWithCenterViewController:centerViewController
  31. leftDrawerViewController:leftViewController
  32. rightDrawerViewController:rightViewController];
  33. [self setAnimationTypeWithName:props[@"animationType"]];
  34. // default is all MMOpenDrawerGestureModeAll and MMCloseDrawerGestureModeAll
  35. self.openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
  36. self.closeDrawerGestureModeMask = MMCloseDrawerGestureModeAll;
  37. NSNumber *disableOpenGesture = props[@"disableOpenGesture"];
  38. if ([disableOpenGesture boolValue]) {
  39. self.openDrawerGestureModeMask = MMOpenDrawerGestureModeNone;
  40. }
  41. [self setStyle];
  42. [self setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {
  43. MMDrawerControllerDrawerVisualStateBlock block;
  44. block = [[MMExampleDrawerVisualStateManager sharedManager] drawerVisualStateBlockForDrawerSide:drawerSide];
  45. if (block) {
  46. block(drawerController, drawerSide, percentVisible);
  47. }
  48. }];
  49. [self setGestureStartBlock:^(MMDrawerController *drawerController, UIGestureRecognizer *gesture) {
  50. [RCCManagerModule cancelAllRCCViewControllerReactTouches];
  51. }];
  52. self.view.backgroundColor = [UIColor clearColor];
  53. [self setRotation:props];
  54. if (!self) return nil;
  55. return self;
  56. }
  57. -(void)setStyle {
  58. if (self.drawerStyle[@"drawerShadow"]) {
  59. self.showsShadow = ([self.drawerStyle[@"drawerShadow"] boolValue]) ? YES : NO;
  60. }
  61. NSNumber *leftDrawerWidth = self.drawerStyle[@"leftDrawerWidth"];
  62. if (leftDrawerWidth) {
  63. self.maximumLeftDrawerWidth = self.view.bounds.size.width * MIN(1, (leftDrawerWidth.floatValue/100.0));
  64. }
  65. NSNumber *rightDrawerWidth = self.drawerStyle[@"rightDrawerWidth"];
  66. if (rightDrawerWidth) {
  67. self.maximumRightDrawerWidth = self.view.bounds.size.width * MIN(1, (rightDrawerWidth.floatValue/100.0));
  68. }
  69. NSString *contentOverlayColor = self.drawerStyle[@"contentOverlayColor"];
  70. if (contentOverlayColor)
  71. {
  72. UIColor *color = contentOverlayColor != (id)[NSNull null] ? [RCTConvert UIColor:contentOverlayColor] : nil;
  73. [self setCenterOverlayColor:color];
  74. }
  75. }
  76. - (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actionParams bridge:(RCTBridge *)bridge
  77. {
  78. MMDrawerSide side = MMDrawerSideLeft;
  79. if ([actionParams[@"side"] isEqualToString:@"right"]) side = MMDrawerSideRight;
  80. BOOL animated = actionParams[@"animated"] ? [actionParams[@"animated"] boolValue] : YES;
  81. // open
  82. if ([performAction isEqualToString:@"open"])
  83. {
  84. [self openDrawerSide:side animated:animated completion:nil];
  85. return;
  86. }
  87. // close
  88. if ([performAction isEqualToString:@"close"])
  89. {
  90. if (self.openSide == side) {
  91. [self closeDrawerAnimated:animated completion:nil];
  92. }
  93. return;
  94. }
  95. // toggle
  96. if ([performAction isEqualToString:@"toggle"])
  97. {
  98. [super toggleDrawerSide:side animated:animated completion:nil];
  99. return;
  100. }
  101. // setStyle
  102. if ([performAction isEqualToString:@"setStyle"])
  103. {
  104. if (actionParams[@"animationType"]) {
  105. NSString *animationTypeString = actionParams[@"animationType"];
  106. [self setAnimationTypeWithName:animationTypeString];
  107. }
  108. return;
  109. }
  110. }
  111. -(void)setAnimationTypeWithName:(NSString*)animationTypeName {
  112. MMDrawerAnimationType animationType = MMDrawerAnimationTypeNone;
  113. if ([animationTypeName isEqualToString:@"door"]) animationType = MMDrawerAnimationTypeSwingingDoor;
  114. else if ([animationTypeName isEqualToString:@"parallax"]) animationType = MMDrawerAnimationTypeParallax;
  115. else if ([animationTypeName isEqualToString:@"slide"]) animationType = MMDrawerAnimationTypeSlide;
  116. else if ([animationTypeName isEqualToString:@"slide-and-scale"]) animationType = MMDrawerAnimationTypeSlideAndScale;
  117. [MMExampleDrawerVisualStateManager sharedManager].leftDrawerAnimationType = animationType;
  118. [MMExampleDrawerVisualStateManager sharedManager].rightDrawerAnimationType = animationType;
  119. }
  120. @end