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 option to execute callback after timeout #212

Open
wants to merge 2 commits 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
3 changes: 3 additions & 0 deletions Pod/Classes/TSMessage.h
Expand Up @@ -69,6 +69,9 @@ typedef NS_ENUM(NSInteger,TSMessageNotificationDuration) {
/** By setting this delegate it's possible to set a custom offset for the notification view */
@property (nonatomic, assign) id <TSMessageViewProtocol>delegate;

/** Whether or not a specified callback function should be executed on timeout instead of just on button tap **/
@property (nonatomic) BOOL executeCallbackOnTimeout;

+ (instancetype)sharedMessage;

+ (UIViewController *)defaultViewController;
Expand Down
3 changes: 3 additions & 0 deletions Pod/Classes/TSMessage.m
Expand Up @@ -327,6 +327,9 @@ + (BOOL)isNavigationBarInNavigationControllerHidden:(UINavigationController *)na
- (void)fadeOutNotification:(TSMessageView *)currentView
{
[self fadeOutNotification:currentView animationFinishedBlock:nil];
if (self.executeCallbackOnTimeout) {
[currentView executeCallback];
}
}

- (void)fadeOutNotification:(TSMessageView *)currentView animationFinishedBlock:(void (^)())animationFinished
Expand Down
3 changes: 3 additions & 0 deletions Pod/Classes/TSMessageView.h
Expand Up @@ -62,6 +62,9 @@ canBeDismissedByUser:(BOOL)dismissingEnabled;
/** Fades out this notification view */
- (void)fadeMeOut;

/** Executes the callback (called by TSMessage on fadeout) **/
- (void)executeCallback;

/** Use this method to load a custom design file */
+ (void)addNotificationDesignFromFile:(NSString *)file;

Expand Down
7 changes: 7 additions & 0 deletions Pod/Classes/TSMessageView.m
Expand Up @@ -477,6 +477,13 @@ - (void)fadeMeOut
[[TSMessage sharedMessage] performSelectorOnMainThread:@selector(fadeOutNotification:) withObject:self waitUntilDone:NO];
}

- (void)executeCallback
{
dispatch_async(dispatch_get_main_queue(), ^{
if (self.callback) { self.callback(); }
});
}

- (void)didMoveToWindow
{
[super didMoveToWindow];
Expand Down