#35 Close toast when app is suspended or closed: added hide() function, for iOS and Android only for now

This commit is contained in:
EddyVerbruggen 2015-05-21 21:24:03 +02:00
parent 4593549f41
commit 7ada5fbaa7
5 changed files with 18 additions and 6 deletions

View File

@ -32,10 +32,8 @@ public class Toast extends CordovaPlugin {
if (ACTION_HIDE_EVENT.equals(action)) {
if (mostRecentToast != null) {
mostRecentToast.cancel();
callbackContext.success();
} else {
callbackContext.error("No Toast has been shows yet");
}
callbackContext.success();
return true;
} else if (ACTION_SHOW_EVENT.equals(action)) {

View File

@ -9,6 +9,8 @@
- (void)makeToast:(NSString *)message duration:(NSTimeInterval)interval position:(id)position title:(NSString *)title;
- (void)makeToast:(NSString *)message duration:(NSTimeInterval)interval position:(id)position title:(NSString *)title image:(UIImage *)image;
- (void)hideToast;
// displays toast with an activity spinner
- (void)makeToastActivity;
- (void)makeToastActivity:(id)position;

View File

@ -93,9 +93,7 @@ static UIView *prevToast = NULL;
}
- (void)showToast:(UIView *)toast duration:(NSTimeInterval)duration position:(id)point {
if(prevToast){
[self hideToast:prevToast];
}
[self hideToast];
prevToast = toast;
toast.center = [self centerPointForPosition:point withToast:toast];
toast.alpha = 0.0;
@ -123,6 +121,12 @@ static UIView *prevToast = NULL;
}
- (void)hideToast {
if (prevToast){
[self hideToast:prevToast];
}
}
- (void)hideToast:(UIView *)toast {
[UIView animateWithDuration:CSToastFadeDuration
delay:0.0

View File

@ -3,5 +3,6 @@
@interface Toast : CDVPlugin
- (void)show:(CDVInvokedUrlCommand*)command;
- (void)hide:(CDVInvokedUrlCommand*)command;
@end

View File

@ -35,4 +35,11 @@
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
- (void)hide:(CDVInvokedUrlCommand*)command {
[self.webView hideToast];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
@end