From 9b9365d9da035950a51c7dedb4aaa970db9d24b3 Mon Sep 17 00:00:00 2001 From: ElNinjaGaiden Date: Fri, 4 Mar 2016 09:24:55 -0600 Subject: [PATCH] Changes to send same parameters to success callback when the toast hides automatically - no tap --- src/android/nl/xservices/plugins/Toast.java | 13 ++++++++++++- src/ios/Toast+UIView.m | 9 +++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/android/nl/xservices/plugins/Toast.java b/src/android/nl/xservices/plugins/Toast.java index 1232c7a..dc73424 100644 --- a/src/android/nl/xservices/plugins/Toast.java +++ b/src/android/nl/xservices/plugins/Toast.java @@ -52,7 +52,18 @@ public class Toast extends CordovaPlugin { mostRecentToast.cancel(); getViewGroup().setOnTouchListener(null); } - callbackContext.success(); + final JSONObject hideOptions = args.getJSONObject(0); + final String hidemessage = hideOptions.getString("message"); + final JSONObject hideData = hideOptions.has("data") ? hideOptions.getJSONObject("data") : null; + final JSONObject json = new JSONObject(); + try { + json.put("event", "hide"); + json.put("message", hidemessage); + json.put("data", hideData); + } catch (JSONException e) { + e.printStackTrace(); + } + callbackContext.success(json); return true; } else if (ACTION_SHOW_EVENT.equals(action)) { diff --git a/src/ios/Toast+UIView.m b/src/ios/Toast+UIView.m index 8b33055..18c7289 100644 --- a/src/ios/Toast+UIView.m +++ b/src/ios/Toast+UIView.m @@ -185,6 +185,15 @@ static id styling; - (void)toastTimerDidFinish:(NSTimer *)timer { [self hideToast:(UIView *)timer.userInfo]; + + // also send an event back to JS + NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:msg, @"message", @"hide", @"event", nil]; + if (data != nil) { + [dict setObject:data forKey:@"data"]; + } + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dict]; + [commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; } - (void)handleToastTapped:(UITapGestureRecognizer *)recognizer {