Skip to content

Commit

Permalink
Warn about non sensible options, support for DBL_MAX time interval
Browse files Browse the repository at this point in the history
  • Loading branch information
Collin Ruffenach committed Mar 17, 2014
1 parent b4b1c1a commit 86d133c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
27 changes: 26 additions & 1 deletion CRToast/CRToast.m
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,30 @@ - (CGPoint)outCollisionPoint2 {
return (CGPoint){x, y};
}

- (void)warnAboutSensibility {
if (self.notificationType == CRToastTypeStatusBar) {
if (self.displayUnderStatusBar) {
NSLog(@"[CRToast] : WARNING - It is not sensible to have set kCRToastNotificationTypeKey to @(CRToastTypeStatusBar) while setting kCRToastUnderStatusBarKey to @(YES). I'll do what you ask, but it'll probably work weird");
}

if (self.subtitleText) {
NSLog(@"[CRToast] : WARNING - It is not sensible to have set kCRToastNotificationTypeKey to @(CRToastTypeStatusBar) and configuring subtitle text to show. I'll do what you ask, but it'll probably work weird");
}
}

if (self.inAnimationType == CRToastAnimationTypeGravity) {
if (self.animateInTimeInterval != kCRAnimateInTimeIntervalDefault) {
NSLog(@"[CRToast] : WARNING - It is not sensible to have set kCRToastAnimationInTypeKey to @(CRToastAnimationTypeGravity) and configure a kCRToastAnimationInTimeIntervalKey. Gravity and distance will be driving the in animation duration here. kCRToastAnimationGravityMagnitudeKey can be modified to change the in animation duration.");
}
}

if (self.outAnimationType == CRToastAnimationTypeGravity) {
if (self.animateOutTimeInterval != kCRAnimateOutTimeIntervalDefault) {
NSLog(@"[CRToast] : WARNING - It is not sensible to have set kCRToastAnimationOutTypeKey to @(CRToastAnimationTypeGravity) and configure a kCRToastAnimationOutTimeIntervalKey. Gravity and distance will be driving the in animation duration here. kCRToastAnimationGravityMagnitudeKey can be modified to change the in animation duration.");
}
}
}

- (void)setOptions:(NSDictionary *)options {
NSMutableDictionary *cleanOptions = [options mutableCopy];
[options enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
Expand All @@ -849,6 +873,7 @@ - (void)setOptions:(NSDictionary *)options {
}
}];
_options = [NSDictionary dictionaryWithDictionary:cleanOptions];
[self warnAboutSensibility];
}

#pragma mark - UIGestureRecognizerDelegate
Expand Down Expand Up @@ -1188,7 +1213,7 @@ - (void)displayNotification:(CRToast*)notification {

NSString *notificationUUIDString = notification.uuid.UUIDString;
CRToastAnimationCompltionBlock inwardAnimationsCompletionBlock = ^void(BOOL finished) {
if (notification.state == CRToastStateEntering) {
if (notification.timeInterval != DBL_MAX && notification.state == CRToastStateEntering) {
notification.state = CRToastStateDisplaying;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(notification.timeInterval * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (weakSelf.notification.state == CRToastStateDisplaying && [weakSelf.notification.uuid.UUIDString isEqualToString:notificationUUIDString]) {
Expand Down
1 change: 0 additions & 1 deletion CRToastDemo/MainViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ - (NSDictionary*)options {
kCRToastNotificationPresentationTypeKey : self.slideOverSwitch.on ? @(CRToastPresentationTypeCover) : @(CRToastPresentationTypePush),
kCRToastUnderStatusBarKey : @(self.slideUnderSwitch.on),
kCRToastTextKey : self.txtNotificationMessage.text,
kCRToastTimeIntervalKey : @(self.sliderDuration.value),
kCRToastTextAlignmentKey : @(self.textAlignment),
kCRToastTimeIntervalKey : @(self.sliderDuration.value),
kCRToastAnimationInTypeKey : @(CRToastAnimationTypeFromSegmentedControl(_inAnimationTypeSegmentedControl)),
Expand Down

0 comments on commit 86d133c

Please sign in to comment.