Instantly share code, notes, and snippets.
Created
December 4, 2019 12:11
-
Save trantus/04b05afd8b79ff6cd11664d2c9afbc1a to your computer and use it in GitHub Desktop.
for V2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "RNNSideMenuPresenter.h" | |
#import "RNNSideMenuController.h" | |
@implementation RNNSideMenuPresenter | |
-(instancetype)initWithDefaultOptions:(RNNNavigationOptions *)defaultOptions { | |
self = [super initWithDefaultOptions:defaultOptions]; | |
return self; | |
} | |
- (void)applyOptions:(RNNNavigationOptions *)options { | |
[super applyOptions:options]; | |
RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]]; | |
RNNSideMenuController* sideMenuController = self.boundViewController; | |
[sideMenuController side:MMDrawerSideLeft enabled:[withDefault.sideMenu.left.enabled getWithDefaultValue:YES]]; | |
[sideMenuController side:MMDrawerSideRight enabled:[withDefault.sideMenu.right.enabled getWithDefaultValue:YES]]; | |
[sideMenuController setShouldStretchLeftDrawer:[withDefault.sideMenu.left.shouldStretchDrawer getWithDefaultValue:YES]]; | |
[sideMenuController setShouldStretchRightDrawer:[withDefault.sideMenu.right.shouldStretchDrawer getWithDefaultValue:YES]]; | |
[sideMenuController setAnimationVelocityLeft:[withDefault.sideMenu.left.animationVelocity getWithDefaultValue:840.0f]]; | |
[sideMenuController setAnimationVelocityRight:[withDefault.sideMenu.right.animationVelocity getWithDefaultValue:840.0f]]; | |
[sideMenuController setAnimationType:[withDefault.sideMenu.animationType getWithDefaultValue:nil]]; | |
if (withDefault.sideMenu.left.width.hasValue) { | |
[sideMenuController side:MMDrawerSideLeft width:withDefault.sideMenu.left.width.get]; | |
} | |
if (withDefault.sideMenu.right.width.hasValue) { | |
[sideMenuController side:MMDrawerSideRight width:withDefault.sideMenu.right.width.get]; | |
} | |
if (withDefault.sideMenu.left.visible.hasValue) { | |
[sideMenuController side:MMDrawerSideLeft visible:withDefault.sideMenu.left.visible.get]; | |
[withDefault.sideMenu.left.visible consume]; | |
} | |
if (withDefault.sideMenu.right.visible.hasValue) { | |
[sideMenuController side:MMDrawerSideRight visible:withDefault.sideMenu.right.visible.get]; | |
[withDefault.sideMenu.right.visible consume]; | |
} | |
if (options.sideMenu.left.enabled.hasValue) { | |
[sideMenuController side:MMDrawerSideLeft enabled:options.sideMenu.left.enabled.get]; | |
if(options.sideMenu.left.enabled.get){ | |
[sideMenuController setOpenDrawerGestureModeMask:[[options.sideMenu.openGestureMode getWithDefaultValue:@(MMOpenDrawerGestureModeAll)] integerValue]]; | |
} | |
else { | |
[sideMenuController setOpenDrawerGestureModeMask:[[options.sideMenu.openGestureMode getWithDefaultValue:@(MMOpenDrawerGestureModeNone)] integerValue]]; | |
} | |
[options.sideMenu.left.enabled consume]; | |
} | |
if (options.sideMenu.right.enabled.hasValue) { | |
[sideMenuController side:MMDrawerSideRight enabled:options.sideMenu.right.enabled.get]; | |
if(options.sideMenu.right.enabled.get){ | |
[sideMenuController setOpenDrawerGestureModeMask:[[options.sideMenu.openGestureMode getWithDefaultValue:@(MMOpenDrawerGestureModeAll)] integerValue]]; | |
} | |
else { | |
[sideMenuController setOpenDrawerGestureModeMask:[[options.sideMenu.openGestureMode getWithDefaultValue:@(MMOpenDrawerGestureModeNone)] integerValue]]; | |
} | |
[options.sideMenu.right.enabled consume]; | |
} | |
} | |
- (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions { | |
[super applyOptionsOnInit:initialOptions]; | |
RNNNavigationOptions *withDefault = [initialOptions withDefault:[self defaultOptions]]; | |
RNNSideMenuController* sideMenuController = self.boundViewController; | |
if (withDefault.sideMenu.left.width.hasValue) { | |
[sideMenuController side:MMDrawerSideLeft width:withDefault.sideMenu.left.width.get]; | |
} | |
if (withDefault.sideMenu.right.width.hasValue) { | |
[sideMenuController side:MMDrawerSideRight width:withDefault.sideMenu.right.width.get]; | |
} | |
if (withDefault.sideMenu.left.enabled.hasValue) { | |
[sideMenuController side:MMDrawerSideLeft enabled:withDefault.sideMenu.left.enabled.get]; | |
if(withDefault.sideMenu.left.enabled.get){ | |
[sideMenuController setOpenDrawerGestureModeMask:[[withDefault.sideMenu.openGestureMode getWithDefaultValue:@(MMOpenDrawerGestureModeAll)] integerValue]]; | |
} | |
else { | |
[sideMenuController setOpenDrawerGestureModeMask:[[withDefault.sideMenu.openGestureMode getWithDefaultValue:@(MMOpenDrawerGestureModeNone)] integerValue]]; | |
} | |
[withDefault.sideMenu.left.enabled consume]; | |
} | |
if (withDefault.sideMenu.right.enabled.hasValue) { | |
[sideMenuController side:MMDrawerSideRight enabled:withDefault.sideMenu.right.enabled.get]; | |
if(withDefault.sideMenu.right.enabled.get){ | |
[sideMenuController setOpenDrawerGestureModeMask:[[withDefault.sideMenu.openGestureMode getWithDefaultValue:@(MMOpenDrawerGestureModeAll)] integerValue]]; | |
} | |
else { | |
[sideMenuController setOpenDrawerGestureModeMask:[[withDefault.sideMenu.openGestureMode getWithDefaultValue:@(MMOpenDrawerGestureModeNone)] integerValue]]; | |
} | |
[withDefault.sideMenu.right.enabled consume]; | |
} | |
[sideMenuController setOpenDrawerGestureModeMask:[[withDefault.sideMenu.openGestureMode getWithDefaultValue:@(MMOpenDrawerGestureModeAll)] integerValue]]; | |
} | |
- (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions { | |
[super mergeOptions:newOptions currentOptions:currentOptions]; | |
RNNSideMenuController* sideMenuController = self.boundViewController; | |
if (newOptions.sideMenu.left.enabled.hasValue) { | |
[sideMenuController side:MMDrawerSideLeft enabled:newOptions.sideMenu.left.enabled.get]; | |
} | |
if (newOptions.sideMenu.right.enabled.hasValue) { | |
[sideMenuController side:MMDrawerSideRight enabled:newOptions.sideMenu.right.enabled.get]; | |
} | |
if (newOptions.sideMenu.left.visible.hasValue) { | |
[sideMenuController side:MMDrawerSideLeft visible:newOptions.sideMenu.left.visible.get]; | |
[newOptions.sideMenu.left.visible consume]; | |
} | |
if (newOptions.sideMenu.right.visible.hasValue) { | |
[sideMenuController side:MMDrawerSideRight visible:newOptions.sideMenu.right.visible.get]; | |
[newOptions.sideMenu.right.visible consume]; | |
} | |
if (newOptions.sideMenu.left.width.hasValue) { | |
[sideMenuController side:MMDrawerSideLeft width:newOptions.sideMenu.left.width.get]; | |
} | |
if (newOptions.sideMenu.right.width.hasValue) { | |
[sideMenuController side:MMDrawerSideRight width:newOptions.sideMenu.right.width.get]; | |
} | |
if (newOptions.sideMenu.left.shouldStretchDrawer.hasValue) { | |
sideMenuController.shouldStretchLeftDrawer = newOptions.sideMenu.left.shouldStretchDrawer.get; | |
} | |
if (newOptions.sideMenu.right.shouldStretchDrawer.hasValue) { | |
sideMenuController.shouldStretchRightDrawer = newOptions.sideMenu.right.shouldStretchDrawer.get; | |
} | |
if (newOptions.sideMenu.left.animationVelocity.hasValue) { | |
sideMenuController.animationVelocityLeft = newOptions.sideMenu.left.animationVelocity.get; | |
} | |
if (newOptions.sideMenu.right.animationVelocity.hasValue) { | |
sideMenuController.animationVelocityRight = newOptions.sideMenu.right.animationVelocity.get; | |
} | |
if (newOptions.sideMenu.animationType.hasValue) { | |
[sideMenuController setAnimationType:newOptions.sideMenu.animationType.get]; | |
} | |
if (newOptions.sideMenu.left.enabled.hasValue) { | |
[sideMenuController side:MMDrawerSideLeft enabled:newOptions.sideMenu.left.enabled.get]; | |
if(newOptions.sideMenu.left.enabled.get){ | |
[sideMenuController setOpenDrawerGestureModeMask:[[newOptions.sideMenu.openGestureMode getWithDefaultValue:@(MMOpenDrawerGestureModeAll)] integerValue]]; | |
} | |
else { | |
[sideMenuController setOpenDrawerGestureModeMask:[[newOptions.sideMenu.openGestureMode getWithDefaultValue:@(MMOpenDrawerGestureModeNone)] integerValue]]; | |
} | |
[newOptions.sideMenu.left.enabled consume]; | |
} | |
if (newOptions.sideMenu.right.enabled.hasValue) { | |
[sideMenuController side:MMDrawerSideRight enabled:newOptions.sideMenu.right.enabled.get]; | |
if(newOptions.sideMenu.right.enabled.get){ | |
[sideMenuController setOpenDrawerGestureModeMask:[[newOptions.sideMenu.openGestureMode getWithDefaultValue:@(MMOpenDrawerGestureModeAll)] integerValue]]; | |
} | |
else { | |
[sideMenuController setOpenDrawerGestureModeMask:[[newOptions.sideMenu.openGestureMode getWithDefaultValue:@(MMOpenDrawerGestureModeNone)] integerValue]]; | |
} | |
[newOptions.sideMenu.right.enabled consume]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment