Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dismissActiveNotificationWithCompletion will now call completion even wh... #166

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions TSMessages/Classes/TSMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ typedef NS_ENUM(NSInteger,TSMessageNotificationDuration) {
atPosition:(TSMessageNotificationPosition)messagePosition
canBeDismissedByUser:(BOOL)dismissingEnabled;

/** Return YES if there is a notification, and that notification is fully display (check by messageIsFullyDisplayed method)
*/
+ (BOOL)hasFullyDisplayedNotification;

/** Fades out the currently displayed notification. If another notification is in the queue,
the next one will be displayed automatically
@return YES if the currently displayed notification was successfully dismissed. NO if no notification
Expand All @@ -148,11 +152,11 @@ typedef NS_ENUM(NSInteger,TSMessageNotificationDuration) {
+ (BOOL)dismissActiveNotification;

/** Fades out the currently displayed notification with a completion block after the animation has finished. If another notification is in the queue,
the next one will be displayed automatically
the next one will be displayed automatically. The completion block will be call even when there is nothing to dismiss (didDismissNotification will be NO in this case)
@return YES if the currently displayed notification was successfully dismissed. NO if no notification
was currently displayed.
was currently fully displayed.
*/
+ (BOOL)dismissActiveNotificationWithCompletion:(void (^)())completion;
+ (BOOL)dismissActiveNotificationWithCompletion:(void (^)(BOOL didDismissNotification))completion;

/** Use this method to set a default view controller to display the messages in */
+ (void)setDefaultViewController:(UIViewController *)defaultViewController;
Expand Down
39 changes: 31 additions & 8 deletions TSMessages/Classes/TSMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -362,25 +362,48 @@ - (void)fadeOutNotification:(TSMessageView *)currentView animationFinishedBlock:
}];
}

+ (BOOL)hasFullyDisplayedNotification {
if ([[TSMessage sharedMessage].messages count] > 0) {
TSMessageView *currentMessage = [[TSMessage sharedMessage].messages objectAtIndex:0];
if (currentMessage.messageIsFullyDisplayed)
{
return YES;
}
}
return NO;
}

+ (BOOL)dismissActiveNotification
{
return [self dismissActiveNotificationWithCompletion:nil];
}

+ (BOOL)dismissActiveNotificationWithCompletion:(void (^)())completion
+ (BOOL)dismissActiveNotificationWithCompletion:(void (^)(BOOL didDismissNotification))completion
{
if ([[TSMessage sharedMessage].messages count] == 0) return NO;

dispatch_async(dispatch_get_main_queue(), ^
{
if ([[TSMessage sharedMessage].messages count] == 0) return;
TSMessageView *currentMessage = [[TSMessage sharedMessage].messages objectAtIndex:0];
if (currentMessage.messageIsFullyDisplayed)
if ([[TSMessage sharedMessage].messages count] > 0)
{
[[TSMessage sharedMessage] fadeOutNotification:currentMessage animationFinishedBlock:completion];
TSMessageView *currentMessage = [[TSMessage sharedMessage].messages objectAtIndex:0];
if (currentMessage.messageIsFullyDisplayed)
{
[[TSMessage sharedMessage] fadeOutNotification:currentMessage animationFinishedBlock:^{
if (completion) {
completion(YES);
}
}];
}else {
if (completion) {
completion(NO);
}
}
}else {
if (completion) {
completion(NO);
}
}
});
return YES;
return [self hasFullyDisplayedNotification];
}

#pragma mark Customizing TSMessages
Expand Down