react-native-navigation的迁移库

RNNSideMenuPresenter.m 4.8KB

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