react-native-navigation的迁移库

RNNSideMenuPresenter.m 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #import "RNNSideMenuPresenter.h"
  2. #import "RNNSideMenuController.h"
  3. @implementation RNNSideMenuPresenter
  4. -(instancetype)initWithDefaultOptions:(RNNNavigationOptions *)defaultOptions {
  5. self = [super initWithDefaultOptions:defaultOptions];
  6. return self;
  7. }
  8. - (void)applyOptions:(RNNNavigationOptions *)options {
  9. [super applyOptions:options];
  10. RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
  11. RNNSideMenuController* sideMenuController = self.boundViewController;
  12. [sideMenuController side:MMDrawerSideLeft enabled:[withDefault.sideMenu.left.enabled getWithDefaultValue:YES]];
  13. [sideMenuController side:MMDrawerSideRight enabled:[withDefault.sideMenu.right.enabled getWithDefaultValue:YES]];
  14. [sideMenuController setShouldStretchLeftDrawer:[withDefault.sideMenu.left.shouldStretchDrawer getWithDefaultValue:YES]];
  15. [sideMenuController setShouldStretchRightDrawer:[withDefault.sideMenu.right.shouldStretchDrawer getWithDefaultValue:YES]];
  16. [sideMenuController setAnimationVelocityLeft:[withDefault.sideMenu.left.animationVelocity getWithDefaultValue:840.0f]];
  17. [sideMenuController setAnimationVelocityRight:[withDefault.sideMenu.right.animationVelocity getWithDefaultValue:840.0f]];
  18. [sideMenuController setAnimationType:[withDefault.sideMenu.animationType getWithDefaultValue:nil]];
  19. if (withDefault.sideMenu.left.width.hasValue) {
  20. [sideMenuController side:MMDrawerSideLeft width:withDefault.sideMenu.left.width.get];
  21. }
  22. if (withDefault.sideMenu.right.width.hasValue) {
  23. [sideMenuController side:MMDrawerSideRight width:withDefault.sideMenu.right.width.get];
  24. }
  25. if (withDefault.sideMenu.left.visible.hasValue) {
  26. [sideMenuController side:MMDrawerSideLeft visible:withDefault.sideMenu.left.visible.get];
  27. [withDefault.sideMenu.left.visible consume];
  28. }
  29. if (withDefault.sideMenu.right.visible.hasValue) {
  30. [sideMenuController side:MMDrawerSideRight visible:withDefault.sideMenu.right.visible.get];
  31. [withDefault.sideMenu.right.visible consume];
  32. }
  33. }
  34. - (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions {
  35. [super applyOptionsOnInit:initialOptions];
  36. RNNNavigationOptions *withDefault = [initialOptions withDefault:[self defaultOptions]];
  37. RNNSideMenuController* sideMenuController = self.boundViewController;
  38. if (withDefault.sideMenu.left.width.hasValue) {
  39. [sideMenuController side:MMDrawerSideLeft width:withDefault.sideMenu.left.width.get];
  40. }
  41. if (withDefault.sideMenu.right.width.hasValue) {
  42. [sideMenuController side:MMDrawerSideRight width:withDefault.sideMenu.right.width.get];
  43. }
  44. [sideMenuController setOpenDrawerGestureModeMask:[[withDefault.sideMenu.openGestureMode getWithDefaultValue:@(MMOpenDrawerGestureModeAll)] integerValue]];
  45. }
  46. - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions {
  47. [super mergeOptions:newOptions currentOptions:currentOptions];
  48. RNNSideMenuController* sideMenuController = self.boundViewController;
  49. if (newOptions.sideMenu.left.enabled.hasValue) {
  50. [sideMenuController side:MMDrawerSideLeft enabled:newOptions.sideMenu.left.enabled.get];
  51. [newOptions.sideMenu.left.enabled consume];
  52. }
  53. if (newOptions.sideMenu.right.enabled.hasValue) {
  54. [sideMenuController side:MMDrawerSideRight enabled:newOptions.sideMenu.right.enabled.get];
  55. [newOptions.sideMenu.right.enabled consume];
  56. }
  57. if (newOptions.sideMenu.left.visible.hasValue) {
  58. [sideMenuController side:MMDrawerSideLeft visible:newOptions.sideMenu.left.visible.get];
  59. [newOptions.sideMenu.left.visible consume];
  60. }
  61. if (newOptions.sideMenu.right.visible.hasValue) {
  62. [sideMenuController side:MMDrawerSideRight visible:newOptions.sideMenu.right.visible.get];
  63. [newOptions.sideMenu.right.visible consume];
  64. }
  65. if (newOptions.sideMenu.left.width.hasValue) {
  66. [sideMenuController side:MMDrawerSideLeft width:newOptions.sideMenu.left.width.get];
  67. }
  68. if (newOptions.sideMenu.right.width.hasValue) {
  69. [sideMenuController side:MMDrawerSideRight width:newOptions.sideMenu.right.width.get];
  70. }
  71. if (newOptions.sideMenu.left.shouldStretchDrawer.hasValue) {
  72. sideMenuController.shouldStretchLeftDrawer = newOptions.sideMenu.left.shouldStretchDrawer.get;
  73. }
  74. if (newOptions.sideMenu.right.shouldStretchDrawer.hasValue) {
  75. sideMenuController.shouldStretchRightDrawer = newOptions.sideMenu.right.shouldStretchDrawer.get;
  76. }
  77. if (newOptions.sideMenu.left.animationVelocity.hasValue) {
  78. sideMenuController.animationVelocityLeft = newOptions.sideMenu.left.animationVelocity.get;
  79. }
  80. if (newOptions.sideMenu.right.animationVelocity.hasValue) {
  81. sideMenuController.animationVelocityRight = newOptions.sideMenu.right.animationVelocity.get;
  82. }
  83. if (newOptions.sideMenu.animationType.hasValue) {
  84. [sideMenuController setAnimationType:newOptions.sideMenu.animationType.get];
  85. }
  86. }
  87. @end