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

Add parameter forceDismiss to dismissActiveNotification method #113

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions TSMessages/Classes/TSMessage.h
Expand Up @@ -115,6 +115,14 @@ typedef NS_ENUM(NSInteger,TSMessageNotificationDuration) {
*/
+ (BOOL)dismissActiveNotification;

/** Fades out the currently displayed notification. If another notification is in the queue,
the next one will be displayed automatically
@param forceDismiss Should the message be dismissed even if it is not fully displayed
@return YES if the currently displayed notification was successfully dismissed. NO if no notification
was currently displayed.
*/
+ (BOOL)dismissActiveNotification:(BOOL)forceDismiss;

/** Use this method to set a default view controller to display the messages in */
+ (void)setDefaultViewController:(UIViewController *)defaultViewController;

Expand Down
9 changes: 7 additions & 2 deletions TSMessages/Classes/TSMessage.m
Expand Up @@ -306,22 +306,27 @@ - (void)fadeOutNotification:(TSMessageView *)currentView
}];
}

+ (BOOL)dismissActiveNotification
+ (BOOL)dismissActiveNotification:(BOOL)forceDismiss
{
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 (forceDismiss || currentMessage.messageIsFullyDisplayed)
{
[[TSMessage sharedMessage] fadeOutNotification:currentMessage];
}
});
return YES;
}

+ (BOOL)dismissActiveNotification
{
return [TSMessage dismissActiveNotification: NO];
}

#pragma mark Customizing TSMessages

+ (void)setDefaultViewController:(UIViewController *)defaultViewController
Expand Down