From 95f692c225f1dd891f206b3b07fbcd458c6201f0 Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 23 Oct 2015 17:19:45 +0300 Subject: [PATCH] Slide menu notifications extends params added --- SlideMenu/Source/SlideNavigationController.h | 2 ++ SlideMenu/Source/SlideNavigationController.m | 29 ++++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/SlideMenu/Source/SlideNavigationController.h b/SlideMenu/Source/SlideNavigationController.h index 5b96d97..57b0689 100644 --- a/SlideMenu/Source/SlideNavigationController.h +++ b/SlideMenu/Source/SlideNavigationController.h @@ -48,6 +48,8 @@ extern NSString * const SlideNavigationControllerDidOpen; extern NSString *const SlideNavigationControllerDidClose; extern NSString *const SlideNavigationControllerDidReveal; +extern NSString *const SlideMenuOpenAfterSwipeKey; + @property (nonatomic, assign) BOOL avoidSwitchingToSameClassViewController; @property (nonatomic, assign) BOOL enableSwipeGesture; @property (nonatomic, assign) BOOL enableShadow; diff --git a/SlideMenu/Source/SlideNavigationController.m b/SlideMenu/Source/SlideNavigationController.m index 4da2079..1e8f525 100644 --- a/SlideMenu/Source/SlideNavigationController.m +++ b/SlideMenu/Source/SlideNavigationController.m @@ -47,6 +47,8 @@ NSString * const SlideNavigationControllerDidOpen = @"SlideNavigationControllerD NSString * const SlideNavigationControllerDidClose = @"SlideNavigationControllerDidClose"; NSString *const SlideNavigationControllerDidReveal = @"SlideNavigationControllerDidReveal"; +NSString *const SlideMenuOpenAfterSwipeKey = @"SlideMenuOpenAfterSwipeKey"; + #define MENU_SLIDE_ANIMATION_DURATION .3 #define MENU_SLIDE_OPEN_ANIMATION_DURATION .4 #define MENU_SLIDE_CLOSE_ANIMATION_DURATION .2 @@ -467,6 +469,11 @@ static SlideNavigationController *singletonInstance; } - (void)openMenu:(Menu)menu withCompletion:(void (^)())completion +{ + [self openMenu:menu afterSwipe:NO withCompletion:completion]; +} + +- (void)openMenu:(Menu)menu afterSwipe:(BOOL)afterSwipe withCompletion:(void (^)())completion { NSTimeInterval duration = self.menuOpenAnimationDuration; @@ -487,7 +494,9 @@ static SlideNavigationController *singletonInstance; if (completion) completion(); - [self postNotificationWithName:SlideNavigationControllerDidOpen forMenu:menu]; + [self postNotificationWithName:SlideNavigationControllerDidOpen forMenu:menu withExtParams:@{ + SlideMenuOpenAfterSwipeKey : @(afterSwipe) + }]; }]; } @@ -653,9 +662,17 @@ static SlideNavigationController *singletonInstance; - (void)postNotificationWithName:(NSString *)name forMenu:(Menu)menu { + [self postNotificationWithName:name forMenu:menu withExtParams:nil]; +} + +- (void)postNotificationWithName:(NSString *)name forMenu:(Menu)menu withExtParams:(NSDictionary *)extParams +{ + NSMutableDictionary *userInfo = extParams ? [extParams mutableCopy] : [NSMutableDictionary dictionary]; + NSString *menuString = (menu == MenuLeft) ? NOTIFICATION_USER_INFO_MENU_LEFT : NOTIFICATION_USER_INFO_MENU_RIGHT; - NSDictionary *userInfo = @{ NOTIFICATION_USER_INFO_MENU : menuString }; - [[NSNotificationCenter defaultCenter] postNotificationName:name object:nil userInfo:userInfo]; + userInfo[NOTIFICATION_USER_INFO_MENU] = menuString; + + [[NSNotificationCenter defaultCenter] postNotificationName:name object:nil userInfo:[userInfo copy]]; } #pragma mark - UINavigationControllerDelegate Methods - @@ -769,7 +786,7 @@ static SlideNavigationController *singletonInstance; if (currentX > 0) { if ([self shouldDisplayMenu:menu forViewController:self.visibleViewController]) - [self openMenu:(velocity.x > 0) ? MenuLeft : MenuRight withCompletion:nil]; + [self openMenu:(velocity.x > 0) ? MenuLeft : MenuRight afterSwipe:YES withCompletion:nil]; } else { @@ -786,7 +803,7 @@ static SlideNavigationController *singletonInstance; else { if ([self shouldDisplayMenu:menu forViewController:self.visibleViewController]) - [self openMenu:(velocity.x > 0) ? MenuLeft : MenuRight withCompletion:nil]; + [self openMenu:(velocity.x > 0) ? MenuLeft : MenuRight afterSwipe:YES withCompletion:nil]; } } } @@ -795,7 +812,7 @@ static SlideNavigationController *singletonInstance; if (currentXOffset < (self.horizontalSize - self.slideOffset)/2) [self closeMenuWithCompletion:nil]; else - [self openMenu:(currentX > 0) ? MenuLeft : MenuRight withCompletion:nil]; + [self openMenu:(currentX > 0) ? MenuLeft : MenuRight afterSwipe:YES withCompletion:nil]; } } }