Skip to content

Commit

Permalink
Adding more support delegates to control the show and dismiss of the …
Browse files Browse the repository at this point in the history
…menu. Also a little bug correction for the not animated appearance of the menu (animation flag being ignored)
  • Loading branch information
George Villasboas committed Sep 10, 2013
1 parent 71477c9 commit dccabcb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
6 changes: 5 additions & 1 deletion RNFrostedSidebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
//
// Original Dribbble shot by Jakub Antalik
// http://dribbble.com/shots/1194205-Sidebar-calendar-animation
//
//

#import <UIKit/UIKit.h>

@class RNFrostedSidebar;

@protocol RNFrostedSidebarDelegate <NSObject>
@optional
- (void)sidebar:(RNFrostedSidebar *)sidebar willShowOnScreenAnimated:(BOOL)animatedYesOrNo;
- (void)sidebar:(RNFrostedSidebar *)sidebar didShowOnScreenAnimated:(BOOL)animatedYesOrNo;
- (void)sidebar:(RNFrostedSidebar *)sidebar willDismissFromScreenAnimated:(BOOL)animatedYesOrNo;
- (void)sidebar:(RNFrostedSidebar *)sidebar didDismissFromScreenAnimated:(BOOL)animatedYesOrNo;
- (void)sidebar:(RNFrostedSidebar *)sidebar didTapItemAtIndex:(NSUInteger)index;
- (void)sidebar:(RNFrostedSidebar *)sidebar didEnable:(BOOL)itemEnabled itemAtIndex:(NSUInteger)index;
@end
Expand Down
49 changes: 40 additions & 9 deletions RNFrostedSidebar.m
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,37 @@ - (void)showInViewController:(UIViewController *)controller animated:(BOOL)anima
blurFrame.origin.x = contentFrame.origin.x;
blurFrame.size.width = _width;

[UIView animateWithDuration:self.animationDuration
delay:0
options:kNilOptions
animations:^{
self.contentView.frame = contentFrame;
self.blurView.frame = blurFrame;
}
completion:nil];
// tell the delegate that the menu is about to show on screen
if ([self.delegate respondsToSelector:@selector(sidebar:willShowOnScreenAnimated:)]) {
[self.delegate sidebar:self willShowOnScreenAnimated:animated];
}

if (animated) {
[UIView animateWithDuration:self.animationDuration
delay:0
options:kNilOptions
animations:^{
self.contentView.frame = contentFrame;
self.blurView.frame = blurFrame;
}
completion:^(BOOL finished) {
if (finished) {
// tell the delegate that the menu just finished showing on screen
if ([self.delegate respondsToSelector:@selector(sidebar:didShowOnScreenAnimated:)]) {
[self.delegate sidebar:self didShowOnScreenAnimated:animated];
}
}
}];
}
else{
self.contentView.frame = contentFrame;
self.blurView.frame = blurFrame;

// tell the delegate that the menu just finished showing on screen
if ([self.delegate respondsToSelector:@selector(sidebar:didShowOnScreenAnimated:)]) {
[self.delegate sidebar:self didShowOnScreenAnimated:animated];
}
}

CGFloat initDelay = 0.1f;
SEL sdkSpringSelector = NSSelectorFromString(@"animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:");
Expand Down Expand Up @@ -455,8 +478,16 @@ - (void)dismiss {
- (void)dismissAnimated:(BOOL)animated {
void (^completion)(BOOL) = ^(BOOL finished){
[self rn_removeFromParentViewControllerCallingAppearanceMethods:YES];

if ([self.delegate respondsToSelector:@selector(sidebar:didDismissFromScreenAnimated:)]) {
[self.delegate sidebar:self didDismissFromScreenAnimated:YES];
}
};

if ([self.delegate respondsToSelector:@selector(sidebar:willDismissFromScreenAnimated:)]) {
[self.delegate sidebar:self willDismissFromScreenAnimated:YES];
}

if (animated) {
CGFloat parentWidth = self.view.bounds.size.width;
CGRect contentFrame = self.contentView.frame;
Expand Down Expand Up @@ -605,7 +636,7 @@ - (void)rn_addToParentViewController:(UIViewController *)parentViewController ca
if (callAppearanceMethods) [self endAppearanceTransition];
}

- (void)rn_removeFromParentViewControllerCallingAppearanceMethods:(BOOL)callAppearanceMethods {
- (void)rn_removeFromParentViewControllerCallingAppearanceMethods:(BOOL)callAppearanceMethods {
if (callAppearanceMethods) [self beginAppearanceTransition:NO animated:NO];
[self willMoveToParentViewController:nil];
[self.view removeFromSuperview];
Expand Down

0 comments on commit dccabcb

Please sign in to comment.