react-native-navigation的迁移库

RNNSideMenuSideOptions.m 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #import "RNNSideMenuSideOptions.h"
  2. #import "RNNSideMenuController.h"
  3. #import "MMDrawerVisualState.h"
  4. @implementation RNNSideMenuSideOptions
  5. - (void)applyOnSide:(MMDrawerSide)side viewController:(UIViewController *)viewController {
  6. RNNSideMenuController* sideMenuController = [self getParentSideMenuControllerFromChild:viewController];
  7. if (sideMenuController) {
  8. if (self.enabled) {
  9. switch (side) {
  10. case MMDrawerSideRight:
  11. sideMenuController.sideMenu.rightSideEnabled = [self.enabled boolValue];
  12. break;
  13. case MMDrawerSideLeft:
  14. sideMenuController.sideMenu.leftSideEnabled = [self.enabled boolValue];
  15. default:
  16. break;
  17. }
  18. sideMenuController.sideMenu.openDrawerGestureModeMask = [self.enabled boolValue] ? MMOpenDrawerGestureModeAll : MMOpenDrawerGestureModeNone;
  19. }
  20. if (self.visible) {
  21. if (self.visible.boolValue) {
  22. [sideMenuController showSideMenu:side animated:YES];
  23. } else {
  24. [sideMenuController hideSideMenu:side animated:YES];
  25. }
  26. }
  27. if (self.shouldStretchDrawer) {
  28. sideMenuController.sideMenu.shouldStretchDrawer = self.shouldStretchDrawer.boolValue;
  29. }
  30. if (self.animationVelocity) {
  31. sideMenuController.sideMenu.animationVelocity = [self.animationVelocity doubleValue];
  32. }
  33. MMDrawerControllerDrawerVisualStateBlock animationTypeStateBlock = nil;
  34. if ([self.animationType isEqualToString:@"door"]) animationTypeStateBlock = [MMDrawerVisualState swingingDoorVisualStateBlock];
  35. else if ([self.animationType isEqualToString:@"parallax"]) animationTypeStateBlock = [MMDrawerVisualState parallaxVisualStateBlockWithParallaxFactor:2.0];
  36. else if ([self.animationType isEqualToString:@"slide"]) animationTypeStateBlock = [MMDrawerVisualState slideVisualStateBlock];
  37. else if ([self.animationType isEqualToString:@"slide-and-scale"]) animationTypeStateBlock = [MMDrawerVisualState slideAndScaleVisualStateBlock];
  38. if (animationTypeStateBlock) {
  39. [sideMenuController.sideMenu setDrawerVisualStateBlock:animationTypeStateBlock];
  40. }
  41. if (self.width) {
  42. switch (side) {
  43. case MMDrawerSideRight:
  44. sideMenuController.sideMenu.maximumRightDrawerWidth = self.width.floatValue;
  45. break;
  46. case MMDrawerSideLeft:
  47. sideMenuController.sideMenu.maximumLeftDrawerWidth = self.width.floatValue;
  48. default:
  49. break;
  50. }
  51. }
  52. }
  53. [self resetOptions];
  54. }
  55. - (RNNSideMenuController *)getParentSideMenuControllerFromChild:(UIViewController *)childViewController {
  56. UIViewController* vc = childViewController;
  57. while (vc) {
  58. if ([vc isKindOfClass:[RNNSideMenuController class]]) {
  59. return (RNNSideMenuController *)vc;
  60. }
  61. vc = vc.parentViewController;
  62. }
  63. return nil;
  64. }
  65. - (void)resetOptions {
  66. self.visible = nil;
  67. self.enabled = nil;
  68. }
  69. @end