From e71a1698839562bdc7ab3d9cb61c175b6b0ba268 Mon Sep 17 00:00:00 2001 From: Isaac Greenspan Date: Mon, 18 May 2015 16:20:22 -0500 Subject: [PATCH 1/8] Use `static` to limit the scope of the constants to the compilation unit (basically, to the .m file) and prefix and export the default diameter to allow consumers of RKNotificationHub to use it. --- RKNotificationHub/RKNotificationHub.h | 5 +++++ RKNotificationHub/RKNotificationHub.m | 24 ++++++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/RKNotificationHub/RKNotificationHub.h b/RKNotificationHub/RKNotificationHub.h index e750bc9..f052d25 100644 --- a/RKNotificationHub/RKNotificationHub.h +++ b/RKNotificationHub/RKNotificationHub.h @@ -34,6 +34,11 @@ #import #import +/** + * The default diameter of the notification hub view. + */ +FOUNDATION_EXPORT CGFloat RKNotificationHubDefaultDiameter; + @interface RKNotificationHub : NSObject //%%% setup diff --git a/RKNotificationHub/RKNotificationHub.m b/RKNotificationHub/RKNotificationHub.m index aa3ebdf..73546b6 100644 --- a/RKNotificationHub/RKNotificationHub.m +++ b/RKNotificationHub/RKNotificationHub.m @@ -10,22 +10,22 @@ #import //%%% default diameter -CGFloat kDefaultDiameter = 30; -CGFloat kCountMagnitudeAdaptationRatio = 0.3; +CGFloat RKNotificationHubDefaultDiameter = 30; +static CGFloat kCountMagnitudeAdaptationRatio = 0.3; //%%% pop values -CGFloat kPopStartRatio = .85; -CGFloat kPopOutRatio = 1.05; -CGFloat kPopInRatio = .95; +static CGFloat kPopStartRatio = .85; +static CGFloat kPopOutRatio = 1.05; +static CGFloat kPopInRatio = .95; //%%% blink values -CGFloat kBlinkDuration = 0.1; -CGFloat kBlinkAlpha = 0.1; +static CGFloat kBlinkDuration = 0.1; +static CGFloat kBlinkAlpha = 0.1; //%%% bump values -CGFloat kFirstBumpDistance = 8.0; -CGFloat kBumpTimeSeconds = 0.13; -CGFloat SECOND_BUMP_DIST = 4.0; -CGFloat kBumpTimeSeconds2 = 0.1; +static CGFloat kFirstBumpDistance = 8.0; +static CGFloat kBumpTimeSeconds = 0.13; +static CGFloat SECOND_BUMP_DIST = 4.0; +static CGFloat kBumpTimeSeconds2 = 0.1; @interface RKView : UIView @property (nonatomic) BOOL isUserChangingBackgroundColor; @@ -99,7 +99,7 @@ - (void)setView:(UIView *)view andCount:(int)startCount [countLabel setTextAlignment:NSTextAlignmentCenter]; countLabel.textColor = [UIColor whiteColor]; - [self setCircleAtFrame:CGRectMake(frame.size.width- (kDefaultDiameter*2/3), -kDefaultDiameter/3, kDefaultDiameter, kDefaultDiameter)]; + [self setCircleAtFrame:CGRectMake(frame.size.width- (RKNotificationHubDefaultDiameter*2/3), -RKNotificationHubDefaultDiameter/3, RKNotificationHubDefaultDiameter, RKNotificationHubDefaultDiameter)]; [view addSubview:redCircle]; [view addSubview:countLabel]; From 511f3399b1c73d49977cebbfde121d7a6b296973 Mon Sep 17 00:00:00 2001 From: Isaac Greenspan Date: Mon, 18 May 2015 16:21:30 -0500 Subject: [PATCH 2/8] Add the `const` keyword to indicate that the constants are compile-time constant. --- RKNotificationHub/RKNotificationHub.h | 2 +- RKNotificationHub/RKNotificationHub.m | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/RKNotificationHub/RKNotificationHub.h b/RKNotificationHub/RKNotificationHub.h index f052d25..1233d6d 100644 --- a/RKNotificationHub/RKNotificationHub.h +++ b/RKNotificationHub/RKNotificationHub.h @@ -37,7 +37,7 @@ /** * The default diameter of the notification hub view. */ -FOUNDATION_EXPORT CGFloat RKNotificationHubDefaultDiameter; +FOUNDATION_EXPORT CGFloat const RKNotificationHubDefaultDiameter; @interface RKNotificationHub : NSObject diff --git a/RKNotificationHub/RKNotificationHub.m b/RKNotificationHub/RKNotificationHub.m index 73546b6..000ef38 100644 --- a/RKNotificationHub/RKNotificationHub.m +++ b/RKNotificationHub/RKNotificationHub.m @@ -10,22 +10,22 @@ #import //%%% default diameter -CGFloat RKNotificationHubDefaultDiameter = 30; -static CGFloat kCountMagnitudeAdaptationRatio = 0.3; +CGFloat const RKNotificationHubDefaultDiameter = 30; +static CGFloat const kCountMagnitudeAdaptationRatio = 0.3; //%%% pop values -static CGFloat kPopStartRatio = .85; -static CGFloat kPopOutRatio = 1.05; -static CGFloat kPopInRatio = .95; +static CGFloat const kPopStartRatio = .85; +static CGFloat const kPopOutRatio = 1.05; +static CGFloat const kPopInRatio = .95; //%%% blink values -static CGFloat kBlinkDuration = 0.1; -static CGFloat kBlinkAlpha = 0.1; +static CGFloat const kBlinkDuration = 0.1; +static CGFloat const kBlinkAlpha = 0.1; //%%% bump values -static CGFloat kFirstBumpDistance = 8.0; -static CGFloat kBumpTimeSeconds = 0.13; -static CGFloat SECOND_BUMP_DIST = 4.0; -static CGFloat kBumpTimeSeconds2 = 0.1; +static CGFloat const kFirstBumpDistance = 8.0; +static CGFloat const kBumpTimeSeconds = 0.13; +static CGFloat const SECOND_BUMP_DIST = 4.0; +static CGFloat const kBumpTimeSeconds2 = 0.1; @interface RKView : UIView @property (nonatomic) BOOL isUserChangingBackgroundColor; From e72b8efbb6f30229081a8495b8d3cb86ebfc2bb6 Mon Sep 17 00:00:00 2001 From: Isaac Greenspan Date: Mon, 18 May 2015 16:22:33 -0500 Subject: [PATCH 3/8] Increment the podspec version. --- RKNotificationHub.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RKNotificationHub.podspec b/RKNotificationHub.podspec index c282a3c..18c44b6 100644 --- a/RKNotificationHub.podspec +++ b/RKNotificationHub.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| # s.name = "RKNotificationHub" -s.version = "1.0.5" +s.version = "1.0.6" s.summary = "iOS: Make any UIView a full fledged notification center" s.description = "A simple one line solution to turning adding a notification bubble to any UIView. Easily increment, decrement, an animate the notification, -Notification, -Notification Center, -objectivec, -ios, -iphone, -xcode" From 9bdd1f68ea93d7bebe77b2d9abf2703253897316 Mon Sep 17 00:00:00 2001 From: Isaac Greenspan Date: Mon, 18 May 2015 16:33:15 -0500 Subject: [PATCH 4/8] Convert count to an NSUInteger @property. --- RKNotificationHub/RKNotificationHub.h | 9 +++---- RKNotificationHub/RKNotificationHub.m | 38 +++++++++++---------------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/RKNotificationHub/RKNotificationHub.h b/RKNotificationHub/RKNotificationHub.h index 1233d6d..7c8c145 100644 --- a/RKNotificationHub/RKNotificationHub.h +++ b/RKNotificationHub/RKNotificationHub.h @@ -46,7 +46,7 @@ FOUNDATION_EXPORT CGFloat const RKNotificationHubDefaultDiameter; - (id)initWithBarButtonItem:(UIBarButtonItem *)barButtonItem; //%%% adjustment methods -- (void)setView:(UIView *)view andCount:(int)startCount; +- (void)setView:(UIView *)view andCount:(NSUInteger)startCount; - (void)setCircleAtFrame:(CGRect)frame; - (void)setCircleColor:(UIColor*)circleColor labelColor:(UIColor*)labelColor; - (void)moveCircleByX:(CGFloat)x Y:(CGFloat)y; @@ -55,11 +55,10 @@ FOUNDATION_EXPORT CGFloat const RKNotificationHubDefaultDiameter; //%%% changing the count - (void)increment; -- (void)incrementBy:(int)amount; +- (void)incrementBy:(NSUInteger)amount; - (void)decrement; -- (void)decrementBy:(int)amount; -- (void)setCount:(int)newCount; -- (int)count; // returns the count (treat as get method) +- (void)decrementBy:(NSUInteger)amount; +@property (nonatomic, assign) NSUInteger count; //%%% hiding / showing the count - (void)hideCount; diff --git a/RKNotificationHub/RKNotificationHub.m b/RKNotificationHub/RKNotificationHub.m index 000ef38..6858d42 100644 --- a/RKNotificationHub/RKNotificationHub.m +++ b/RKNotificationHub/RKNotificationHub.m @@ -45,7 +45,6 @@ - (void)setBackgroundColor:(UIColor *)backgroundColor @implementation RKNotificationHub { - int count; int curOrderMagnitude; UILabel *countLabel; RKView *redCircle; @@ -80,7 +79,7 @@ - (id)initWithBarButtonItem:(UIBarButtonItem *)barButtonItem //%%% give this a view and an initial count (0 hides the notification circle) // and it will make a hub for you -- (void)setView:(UIView *)view andCount:(int)startCount +- (void)setView:(UIView *)view andCount:(NSUInteger)startCount { curOrderMagnitude = 0; @@ -95,7 +94,7 @@ - (void)setView:(UIView *)view andCount:(int)startCount countLabel = [[UILabel alloc]initWithFrame:redCircle.frame]; countLabel.userInteractionEnabled = NO; - [self setCount:startCount]; + self.count = startCount; [countLabel setTextAlignment:NSTextAlignmentCenter]; countLabel.textColor = [UIColor whiteColor]; @@ -169,44 +168,39 @@ - (void)showCount //%%% increases count by 1 - (void)increment { - [self setCount:count+1]; + [self incrementBy:1]; } //%%% increases count by amount -- (void)incrementBy:(int)amount +- (void)incrementBy:(NSUInteger)amount { - [self setCount:count+amount]; + self.count += amount; } //%%% decreases count - (void)decrement { - if (count == 0) { - return; - } - [self setCount:count-1]; + [self decrementBy:1]; } //%%% decreases count by amount -- (void)decrementBy:(int)amount +- (void)decrementBy:(NSUInteger)amount { - [self setCount:count-amount]; + if (amount >= self.count) { + self.count = 0; + } + self.count -= amount; } //%%% set the count yourself -- (void)setCount:(int)newCount +- (void)setCount:(NSUInteger)newCount { - count = newCount; - countLabel.text = [NSString stringWithFormat:@"%i",count]; + _count = newCount; + countLabel.text = [NSString stringWithFormat:@"%@", @(self.count)]; [self checkZero]; [self expandToFitLargerDigits]; } -- (int)count -{ - return count; -} - //%% set the font of the label - (void)setCountLabelFont:(UIFont *)font { @@ -367,7 +361,7 @@ - (void)setAlpha:(float)alpha //%%% hides the notification if the value is 0 - (void)checkZero { - if (count <= 0) { + if (self.count <= 0) { redCircle.hidden = YES; countLabel.hidden = YES; } else { @@ -379,7 +373,7 @@ - (void)checkZero } - (void)expandToFitLargerDigits { - int orderOfMagnitude = log10((double)count); + int orderOfMagnitude = log10((double)self.count); orderOfMagnitude = (orderOfMagnitude >= 2) ? orderOfMagnitude : 1; CGRect frame = initialFrame; frame.size.width = initialFrame.size.width * (1 + kCountMagnitudeAdaptationRatio * (orderOfMagnitude - 1)); From 53d98822b7b66012c0921e0bd170dbb00fa8d190 Mon Sep 17 00:00:00 2001 From: Isaac Greenspan Date: Mon, 18 May 2015 16:52:02 -0500 Subject: [PATCH 5/8] Make countLabelFont a property (proxy to the underlying count label's font property). --- RKNotificationHub/RKNotificationHub.h | 2 +- RKNotificationHub/RKNotificationHub.m | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/RKNotificationHub/RKNotificationHub.h b/RKNotificationHub/RKNotificationHub.h index 7c8c145..316d8db 100644 --- a/RKNotificationHub/RKNotificationHub.h +++ b/RKNotificationHub/RKNotificationHub.h @@ -51,7 +51,7 @@ FOUNDATION_EXPORT CGFloat const RKNotificationHubDefaultDiameter; - (void)setCircleColor:(UIColor*)circleColor labelColor:(UIColor*)labelColor; - (void)moveCircleByX:(CGFloat)x Y:(CGFloat)y; - (void)scaleCircleSizeBy:(CGFloat)scale; -- (void)setCountLabelFont:(UIFont *)font; +@property (nonatomic, strong) UIFont *countLabelFont; //%%% changing the count - (void)increment; diff --git a/RKNotificationHub/RKNotificationHub.m b/RKNotificationHub/RKNotificationHub.m index 6858d42..65aa8cb 100644 --- a/RKNotificationHub/RKNotificationHub.m +++ b/RKNotificationHub/RKNotificationHub.m @@ -207,6 +207,11 @@ - (void)setCountLabelFont:(UIFont *)font [countLabel setFont:[UIFont fontWithName:font.fontName size:redCircle.frame.size.width/2]]; } +- (UIFont *)countLabelFont +{ + return countLabel.font; +} + #pragma mark - ANIMATION //%%% animation that resembles facebook's pop From 3a26f3221923cd2c3b9aba04b4f74974c973af18 Mon Sep 17 00:00:00 2001 From: Isaac Greenspan Date: Mon, 18 May 2015 17:09:29 -0500 Subject: [PATCH 6/8] Update README. --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 80f25e7..a4af2cd 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,10 @@ Code: ``` ``` objc -(void)increment; - -(void)incrementBy:(int)amount; + -(void)incrementBy:(NSUInteger)amount; -(void)decrement; - -(void)decrementBy:(int)amount; - -(void)setCount:(int)newCount; //%%% set to a certain number + -(void)decrementBy:(NSUInteger)amount; + -(void)setCount:(NSUInteger)newCount; //%%% set to a certain number ``` __Combine Actions!__ @@ -73,7 +73,6 @@ __Combine Actions!__ **It isn't incrementing / decrementing properly!** * I've written it so that any count < 1 doesn't show up. If you need help customizing this, reach out to me -* Calling [decrement] will never bring the count below 0, but calling [decrementBy:] or [setCount:] will allow negative values (negative values still won't show up) **The circle is in a weird place** * If you want to resize the circle, use [scaleCircleSizeBy:]. 0.5 will give you half the size, 2 will give you double @@ -91,6 +90,7 @@ __Combine Actions!__ * 1.0.1 cocoapod allows iOS 7.0 * 1.0.2 added "hideCount", "showCount", and "count" methods, allowing indeterminate badges with no number * 1.0.5 added bubble expansion for larger numbers [(gif)](http://i.imgur.com/cpQuShT.gif) +* 1.0.6 changed count to `NSUInteger`, made local constants `static const` ### Areas for Improvements / involvement * A mechanism for adding a custom animation From fce5a8cdc01de4da7c97020672d381c7f8b25c60 Mon Sep 17 00:00:00 2001 From: Isaac Greenspan Date: Tue, 19 May 2015 10:41:42 -0500 Subject: [PATCH 7/8] Insert missing short-circuit return. --- RKNotificationHub/RKNotificationHub.m | 1 + 1 file changed, 1 insertion(+) diff --git a/RKNotificationHub/RKNotificationHub.m b/RKNotificationHub/RKNotificationHub.m index 65aa8cb..1d89dab 100644 --- a/RKNotificationHub/RKNotificationHub.m +++ b/RKNotificationHub/RKNotificationHub.m @@ -188,6 +188,7 @@ - (void)decrementBy:(NSUInteger)amount { if (amount >= self.count) { self.count = 0; + return; } self.count -= amount; } From d2fd2d5e3f8bf5a94bd1933f636ade432da95c1a Mon Sep 17 00:00:00 2001 From: Isaac Greenspan Date: Tue, 19 May 2015 13:10:29 -0500 Subject: [PATCH 8/8] Update podspec and README to reflect version 2.0.0 and call out removal of support for negative counts. --- README.md | 2 +- RKNotificationHub.podspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a4af2cd..b3babbf 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ __Combine Actions!__ * 1.0.1 cocoapod allows iOS 7.0 * 1.0.2 added "hideCount", "showCount", and "count" methods, allowing indeterminate badges with no number * 1.0.5 added bubble expansion for larger numbers [(gif)](http://i.imgur.com/cpQuShT.gif) -* 1.0.6 changed count to `NSUInteger`, made local constants `static const` +* 2.0.0 changed count to `NSUInteger` (removed support for negative counts), made local constants `static const` ### Areas for Improvements / involvement * A mechanism for adding a custom animation diff --git a/RKNotificationHub.podspec b/RKNotificationHub.podspec index 18c44b6..f12b65c 100644 --- a/RKNotificationHub.podspec +++ b/RKNotificationHub.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| # s.name = "RKNotificationHub" -s.version = "1.0.6" +s.version = "2.0.0" s.summary = "iOS: Make any UIView a full fledged notification center" s.description = "A simple one line solution to turning adding a notification bubble to any UIView. Easily increment, decrement, an animate the notification, -Notification, -Notification Center, -objectivec, -ios, -iphone, -xcode"