mirror of
https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git
synced 2026-07-31 00:02:14 +08:00
#59 Add specific duration of the toast
This commit is contained in:
+12
-16
@@ -5,42 +5,38 @@
|
||||
@implementation Toast
|
||||
|
||||
- (void)show:(CDVInvokedUrlCommand*)command {
|
||||
|
||||
NSDictionary* options = [command argumentAtIndex:0];
|
||||
|
||||
NSString *message = options[@"message"];
|
||||
NSString *duration = options[@"duration"];
|
||||
NSString *position = options[@"position"];
|
||||
NSDictionary *data = options[@"data"];
|
||||
NSNumber *addPixelsY = options[@"addPixelsY"];
|
||||
NSDictionary *styling = options[@"styling"];
|
||||
|
||||
|
||||
if (![position isEqual: @"top"] && ![position isEqual: @"center"] && ![position isEqual: @"bottom"]) {
|
||||
CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"invalid position. valid options are 'top', 'center' and 'bottom'"];
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
return;
|
||||
}
|
||||
|
||||
NSInteger durationInt;
|
||||
if ([duration isEqual: @"short"]) {
|
||||
durationInt = 2;
|
||||
} else if ([duration isEqual: @"long"]) {
|
||||
durationInt = 5;
|
||||
|
||||
NSTimeInterval durationMS;
|
||||
if ([duration.lowercaseString isEqualToString: @"short"]) {
|
||||
durationMS = 2000;
|
||||
} else if ([duration.lowercaseString isEqualToString: @"long"]) {
|
||||
durationMS = 4000;
|
||||
} else {
|
||||
CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"invalid duration. valid options are 'short' and 'long'"];
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
return;
|
||||
durationMS = [duration intValue];
|
||||
}
|
||||
|
||||
|
||||
[self.webView makeToast:message
|
||||
duration:durationInt
|
||||
duration:durationMS / 1000
|
||||
position:position
|
||||
addPixelsY:addPixelsY == nil ? 0 : [addPixelsY intValue]
|
||||
data:data
|
||||
styling:styling
|
||||
commandDelegate:self.commandDelegate
|
||||
callbackId:command.callbackId];
|
||||
|
||||
|
||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||
pluginResult.keepCallback = [NSNumber numberWithBool:YES];
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
@@ -48,7 +44,7 @@
|
||||
|
||||
- (void)hide:(CDVInvokedUrlCommand*)command {
|
||||
[self.webView hideToast];
|
||||
|
||||
|
||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user