mirror of
https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git
synced 2025-02-24 10:12:53 +08:00
sync from upstream
This commit is contained in:
commit
23d35404b5
@ -186,7 +186,8 @@ called again. You can distinguish between those events of course:
|
||||
message: "hey there",
|
||||
duration: "short",
|
||||
position: "bottom",
|
||||
addPixelsY: -40 // added a negative value to move it up a bit (default 0)
|
||||
addPixelsY: -40, // (optional) added a negative value to move it up a bit (default 0)
|
||||
data: {'foo','bar'} // (optional) pass in a JSON object here (it will be sent back in the success callback below)
|
||||
},
|
||||
// implement the success callback
|
||||
function(result) {
|
||||
@ -194,6 +195,7 @@ called again. You can distinguish between those events of course:
|
||||
console.log("The toast was tapped");
|
||||
console.log("Event: " + result.event); // will be defined, with a value of "touch" when it was tapped by the user
|
||||
console.log("Message: " + result.message); // will be equal to the message you passed in
|
||||
console.log("data.foo: " + result.data.foo); // .. retrieve passed in data here
|
||||
} else {
|
||||
console.log("The toast has been shown");
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cordova-plugin-x-toast",
|
||||
"version": "2.3.0",
|
||||
"version": "2.3.1",
|
||||
"description": "This plugin allows you to show a Toast. A Toast is a little non intrusive buttonless popup which automatically disappears.",
|
||||
"cordova": {
|
||||
"id": "cordova-plugin-x-toast",
|
||||
|
@ -55,6 +55,7 @@ public class Toast extends CordovaPlugin {
|
||||
final String duration = options.getString("duration");
|
||||
final String position = options.getString("position");
|
||||
final int addPixelsY = options.has("addPixelsY") ? options.getInt("addPixelsY") : 0;
|
||||
final JSONObject data = options.has("data") ? options.getJSONObject("data") : null;
|
||||
|
||||
cordova.getActivity().runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
@ -88,6 +89,7 @@ public class Toast extends CordovaPlugin {
|
||||
try {
|
||||
json.put("event", "touch");
|
||||
json.put("message", message);
|
||||
json.put("data", data);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
// each makeToast method creates a view and displays it as toast
|
||||
- (void)makeToast:(NSString *)message;
|
||||
- (void)makeToast:(NSString *)message duration:(NSTimeInterval)interval position:(id)position;
|
||||
- (void)makeToast:(NSString *)message duration:(NSTimeInterval)duration position:(id)position addPixelsY:(int)addPixelsY commandDelegate:(id <CDVCommandDelegate>)commandDelegate callbackId:(NSString *)callbackId;
|
||||
- (void)makeToast:(NSString *)message duration:(NSTimeInterval)duration position:(id)position addPixelsY:(int)addPixelsY data:(NSDictionary*)data commandDelegate:(id <CDVCommandDelegate>)commandDelegate callbackId:(NSString *)callbackId;
|
||||
- (void)makeToast:(NSString *)message duration:(NSTimeInterval)interval position:(id)position image:(UIImage *)image;
|
||||
- (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;
|
||||
|
@ -52,6 +52,7 @@ static UIView *prevToast = NULL;
|
||||
static id commandDelegate;
|
||||
static id callbackId;
|
||||
static id msg;
|
||||
static id data;
|
||||
|
||||
@interface UIView (ToastPrivate)
|
||||
|
||||
@ -66,6 +67,7 @@ static id msg;
|
||||
|
||||
@implementation UIView (Toast)
|
||||
|
||||
|
||||
#pragma mark - Toast Methods
|
||||
|
||||
- (void)makeToast:(NSString *)message {
|
||||
@ -77,10 +79,11 @@ static id msg;
|
||||
[self showToast:toast duration:duration position:position];
|
||||
}
|
||||
|
||||
- (void)makeToast:(NSString *)message duration:(NSTimeInterval)duration position:(id)position addPixelsY:(int)addPixelsY commandDelegate:(id <CDVCommandDelegate>)_commandDelegate callbackId:(NSString *)_callbackId {
|
||||
- (void)makeToast:(NSString *)message duration:(NSTimeInterval)duration position:(id)position addPixelsY:(int)addPixelsY data:(NSDictionary*)_data commandDelegate:(id <CDVCommandDelegate>)_commandDelegate callbackId:(NSString *)_callbackId {
|
||||
commandDelegate = _commandDelegate;
|
||||
callbackId = _callbackId;
|
||||
msg = message;
|
||||
data = _data;
|
||||
UIView *toast = [self viewForMessage:message title:nil image:nil];
|
||||
[self showToast:toast duration:duration position:position addedPixelsY:addPixelsY];
|
||||
}
|
||||
@ -178,7 +181,11 @@ static id msg;
|
||||
[self hideToast:recognizer.view];
|
||||
|
||||
// also send an event back to JS
|
||||
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:msg, @"message", @"touch", @"event", nil];
|
||||
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:msg, @"message", @"touch", @"event", nil];
|
||||
if (data != nil) {
|
||||
[dict setObject:data forKey:@"data"];
|
||||
}
|
||||
|
||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dict];
|
||||
[commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
NSString *message = [options objectForKey:@"message"];
|
||||
NSString *duration = [options objectForKey:@"duration"];
|
||||
NSString *position = [options objectForKey:@"position"];
|
||||
NSDictionary *data = [options objectForKey:@"data"];
|
||||
NSNumber *addPixelsY = [options objectForKey:@"addPixelsY"];
|
||||
|
||||
if (![position isEqual: @"top"] && ![position isEqual: @"center"] && ![position isEqual: @"bottom"]) {
|
||||
@ -34,6 +35,7 @@
|
||||
duration:durationInt
|
||||
position:position
|
||||
addPixelsY:addPixelsY == nil ? 0 : [addPixelsY intValue]
|
||||
data:data
|
||||
commandDelegate:self.commandDelegate
|
||||
callbackId:command.callbackId];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user