mirror of
https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git
synced 2025-04-26 21:05:39 +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 (ACTION_HIDE_EVENT.equals(action)) {
|
||||||
if (mostRecentToast != null) {
|
if (mostRecentToast != null) {
|
||||||
mostRecentToast.cancel();
|
mostRecentToast.cancel();
|
||||||
callbackContext.success();
|
|
||||||
} else {
|
|
||||||
callbackContext.error("No Toast has been shows yet");
|
|
||||||
}
|
}
|
||||||
|
callbackContext.success();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else if (ACTION_SHOW_EVENT.equals(action)) {
|
} 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;
|
||||||
- (void)makeToast:(NSString *)message duration:(NSTimeInterval)interval position:(id)position title:(NSString *)title image:(UIImage *)image;
|
- (void)makeToast:(NSString *)message duration:(NSTimeInterval)interval position:(id)position title:(NSString *)title image:(UIImage *)image;
|
||||||
|
|
||||||
|
- (void)hideToast;
|
||||||
|
|
||||||
// displays toast with an activity spinner
|
// displays toast with an activity spinner
|
||||||
- (void)makeToastActivity;
|
- (void)makeToastActivity;
|
||||||
- (void)makeToastActivity:(id)position;
|
- (void)makeToastActivity:(id)position;
|
||||||
|
@ -93,9 +93,7 @@ static UIView *prevToast = NULL;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)showToast:(UIView *)toast duration:(NSTimeInterval)duration position:(id)point {
|
- (void)showToast:(UIView *)toast duration:(NSTimeInterval)duration position:(id)point {
|
||||||
if(prevToast){
|
[self hideToast];
|
||||||
[self hideToast:prevToast];
|
|
||||||
}
|
|
||||||
prevToast = toast;
|
prevToast = toast;
|
||||||
toast.center = [self centerPointForPosition:point withToast:toast];
|
toast.center = [self centerPointForPosition:point withToast:toast];
|
||||||
toast.alpha = 0.0;
|
toast.alpha = 0.0;
|
||||||
@ -123,6 +121,12 @@ static UIView *prevToast = NULL;
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)hideToast {
|
||||||
|
if (prevToast){
|
||||||
|
[self hideToast:prevToast];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)hideToast:(UIView *)toast {
|
- (void)hideToast:(UIView *)toast {
|
||||||
[UIView animateWithDuration:CSToastFadeDuration
|
[UIView animateWithDuration:CSToastFadeDuration
|
||||||
delay:0.0
|
delay:0.0
|
||||||
|
@ -3,5 +3,6 @@
|
|||||||
@interface Toast : CDVPlugin
|
@interface Toast : CDVPlugin
|
||||||
|
|
||||||
- (void)show:(CDVInvokedUrlCommand*)command;
|
- (void)show:(CDVInvokedUrlCommand*)command;
|
||||||
|
- (void)hide:(CDVInvokedUrlCommand*)command;
|
||||||
|
|
||||||
@end
|
@end
|
@ -35,4 +35,11 @@
|
|||||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
[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
|
@end
|
Loading…
x
Reference in New Issue
Block a user