mirror of
https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git
synced 2025-04-27 05:10:15 +08:00
#35 Close toast when app is suspended or closed: added hide() function, for iOS and Android only for now
This commit is contained in:
parent
4593549f41
commit
7ada5fbaa7
@ -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)) {
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -3,5 +3,6 @@
|
||||
@interface Toast : CDVPlugin
|
||||
|
||||
- (void)show:(CDVInvokedUrlCommand*)command;
|
||||
- (void)hide:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
@end
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user