2014-01-25 10:46:46 +01:00
# import "Toast.h"
2014-01-25 11:45:10 +01:00
# import "Toast+UIView.h"
# import < Cordova / CDV . h >
2014-01-25 10:46:46 +01:00
@ implementation Toast
- ( void ) show : ( CDVInvokedUrlCommand * ) command {
2016-01-27 20:49:03 +01:00
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" ] ;
2016-03-17 21:23:19 +01:00
2014-01-25 13:22:40 +01:00
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'" ] ;
2014-09-27 15:41:53 +02:00
[ self . commandDelegate sendPluginResult : pluginResult callbackId : command . callbackId ] ;
2014-01-25 13:22:40 +01:00
return ;
}
2016-03-17 21:23:19 +01:00
NSTimeInterval durationMS ;
if ( [ duration . lowercaseString isEqualToString : @ "short" ] ) {
durationMS = 2000 ;
} else if ( [ duration . lowercaseString isEqualToString : @ "long" ] ) {
durationMS = 4000 ;
2014-01-25 13:22:40 +01:00
} else {
2016-03-17 21:23:19 +01:00
durationMS = [ duration intValue ] ;
2014-01-25 13:22:40 +01:00
}
2016-03-17 21:23:19 +01:00
2015-12-08 10:18:20 +01:00
[ self . webView makeToast : message
2016-03-17 21:23:19 +01:00
duration : durationMS / 1000
2015-12-08 10:18:20 +01:00
position : position
addPixelsY : addPixelsY = = nil ? 0 : [ addPixelsY intValue ]
2015-12-08 12:32:08 +01:00
data : data
2016-01-27 20:49:03 +01:00
styling : styling
2015-12-08 10:18:20 +01:00
commandDelegate : self . commandDelegate
callbackId : command . callbackId ] ;
2016-03-17 21:23:19 +01:00
2014-01-25 13:22:40 +01:00
CDVPluginResult * pluginResult = [ CDVPluginResult resultWithStatus : CDVCommandStatus_OK ] ;
2015-12-08 10:18:20 +01:00
pluginResult . keepCallback = [ NSNumber numberWithBool : YES ] ;
2014-09-27 15:41:53 +02:00
[ self . commandDelegate sendPluginResult : pluginResult callbackId : command . callbackId ] ;
2014-01-25 10:46:46 +01:00
}
2015-05-21 21:24:03 +02:00
- ( void ) hide : ( CDVInvokedUrlCommand * ) command {
[ self . webView hideToast ] ;
2016-03-17 21:23:19 +01:00
2015-05-21 21:24:03 +02:00
CDVPluginResult * pluginResult = [ CDVPluginResult resultWithStatus : CDVCommandStatus_OK ] ;
[ self . commandDelegate sendPluginResult : pluginResult callbackId : command . callbackId ] ;
}
2014-01-25 10:46:46 +01:00
@ end