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

Callback is now called when the message view is dismissed. #152

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
Expand Up @@ -5,34 +5,34 @@
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>F6FF7C22-1562-4A01-9CD1-A3C34B7E21C3</string>
<string>F5457609-387E-4BAC-A3E1-DE061D0E133A</string>
<key>IDESourceControlProjectName</key>
<string>Example</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>56C72571-8325-46B6-BC46-920E7DE5B629</key>
<string>https://github.com/toursprung/TSMessages.git</string>
<key>D48E31BE-405E-43F2-AEE5-E5D5996DE94E</key>
<string>https://github.com/Bluezen/TSMessages.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>ExampleProject/Example.xcworkspace</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>56C72571-8325-46B6-BC46-920E7DE5B629</key>
<key>D48E31BE-405E-43F2-AEE5-E5D5996DE94E</key>
<string>../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>https://github.com/toursprung/TSMessages.git</string>
<string>https://github.com/Bluezen/TSMessages.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>110</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>56C72571-8325-46B6-BC46-920E7DE5B629</string>
<string>D48E31BE-405E-43F2-AEE5-E5D5996DE94E</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>56C72571-8325-46B6-BC46-920E7DE5B629</string>
<string>D48E31BE-405E-43F2-AEE5-E5D5996DE94E</string>
<key>IDESourceControlWCCName</key>
<string>TSMessages</string>
</dict>
Expand Down
8 changes: 5 additions & 3 deletions TSMessages/Classes/TSMessage.m
Expand Up @@ -78,15 +78,15 @@ + (void)showNotificationInViewController:(UIViewController *)viewController
buttonTitle:nil
buttonCallback:nil
atPosition:TSMessageNotificationPositionTop
canBeDismissedByUser:YES];
canBeDismissedByUser:YES];
}

+ (void)showNotificationInViewController:(UIViewController *)viewController
title:(NSString *)title
subtitle:(NSString *)subtitle
type:(TSMessageNotificationType)type
duration:(NSTimeInterval)duration
canBeDismissedByUser:(BOOL)dismissingEnabled
canBeDismissedByUser:(BOOL)dismissingEnabled
{
[self showNotificationInViewController:viewController
title:title
Expand All @@ -98,7 +98,7 @@ + (void)showNotificationInViewController:(UIViewController *)viewController
buttonTitle:nil
buttonCallback:nil
atPosition:TSMessageNotificationPositionTop
canBeDismissedByUser:dismissingEnabled];
canBeDismissedByUser:dismissingEnabled];
}

+ (void)showNotificationInViewController:(UIViewController *)viewController
Expand Down Expand Up @@ -334,6 +334,8 @@ - (void)fadeOutNotification:(TSMessageView *)currentView animationFinishedBlock:
currentView.viewController.view.bounds.size.height + CGRectGetHeight(currentView.frame)/2.f);
}

[currentView executeCallback];

[UIView animateWithDuration:kTSMessageAnimationDuration animations:^
{
currentView.center = fadeOutToPoint;
Expand Down
2 changes: 2 additions & 0 deletions TSMessages/Views/TSMessageView.h
Expand Up @@ -76,5 +76,7 @@ canBeDismissedByUser:(BOOL)dismissingEnabled;
/** Use this method to load a custom design file */
+ (void)addNotificationDesignFromFile:(NSString *)file;

/** Perform callback if exists **/
- (void)executeCallback;

@end
24 changes: 7 additions & 17 deletions TSMessages/Views/TSMessageView.m
Expand Up @@ -326,12 +326,6 @@ - (id)initWithTitle:(NSString *)title
action:@selector(fadeMeOut)];
[self addGestureRecognizer:tapRec];
}

if (self.callback) {
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tapGesture.delegate = self;
[self addGestureRecognizer:tapGesture];
}
}
return self;
}
Expand Down Expand Up @@ -455,6 +449,13 @@ - (void)fadeMeOut
[[TSMessage sharedMessage] performSelectorOnMainThread:@selector(fadeOutNotification:) withObject:self waitUntilDone:NO];
}

- (void)executeCallback
{
if (self.callback) {
self.callback();
}
}

- (void)didMoveToWindow {
[super didMoveToWindow];
if (self.duration == TSMessageNotificationDurationEndless && self.superview && !self.window ) {
Expand All @@ -474,17 +475,6 @@ - (void)buttonTapped:(id) sender
[self fadeMeOut];
}

- (void)handleTap:(UITapGestureRecognizer *)tapGesture
{
if (tapGesture.state == UIGestureRecognizerStateRecognized)
{
if (self.callback)
{
self.callback();
}
}
}

#pragma mark - UIGestureRecognizerDelegate

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
Expand Down