Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Commit

Permalink
Cleanups for v1.0.0!
Browse files Browse the repository at this point in the history
Simplify code and reorganize project
  • Loading branch information
Mazyod committed Nov 14, 2015
1 parent 6300326 commit 06195c9
Show file tree
Hide file tree
Showing 14 changed files with 247 additions and 199 deletions.
2 changes: 1 addition & 1 deletion TLYShyNavBar.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Pod::Spec.new do |s|
s.source_files = "TLYShyNavBar/**/*"
s.exclude_files = ""

s.public_header_files = "TLYShyNavBar/TLYShyNavBarManager.h"
s.public_header_files = "TLYShyNavBar/*.h"


# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
Expand Down
16 changes: 16 additions & 0 deletions TLYShyNavBar/Categories/UIScrollView+Helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// UIScrollView+Helpers.h
// TLYShyNavBarDemo
//
// Created by Mazyad Alabduljaleel on 11/13/15.
// Copyright © 2015 Telly, Inc. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface UIScrollView (Helpers)

- (void)tly_smartSetInsets:(UIEdgeInsets)contentAndScrollIndicatorInsets;

@end
26 changes: 26 additions & 0 deletions TLYShyNavBar/Categories/UIScrollView+Helpers.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// UIScrollView+Helpers.m
// TLYShyNavBarDemo
//
// Created by Mazyad Alabduljaleel on 11/13/15.
// Copyright © 2015 Telly, Inc. All rights reserved.
//

#import "UIScrollView+Helpers.h"

@implementation UIScrollView (Helpers)

// Modify contentInset and scrollIndicatorInsets while preserving visual content offset
- (void)tly_smartSetInsets:(UIEdgeInsets)contentAndScrollIndicatorInsets
{
if (contentAndScrollIndicatorInsets.top != self.contentInset.top)
{
CGPoint contentOffset = self.contentOffset;
contentOffset.y -= contentAndScrollIndicatorInsets.top - self.contentInset.top;
self.contentOffset = contentOffset;
}

self.contentInset = self.scrollIndicatorInsets = contentAndScrollIndicatorInsets;
}

@end
20 changes: 20 additions & 0 deletions TLYShyNavBar/ShyControllers/TLYShyParent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// TLYShyParent.h
// TLYShyNavBarDemo
//
// Created by Mazyad Alabduljaleel on 11/13/15.
// Copyright © 2015 Telly, Inc. All rights reserved.
//

#ifndef TLYShyParent_h
#define TLYShyParent_h

@protocol TLYShyParent <NSObject>

@property (nonatomic, readonly) CGFloat viewMaxY;

- (CGFloat)calculateTotalHeightRecursively;

@end

#endif /* TLYShyParent_h */
17 changes: 17 additions & 0 deletions TLYShyNavBar/ShyControllers/TLYShyStatusBarController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// TLYShyStatusBarController.h
// TLYShyNavBarDemo
//
// Created by Mazyad Alabduljaleel on 11/13/15.
// Copyright © 2015 Telly, Inc. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "TLYShyParent.h"


@interface TLYShyStatusBarController : NSObject <TLYShyParent>

@property (nonatomic, weak) UIViewController *viewController;

@end
68 changes: 68 additions & 0 deletions TLYShyNavBar/ShyControllers/TLYShyStatusBarController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// TLYShyStatusBarController.m
// TLYShyNavBarDemo
//
// Created by Mazyad Alabduljaleel on 11/13/15.
// Copyright © 2015 Telly, Inc. All rights reserved.
//

#import "TLYShyStatusBarController.h"


// Thanks to SO user, MattDiPasquale
// http://stackoverflow.com/questions/12991935/how-to-programmatically-get-ios-status-bar-height/16598350#16598350

static inline CGFloat AACStatusBarHeight(UIViewController *viewController)
{
if ([UIApplication sharedApplication].statusBarHidden)
{
return 0.f;
}

// Modal views do not overlap the status bar, so no allowance need be made for it
CGSize statusBarSize = [UIApplication sharedApplication].statusBarFrame.size;
CGFloat statusBarHeight = MIN(statusBarSize.width, statusBarSize.height);

UIView *view = viewController.view;
CGRect frame = [view.superview convertRect:view.frame toView:view.window];

BOOL viewOverlapsStatusBar = frame.origin.y < statusBarHeight;

if (!viewOverlapsStatusBar)
{
return 0.f;
}

return statusBarHeight;
}


@implementation TLYShyStatusBarController

- (CGFloat)_statusBarHeight
{
CGFloat statusBarHeight = AACStatusBarHeight(self.viewController);
/* The standard status bar is 20 pixels. The navigation bar extends 20 pixels up so it is overlapped by the status bar.
* When there is a larger than 20 pixel status bar (e.g. a phone call is in progress or GPS is active), the center needs
* to shift up 20 pixels to avoid this 'dead space' being visible above the usual nav bar.
*/
if (statusBarHeight > 20)
{
statusBarHeight -= 20;
}

return statusBarHeight;
}

- (CGFloat)viewMaxY
{
return [self _statusBarHeight];
}

- (CGFloat)calculateTotalHeightRecursively
{
return [self _statusBarHeight];
}

@end

Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,16 @@

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "TLYShyParent.h"
#import "../TLYShyNavBarFade.h"


extern const CGFloat contractionVelocity;

typedef CGPoint(^TLYShyViewControllerExpandedCenterBlock)(UIView *view);
typedef CGFloat(^TLYShyViewControllerContractionAmountBlock)(UIView *view);


/** This enum is duplicated in the manager header, as to not cause headaches
* for users looking to update the library in Cocoapods.
*/
typedef NS_ENUM(NSInteger, TLYShyNavViewControllerFade) {

TLYShyNavViewControllerFadeDisabled,
TLYShyNavViewControllerFadeSubviews,
TLYShyNavViewControllerFadeNavbar,
};

@protocol TLYShyViewControllerParent <NSObject>

@property (nonatomic, readonly) CGFloat viewMaxY;

- (CGFloat)calculateTotalHeightRecursively;

@end

/* CLASS DESCRIPTION:
* ==================
* A shy view is a view that contracts when a scrolling event is
Expand All @@ -47,10 +32,10 @@ typedef NS_ENUM(NSInteger, TLYShyNavViewControllerFade) {
@interface TLYShyViewController : NSObject

@property (nonatomic, weak) TLYShyViewController *child;
@property (nonatomic, weak) id<TLYShyViewControllerParent> parent;
@property (nonatomic, weak) id<TLYShyParent> parent;
@property (nonatomic, weak) UIView *view;

@property (nonatomic) TLYShyNavViewControllerFade fadeBehavior;
@property (nonatomic) TLYShyNavBarFade fadeBehavior;

@property (nonatomic, readonly) CGFloat totalHeight;

Expand All @@ -69,5 +54,5 @@ typedef NS_ENUM(NSInteger, TLYShyNavViewControllerFade) {
@end


@interface TLYShyViewController (AsParent) <TLYShyViewControllerParent>
@interface TLYShyViewController (AsParent) <TLYShyParent>
@end
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ - (CGFloat)calculateTotalHeightRecursively

@interface TLYShyViewController ()

@property (nonatomic) CGPoint expandedCenterValue;
@property (nonatomic) CGFloat contractionAmountValue;
@property (nonatomic, assign) CGPoint expandedCenterValue;
@property (nonatomic, assign) CGFloat contractionAmountValue;

@property (nonatomic) CGPoint contractedCenterValue;
@property (nonatomic, assign) CGPoint contractedCenterValue;

@property (nonatomic, getter = isContracted) BOOL contracted;
@property (nonatomic, getter = isExpanded) BOOL expanded;
@property (nonatomic, assign) BOOL contracted;
@property (nonatomic, assign) BOOL expanded;

@end

Expand Down Expand Up @@ -61,12 +61,12 @@ - (CGPoint)contractedCenterValue
return CGPointMake(self.expandedCenterValue.x, self.expandedCenterValue.y - self.contractionAmountValue);
}

- (BOOL)isContracted
- (BOOL)contracted
{
return fabs(self.view.center.y - self.contractedCenterValue.y) < FLT_EPSILON;
}

- (BOOL)isExpanded
- (BOOL)expanded
{
return fabs(self.view.center.y - self.expandedCenterValue.y) < FLT_EPSILON;
}
Expand All @@ -89,17 +89,17 @@ - (void)_onAlphaUpdate:(CGFloat)alpha

switch (self.fadeBehavior) {

case TLYShyNavViewControllerFadeDisabled:
case TLYShyNavBarFadeDisabled:
self.view.alpha = 1.f;
[self _updateSubviewsAlpha:1.f];
break;

case TLYShyNavViewControllerFadeSubviews:
case TLYShyNavBarFadeSubviews:
self.view.alpha = 1.f;
[self _updateSubviewsAlpha:alpha];
break;

case TLYShyNavViewControllerFadeNavbar:
case TLYShyNavBarFadeNavbar:
self.view.alpha = alpha;
[self _updateSubviewsAlpha:1.f];
break;
Expand Down Expand Up @@ -133,11 +133,11 @@ - (void)_updateCenter:(CGPoint)newCenter

#pragma mark - Public methods

- (void)setFadeBehavior:(TLYShyNavViewControllerFade)fadeBehavior
- (void)setFadeBehavior:(TLYShyNavBarFade)fadeBehavior
{
_fadeBehavior = fadeBehavior;

if (fadeBehavior == TLYShyNavViewControllerFadeDisabled)
if (fadeBehavior == TLYShyNavBarFadeDisabled)
{
[self _onAlphaUpdate:1.f];
}
Expand All @@ -153,10 +153,10 @@ - (void)offsetCenterBy:(CGPoint)deltaPoint

- (CGFloat)updateYOffset:(CGFloat)deltaY
{
if (self.child && deltaY < 0)
if (self.child && !self.child.sticky && deltaY < 0)
{
deltaY = [self.child updateYOffset:deltaY];
self.child.view.hidden = (!self.child.sticky && deltaY < 0);
self.child.view.hidden = deltaY < 0;
}

CGFloat newYOffset = self.view.center.y + deltaY;
Expand All @@ -171,14 +171,11 @@ - (CGFloat)updateYOffset:(CGFloat)deltaY

CGFloat residual = newYOffset - newYCenter;

if (self.child && deltaY > 0 && residual > 0)
if (self.child && !self.child.sticky && deltaY > 0 && residual > 0)
{
residual = [self.child updateYOffset:residual];
self.child.view.hidden = (!self.child.sticky && residual - (newYOffset - newYCenter) > FLT_EPSILON);
}
else if (self.child.sticky && deltaY > 0)
{
[self.child updateYOffset:deltaY];
CGFloat newResidual = [self.child updateYOffset:residual];
self.child.view.hidden = newResidual - residual > FLT_EPSILON;
residual = newResidual;
}

return residual;
Expand All @@ -200,7 +197,7 @@ - (CGFloat)snap:(BOOL)contract
__block CGFloat deltaY;
[UIView animateWithDuration:0.2 animations:^
{
if ((contract && self.child.isContracted) || (!contract && !self.isExpanded))
if ((contract && self.child.contracted) || (!contract && !self.expanded))
{
deltaY = [self contract];
}
Expand Down
21 changes: 21 additions & 0 deletions TLYShyNavBar/TLYShyNavBarFade.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// TLYShyNavBarFade.h
// TLYShyNavBarDemo
//
// Created by Mazyad Alabduljaleel on 11/13/15.
// Copyright © 2015 Telly, Inc. All rights reserved.
//

#ifndef TLYShyNavBarFade_h
#define TLYShyNavBarFade_h

/** This enum helps control the navigation bar fade behavior.
*/
typedef NS_ENUM(NSInteger, TLYShyNavBarFade) {

TLYShyNavBarFadeDisabled,
TLYShyNavBarFadeSubviews,
TLYShyNavBarFadeNavbar,
};

#endif /* TLYShyNavBarFade_h */
26 changes: 1 addition & 25 deletions TLYShyNavBar/TLYShyNavBarManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,9 @@

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "TLYShyNavBarFade.h"


/** This enum helps control the navigation bar fade behavior.
* NOTE: It is duplicated in the ShyNavController header for now.
*/
typedef NS_ENUM(NSInteger, TLYShyNavBarFade) {

TLYShyNavBarFadeDisabled,
TLYShyNavBarFadeSubviews,
TLYShyNavBarFadeNavbar,
};

/** CLASS DESCRIPTION:
* ==================
* Manages the relationship between a scrollView and a view
Expand Down Expand Up @@ -100,18 +91,3 @@ typedef NS_ENUM(NSInteger, TLYShyNavBarFade) {

@end


/* DEPRECATED:
* ===========
* Please move away from using these properties, as they will be
* removed in the next major release.
*/
@interface TLYShyNavBarManager (Deprecated)

@property (nonatomic, getter = isAlphaFadeEnabled) BOOL alphaFadeEnabled
DEPRECATED_MSG_ATTRIBUTE("use fadeBehavior = TLYShyNavBarFade(Subviews or None)");

@property (nonatomic, getter = isAlphaFadeEntireNavBarEnabled) BOOL alphaFadeEntireNavBar
DEPRECATED_MSG_ATTRIBUTE("use fadeBehavior = TLYShyNavBarFadeNavbar");

@end
Loading

0 comments on commit 06195c9

Please sign in to comment.