Skip to content

Commit

Permalink
Updated UI properties from mutualmobile#338
Browse files Browse the repository at this point in the history
  • Loading branch information
kcharwood committed Mar 11, 2015
1 parent 8eafdb8 commit dd06fde
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 10 deletions.
35 changes: 35 additions & 0 deletions MMDrawerController/MMDrawerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,27 @@ typedef void (^MMDrawerControllerDrawerVisualStateBlock)(MMDrawerController * dr
*/
@property (nonatomic, assign) BOOL showsShadow;

/**
The shadow radius of `centerViewController` when a drawer is open.
By default, this is set to 10.0f;
*/
@property (nonatomic, assign) CGFloat shadowRadius;

/**
The shadow opacity of `centerViewController` when a drawer is open.
By default, this is set to 0.8f;
*/
@property (nonatomic, assign) CGFloat shadowOpacity;

/**
The shadow offset of `centerViewController` when a drawer is open.
By default, this is set to (0, -3);
*/
@property (nonatomic, assign) CGSize shadowOffset;

/**
The flag determining if a custom background view should appear beneath the status bar, forcing the child content to be drawn lower than the status bar. This property is only available for > iOS 7.0 to take into account for the new behavior of the status bar.
Expand All @@ -214,6 +235,20 @@ typedef void (^MMDrawerControllerDrawerVisualStateBlock)(MMDrawerController * dr
*/
@property (nonatomic, strong) UIColor * statusBarViewBackgroundColor;

/**
The value determining panning range of centerView's bezel if the user can open drawer with 'MMOpenDrawerGestureModeBezelPanningCenterView' or close drawer with 'MMCloseDrawerGestureModeBezelPanningCenterView' .
By default, this is set 20.0f.
*/
@property (nonatomic, assign) CGFloat bezelPanningCenterViewRange;

/**
The value determining if the user can open or close drawer with panGesture velocity.
By default, this is set 200.0f.
*/
@property (nonatomic, assign) CGFloat panVelocityXAnimationThreshold;

///---------------------------------------
/// @name Initializing a `MMDrawerController`
///---------------------------------------
Expand Down
48 changes: 38 additions & 10 deletions MMDrawerController/MMDrawerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ - (id)initWithCoder:(NSCoder *)aDecoder{

-(id)initWithCenterViewController:(UIViewController *)centerViewController leftDrawerViewController:(UIViewController *)leftDrawerViewController rightDrawerViewController:(UIViewController *)rightDrawerViewController{
NSParameterAssert(centerViewController);
self = [super init];
self = [self init];
if(self){
[self setCenterViewController:centerViewController];
[self setLeftDrawerViewController:leftDrawerViewController];
Expand Down Expand Up @@ -191,6 +191,17 @@ -(void)commonSetup{
[self setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
[self setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeNone];
[self setCenterHiddenInteractionMode:MMDrawerOpenCenterInteractionModeNavigationBarOnly];

// set shadow related default values
self.shadowOpacity = MMDrawerDefaultShadowOpacity;
self.shadowRadius = MMDrawerDefaultShadowRadius;
self.shadowOffset = CGSizeMake(0, -3);

// set default bezel range for panGestureReconizer
self.bezelPanningCenterViewRange = MMDrawerBezelRange;

// set defualt panVelocityXAnimationThreshold
self.panVelocityXAnimationThreshold = MMDrawerPanVelocityXAnimationThreshold;
}

#pragma mark - State Restoration
Expand Down Expand Up @@ -859,6 +870,21 @@ -(void)setShowsShadow:(BOOL)showsShadow{
[self updateShadowForCenterView];
}

- (void)setShadowRadius:(CGFloat)shadowRadius{
_shadowRadius = shadowRadius;
[self updateShadowForCenterView];
}

- (void)setShadowOpacity:(CGFloat)shadowOpacity{
_shadowOpacity = shadowOpacity;
[self updateShadowForCenterView];
}

- (void)setShadowOffset:(CGSize)shadowOffset{
_shadowOffset = shadowOffset;
[self updateShadowForCenterView];
}

-(void)setOpenSide:(MMDrawerSide)openSide{
if(_openSide != openSide){
_openSide = openSide;
Expand Down Expand Up @@ -1097,14 +1123,14 @@ -(void)setNeedsStatusBarAppearanceUpdateIfSupported{
-(void)finishAnimationForPanGestureWithXVelocity:(CGFloat)xVelocity completion:(void(^)(BOOL finished))completion{
CGFloat currentOriginX = CGRectGetMinX(self.centerContainerView.frame);

CGFloat animationVelocity = MAX(ABS(xVelocity),MMDrawerPanVelocityXAnimationThreshold*2);
CGFloat animationVelocity = MAX(ABS(xVelocity),self.panVelocityXAnimationThreshold*2);

if(self.openSide == MMDrawerSideLeft) {
CGFloat midPoint = self.maximumLeftDrawerWidth / 2.0;
if(xVelocity > MMDrawerPanVelocityXAnimationThreshold){
if(xVelocity > self.panVelocityXAnimationThreshold){
[self openDrawerSide:MMDrawerSideLeft animated:YES velocity:animationVelocity animationOptions:UIViewAnimationOptionCurveEaseOut completion:completion];
}
else if(xVelocity < -MMDrawerPanVelocityXAnimationThreshold){
else if(xVelocity < -self.panVelocityXAnimationThreshold){
[self closeDrawerAnimated:YES velocity:animationVelocity animationOptions:UIViewAnimationOptionCurveEaseOut completion:completion];
}
else if(currentOriginX < midPoint){
Expand All @@ -1117,10 +1143,10 @@ -(void)finishAnimationForPanGestureWithXVelocity:(CGFloat)xVelocity completion:(
else if(self.openSide == MMDrawerSideRight){
currentOriginX = CGRectGetMaxX(self.centerContainerView.frame);
CGFloat midPoint = (CGRectGetWidth(self.childControllerContainerView.bounds)-self.maximumRightDrawerWidth) + (self.maximumRightDrawerWidth / 2.0);
if(xVelocity > MMDrawerPanVelocityXAnimationThreshold){
if(xVelocity > self.panVelocityXAnimationThreshold){
[self closeDrawerAnimated:YES velocity:animationVelocity animationOptions:UIViewAnimationOptionCurveEaseOut completion:completion];
}
else if (xVelocity < -MMDrawerPanVelocityXAnimationThreshold){
else if (xVelocity < -self.panVelocityXAnimationThreshold){
[self openDrawerSide:MMDrawerSideRight animated:YES velocity:animationVelocity animationOptions:UIViewAnimationOptionCurveEaseOut completion:completion];
}
else if(currentOriginX > midPoint){
Expand Down Expand Up @@ -1251,8 +1277,9 @@ -(void)updateShadowForCenterView{
UIView * centerView = self.centerContainerView;
if(self.showsShadow){
centerView.layer.masksToBounds = NO;
centerView.layer.shadowRadius = MMDrawerDefaultShadowRadius;
centerView.layer.shadowOpacity = MMDrawerDefaultShadowOpacity;
centerView.layer.shadowRadius = self.shadowRadius;
centerView.layer.shadowOpacity = self.shadowOpacity;
centerView.layer.shadowOffset = self.shadowOffset;

/** In the event this gets called a lot, we won't update the shadowPath
unless it needs to be updated (like during rotation) */
Expand All @@ -1269,6 +1296,7 @@ unless it needs to be updated (like during rotation) */
else if (centerView.layer.shadowPath != NULL) {
centerView.layer.shadowRadius = 0.f;
centerView.layer.shadowOpacity = 0.f;
centerView.layer.shadowOffset = CGSizeMake(0, -3);
centerView.layer.shadowPath = NULL;
centerView.layer.masksToBounds = YES;
}
Expand Down Expand Up @@ -1407,15 +1435,15 @@ -(BOOL)isPointContainedWithinCenterViewContentRect:(CGPoint)point{
-(BOOL)isPointContainedWithinLeftBezelRect:(CGPoint)point{
CGRect leftBezelRect = CGRectNull;
CGRect tempRect;
CGRectDivide(self.childControllerContainerView.bounds, &leftBezelRect, &tempRect, MMDrawerBezelRange, CGRectMinXEdge);
CGRectDivide(self.childControllerContainerView.bounds, &leftBezelRect, &tempRect, self.bezelPanningCenterViewRange, CGRectMinXEdge);
return (CGRectContainsPoint(leftBezelRect, point) &&
[self isPointContainedWithinCenterViewContentRect:point]);
}

-(BOOL)isPointContainedWithinRightBezelRect:(CGPoint)point{
CGRect rightBezelRect = CGRectNull;
CGRect tempRect;
CGRectDivide(self.childControllerContainerView.bounds, &rightBezelRect, &tempRect, MMDrawerBezelRange, CGRectMaxXEdge);
CGRectDivide(self.childControllerContainerView.bounds, &rightBezelRect, &tempRect, self.bezelPanningCenterViewRange, CGRectMaxXEdge);

return (CGRectContainsPoint(rightBezelRect, point) &&
[self isPointContainedWithinCenterViewContentRect:point]);
Expand Down

0 comments on commit dd06fde

Please sign in to comment.