From 7ada5fbaa700970c50abb85c5437e89f7a207f25 Mon Sep 17 00:00:00 2001 From: EddyVerbruggen Date: Thu, 21 May 2015 21:24:03 +0200 Subject: [PATCH] #35 Close toast when app is suspended or closed: added hide() function, for iOS and Android only for now --- src/android/nl/xservices/plugins/Toast.java | 4 +--- src/ios/Toast+UIView.h | 2 ++ src/ios/Toast+UIView.m | 10 +++++++--- src/ios/Toast.h | 1 + src/ios/Toast.m | 7 +++++++ 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/android/nl/xservices/plugins/Toast.java b/src/android/nl/xservices/plugins/Toast.java index 7b278de..dffece4 100644 --- a/src/android/nl/xservices/plugins/Toast.java +++ b/src/android/nl/xservices/plugins/Toast.java @@ -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)) { diff --git a/src/ios/Toast+UIView.h b/src/ios/Toast+UIView.h index 5af9a59..a3369e9 100644 --- a/src/ios/Toast+UIView.h +++ b/src/ios/Toast+UIView.h @@ -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; diff --git a/src/ios/Toast+UIView.m b/src/ios/Toast+UIView.m index 047733b..af60759 100644 --- a/src/ios/Toast+UIView.m +++ b/src/ios/Toast+UIView.m @@ -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 diff --git a/src/ios/Toast.h b/src/ios/Toast.h index 026a5dc..c37e72b 100644 --- a/src/ios/Toast.h +++ b/src/ios/Toast.h @@ -3,5 +3,6 @@ @interface Toast : CDVPlugin - (void)show:(CDVInvokedUrlCommand*)command; +- (void)hide:(CDVInvokedUrlCommand*)command; @end \ No newline at end of file diff --git a/src/ios/Toast.m b/src/ios/Toast.m index 2dd535a..00200ab 100644 --- a/src/ios/Toast.m +++ b/src/ios/Toast.m @@ -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 \ No newline at end of file