Compare commits

..
24 Commits
Author SHA1 Message Date
EddyVerbruggen ecb47ab110 #60 Is it possible to change the android theme? Compatibility with older Android versions. 2015-12-01 12:31:41 +01:00
EddyVerbruggen f8887dc45e #60 Is it possible to change the android theme? Compatibility with older Android versions.
#61 Android exception NoSuchMethodError setTint.
2015-12-01 08:59:43 +01:00
EddyVerbruggen 273334664a #60 Is it possible to change the android theme? Version bump. 2015-11-30 09:33:28 +01:00
EddyVerbruggen 6ee16e9e7d #60 Is it possible to change the android theme? 2015-11-29 21:00:46 +01:00
EddyVerbruggen 03320113b4 #42 toast not showing on top of InAppBrowser on iOS
#55 Again/Still? Toast won't show in front of InAppBrowser on iOS
2015-09-29 22:36:48 +02:00
Eddy Verbruggen 5634e1d84c typo 2015-09-26 08:05:18 +02:00
EddyVerbruggen 2add9bef7b Cordova id change & version bump 2015-08-27 16:34:49 +02:00
EddyVerbruggen c252764372 #41 npm prep (name was taken) 2015-08-04 22:17:28 +02:00
EddyVerbruggen ba7c60f324 #41 npm prep 2015-08-04 22:09:57 +02:00
EddyVerbruggen eed523111b bump 2015-08-04 22:07:13 +02:00
EddyVerbruggen e0420e0aef bump 2015-08-04 22:06:46 +02:00
Eddy Verbruggen 8c10bcaec5 Merge pull request #45 from martinoss/android-fix-blurry-toast
Fix blurry toast on Android 5, resolves #44
2015-08-04 21:39:56 +02:00
Martin Oss 5d9aa4f187 Fix blurry toast on Android 5, resolves EddyVerbruggen/Toast-PhoneGap-Plugin#44 2015-08-04 21:09:29 +02:00
EddyVerbruggen 50290d83de #37 Support landscape mode on iOS 7 2015-06-19 12:28:29 +02:00
eddyverbruggen@gmail.com 3d0b2927ae #36 control the vertical position (added WP support) 2015-06-11 19:43:27 +02:00
eddyverbruggen@gmail.com 2cb29b217a #36 control the vertical position (added Android support) 2015-06-11 19:39:49 +02:00
eddyverbruggen@gmail.com 6208c60449 #36 control the vertical position 2015-06-11 19:31:10 +02:00
EddyVerbruggen 39dd68c7c0 #35 Close toast when app is suspended or closed: lastly, added WP8 (fix) 2015-05-21 22:15:44 +02:00
EddyVerbruggen d175358f36 #35 Close toast when app is suspended or closed: lastly, added WP8 2015-05-21 21:37:41 +02:00
EddyVerbruggen 9c269fc9ba #35 Close toast when app is suspended or closed: documentation 2015-05-21 21:31:18 +02:00
EddyVerbruggen 5eb202fd54 #36 iOS: top toast a little lower, bottom toast a bit higher 2015-05-21 21:25:21 +02:00
EddyVerbruggen 7ada5fbaa7 #35 Close toast when app is suspended or closed: added hide() function, for iOS and Android only for now 2015-05-21 21:24:03 +02:00
EddyVerbruggen 4593549f41 #35 Close toast when app is suspended or closed: added hide() function, for Android only for now 2015-05-21 21:04:37 +02:00
eddyverbruggen@gmail.com 69f1fbaa80 #4 test updates 2015-04-22 22:24:10 +02:00
11 changed files with 213 additions and 58 deletions
+36 -10
View File
@@ -63,18 +63,19 @@ Toast is compatible with [Cordova Plugman](https://github.com/apache/cordova-plu
Using the Cordova CLI and the [Cordova Plugin Registry](http://plugins.cordova.io)
```
$ cordova plugin add nl.x-services.plugins.toast
$ cordova plugin add cordova-plugin-x-toast
$ cordova prepare
```
Or using the phonegap CLI
```
$ phonegap local plugin add nl.x-services.plugins.toast
$ phonegap local plugin add cordova-plugin-x-toast
```
Toast.js is brought in automatically. There is no need to change or add anything in your html.
### Manually
You'd better use the CLI, but here goes:
1\. Add the following xml to your `config.xml` in the root directory of your `www` folder:
```xml
@@ -118,20 +119,18 @@ Toast works with PhoneGap build too, but only with PhoneGap 3.0 and up.
Just add the following xml to your `config.xml` to always use the latest version of this plugin:
```xml
<gap:plugin name="nl.x-services.plugins.toast" />
```
or to use this exact version:
```xml
<gap:plugin name="nl.x-services.plugins.toast" version="1.0" />
<gap:plugin name="cordova-plugin-x-toast" source="npm" />
```
Toast.js is brought in automatically. There is no need to change or add anything in your html.
## 4. Usage
### Showing a Toast
You have two choices to make when showing a Toast: where to show it and for how long.
* show(message, duration, position)
* duration: 'short', 'long'
* position: 'top', 'center', 'bottom'
* duration: 'short', 'long'
* position: 'top', 'center', 'bottom'
You can also use any of these convenience methods:
* showShortTop(message)
@@ -148,7 +147,34 @@ You can copy-paste these lines of code for a quick test:
<button onclick="window.plugins.toast.show('Hello there!', 'long', 'center', function(a){console.log('toast success: ' + a)}, function(b){alert('toast error: ' + b)})">Toast show long center</button>
```
### WP8 quircks
#### Tweaking the vertical position
Since 2.1.0 you can add pixels to move the toast up or down.
Note that `showWithOptions` can be used instead of the functions above, but it's not useful unless you want to pass `addPixelsY`.
```js
function showTop() {
window.plugins.toast.showWithOptions(
{
message: "hey there",
duration: "short",
position: "bottom",
addPixelsY: -40 // added a negative value to move it up a bit (default 0)
},
onSuccess, // optional
onError // optional
);
}
```
### Hiding a Toast
In case you want to hide a Toast manually, call this:
```js
function hide() {
// this function takes an optional success callback, but you can do without just as well
window.plugins.toast.hide();
}
```
### WP8 quirks
The WP8 implementation needs a little more work, but it's perfectly useable when you keep this in mind:
* You can't show two Toasts simultaneously.
* Wait until the first Toast is hidden before the second is shown, otherwise the second one will be hidden quickly.
+41
View File
@@ -0,0 +1,41 @@
{
"name": "cordova-plugin-x-toast",
"version": "2.2.3",
"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",
"platforms": [
"ios",
"android",
"wp8",
"blackberry10"
]
},
"repository": {
"type": "git",
"url": "git+https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git"
},
"keywords": [
"Toast",
"Notification",
"Message",
"Alert",
"ecosystem:cordova",
"cordova-ios",
"cordova-android",
"cordova-wp8",
"cordova-blackberry10"
],
"engines": [
{
"name": "cordova",
"version": ">=3.0.0"
}
],
"author": "Eddy Verbruggen <eddyverbruggen@gmail.com> (https://github.com/EddyVerbruggen)",
"license": "MIT",
"bugs": {
"url": "https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin/issues"
},
"homepage": "https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin#readme"
}
+2 -2
View File
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="nl.x-services.plugins.toast"
version="2.0.5">
id="cordova-plugin-x-toast"
version="2.2.3">
<name>Toast</name>
+25 -6
View File
@@ -1,6 +1,8 @@
package nl.xservices.plugins;
import android.os.Build;
import android.view.Gravity;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
@@ -20,15 +22,25 @@ import org.json.JSONObject;
public class Toast extends CordovaPlugin {
private static final String ACTION_SHOW_EVENT = "show";
private static final String ACTION_HIDE_EVENT = "hide";
private android.widget.Toast mostRecentToast;
private static final boolean IS_AT_LEAST_ANDROID5 = Build.VERSION.SDK_INT >= 21;
// note that webView.isPaused() is not Xwalk compatible, so tracking it poor-man style
private boolean isPaused;
@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
if (ACTION_SHOW_EVENT.equals(action)) {
if (ACTION_HIDE_EVENT.equals(action)) {
if (mostRecentToast != null) {
mostRecentToast.cancel();
}
callbackContext.success();
return true;
} else if (ACTION_SHOW_EVENT.equals(action)) {
if (this.isPaused) {
return true;
@@ -39,20 +51,27 @@ public class Toast extends CordovaPlugin {
final String message = options.getString("message");
final String duration = options.getString("duration");
final String position = options.getString("position");
final int addPixelsY = options.has("addPixelsY") ? options.getInt("addPixelsY") : 0;
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
android.widget.Toast toast = android.widget.Toast.makeText(
webView.getContext(),
IS_AT_LEAST_ANDROID5 ? cordova.getActivity().getWindow().getContext() : cordova.getActivity().getApplicationContext(),
message,
"short".equals(duration) ? android.widget.Toast.LENGTH_SHORT : android.widget.Toast.LENGTH_LONG);
// if we want to change the background color some day, we can use this
// try {
// final Method setTintMethod = Drawable.class.getMethod("setTint", int.class);
// setTintMethod.invoke(toast.getView().getBackground(), Color.RED); // default is Color.DKGRAY
// } catch (Exception ignore) {
// }
if ("top".equals(position)) {
toast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 20);
toast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 20 + addPixelsY);
} else if ("bottom".equals(position)) {
toast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 20);
toast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 20 - addPixelsY);
} else if ("center".equals(position)) {
toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, addPixelsY);
} else {
callbackContext.error("invalid position. valid options are 'top', 'center' and 'bottom'");
return;
@@ -83,4 +102,4 @@ public class Toast extends CordovaPlugin {
public void onResume(boolean multitasking) {
this.isPaused = false;
}
}
}
+5 -1
View File
@@ -5,10 +5,13 @@
// 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;
- (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;
- (void)hideToast;
// displays toast with an activity spinner
- (void)makeToastActivity;
- (void)makeToastActivity:(id)position;
@@ -16,6 +19,7 @@
// the showToast methods display any view as toast
- (void)showToast:(UIView *)toast;
- (void)showToast:(UIView *)toast duration:(NSTimeInterval)interval position:(id)point;
- (void)showToast:(UIView *)toast duration:(NSTimeInterval)interval position:(id)point ;
- (void)showToast:(UIView *)toast duration:(NSTimeInterval)interval position:(id)point addedPixelsY:(int)addPixelsY;
@end
+54 -28
View File
@@ -12,7 +12,7 @@ static const CGFloat CSToastMaxWidth = 0.8; // 80% of parent vie
static const CGFloat CSToastMaxHeight = 0.8; // 80% of parent view height
static const CGFloat CSToastHorizontalPadding = 16.0;
static const CGFloat CSToastVerticalPadding = 12.0;
static const CGFloat CSToastTopBottomOffset = 10.0;
static const CGFloat CSToastTopBottomOffset = 20.0;
static const CGFloat CSToastCornerRadius = 20.0;
static const CGFloat CSToastOpacity = 0.8;
static const CGFloat CSToastFontSize = 13.0;
@@ -53,7 +53,7 @@ static UIView *prevToast = NULL;
- (void)hideToast:(UIView *)toast;
- (void)toastTimerDidFinish:(NSTimer *)timer;
- (void)handleToastTapped:(UITapGestureRecognizer *)recognizer;
- (CGPoint)centerPointForPosition:(id)position withToast:(UIView *)toast;
- (CGPoint)centerPointForPosition:(id)position withToast:(UIView *)toast withAddedPixelsY:(int) addPixelsY;
- (UIView *)viewForMessage:(NSString *)message title:(NSString *)title image:(UIImage *)image;
- (CGSize)sizeForString:(NSString *)string font:(UIFont *)font constrainedToSize:(CGSize)constrainedSize lineBreakMode:(NSLineBreakMode)lineBreakMode;
@@ -73,19 +73,24 @@ static UIView *prevToast = NULL;
[self showToast:toast duration:duration position:position];
}
- (void)makeToast:(NSString *)message duration:(NSTimeInterval)duration position:(id)position addPixelsY:(int)addPixelsY {
UIView *toast = [self viewForMessage:message title:nil image:nil];
[self showToast:toast duration:duration position:position addedPixelsY:addPixelsY];
}
- (void)makeToast:(NSString *)message duration:(NSTimeInterval)duration position:(id)position title:(NSString *)title {
UIView *toast = [self viewForMessage:message title:title image:nil];
[self showToast:toast duration:duration position:position];
[self showToast:toast duration:duration position:position];
}
- (void)makeToast:(NSString *)message duration:(NSTimeInterval)duration position:(id)position image:(UIImage *)image {
UIView *toast = [self viewForMessage:message title:nil image:image];
[self showToast:toast duration:duration position:position];
[self showToast:toast duration:duration position:position];
}
- (void)makeToast:(NSString *)message duration:(NSTimeInterval)duration position:(id)position title:(NSString *)title image:(UIImage *)image {
UIView *toast = [self viewForMessage:message title:title image:image];
[self showToast:toast duration:duration position:position];
[self showToast:toast duration:duration position:position];
}
- (void)showToast:(UIView *)toast {
@@ -93,23 +98,27 @@ static UIView *prevToast = NULL;
}
- (void)showToast:(UIView *)toast duration:(NSTimeInterval)duration position:(id)point {
if(prevToast){
[self hideToast:prevToast];
}
[self showToast:toast duration:CSToastDefaultDuration position:CSToastDefaultPosition addedPixelsY:0];
}
- (void)showToast:(UIView *)toast duration:(NSTimeInterval)duration position:(id)point addedPixelsY:(int) addPixelsY {
[self hideToast];
prevToast = toast;
toast.center = [self centerPointForPosition:point withToast:toast];
toast.center = [self centerPointForPosition:point withToast:toast withAddedPixelsY:addPixelsY];
toast.alpha = 0.0;
if (CSToastHidesOnTap) {
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:toast action:@selector(handleToastTapped:)];
[toast addGestureRecognizer:recognizer];
toast.userInteractionEnabled = YES;
toast.exclusiveTouch = YES;
}
// make sure that if InAppBrowser is active, we're still showing Toasts on top of it
[self.superview.superview addSubview:toast];
UIViewController *vc = [self getTopMostViewController];
UIView *v = [vc view];
[v addSubview:toast];
[UIView animateWithDuration:CSToastFadeDuration
delay:0.0
options:(UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAllowUserInteraction)
@@ -120,7 +129,21 @@ static UIView *prevToast = NULL;
// associate the timer with the toast view
objc_setAssociatedObject (toast, &CSToastTimerKey, timer, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}];
}
- (UIViewController*) getTopMostViewController {
UIViewController *presentingViewController = [[[UIApplication sharedApplication] delegate] window].rootViewController;
while (presentingViewController.presentedViewController != nil) {
presentingViewController = presentingViewController.presentedViewController;
}
return presentingViewController;
}
- (void)hideToast {
if (prevToast){
[self hideToast:prevToast];
}
}
- (void)hideToast:(UIView *)toast {
@@ -143,7 +166,7 @@ static UIView *prevToast = NULL;
- (void)handleToastTapped:(UITapGestureRecognizer *)recognizer {
NSTimer *timer = (NSTimer *)objc_getAssociatedObject(self, &CSToastTimerKey);
[timer invalidate];
[self hideToast:recognizer.view];
}
@@ -157,31 +180,31 @@ static UIView *prevToast = NULL;
// sanity
UIView *existingActivityView = (UIView *)objc_getAssociatedObject(self, &CSToastActivityViewKey);
if (existingActivityView != nil) return;
UIView *activityView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CSToastActivityWidth, CSToastActivityHeight)];
activityView.center = [self centerPointForPosition:position withToast:activityView];
activityView.center = [self centerPointForPosition:position withToast:activityView withAddedPixelsY:0];
activityView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:CSToastOpacity];
activityView.alpha = 0.0;
activityView.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin);
activityView.layer.cornerRadius = CSToastCornerRadius;
if (CSToastDisplayShadow) {
activityView.layer.shadowColor = [UIColor blackColor].CGColor;
activityView.layer.shadowOpacity = CSToastShadowOpacity;
activityView.layer.shadowRadius = CSToastShadowRadius;
activityView.layer.shadowOffset = CSToastShadowOffset;
}
UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityIndicatorView.center = CGPointMake(activityView.bounds.size.width / 2, activityView.bounds.size.height / 2);
[activityView addSubview:activityIndicatorView];
[activityIndicatorView startAnimating];
// associate the activity view with self
objc_setAssociatedObject (self, &CSToastActivityViewKey, activityView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self addSubview:activityView];
[UIView animateWithDuration:CSToastFadeDuration
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
@@ -207,22 +230,22 @@ static UIView *prevToast = NULL;
#pragma mark - Helpers
- (CGPoint)centerPointForPosition:(id)point withToast:(UIView *)toast {
- (CGPoint)centerPointForPosition:(id)point withToast:(UIView *)toast withAddedPixelsY:(int) addPixelsY {
if([point isKindOfClass:[NSString class]]) {
// convert string literals @"top", @"bottom", @"center", or any point wrapped in an NSValue object into a CGPoint
if([point caseInsensitiveCompare:@"top"] == NSOrderedSame) {
return CGPointMake(self.bounds.size.width/2, (toast.frame.size.height / 2) + CSToastVerticalPadding + CSToastTopBottomOffset);
return CGPointMake(self.bounds.size.width/2, (toast.frame.size.height / 2) + addPixelsY + CSToastVerticalPadding + CSToastTopBottomOffset);
} else if([point caseInsensitiveCompare:@"bottom"] == NSOrderedSame) {
return CGPointMake(self.bounds.size.width/2, (self.bounds.size.height - (toast.frame.size.height / 2)) - CSToastVerticalPadding - CSToastTopBottomOffset);
return CGPointMake(self.bounds.size.width/2, (self.bounds.size.height - (toast.frame.size.height / 2)) - CSToastVerticalPadding - CSToastTopBottomOffset + addPixelsY);
} else if([point caseInsensitiveCompare:@"center"] == NSOrderedSame) {
return CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);
return CGPointMake(self.bounds.size.width / 2, (self.bounds.size.height / 2) + addPixelsY);
}
} else if ([point isKindOfClass:[NSValue class]]) {
return [point CGPointValue];
}
NSLog(@"Warning: Invalid position for toast.");
return [self centerPointForPosition:CSToastDefaultPosition withToast:toast];
return [self centerPointForPosition:CSToastDefaultPosition withToast:toast withAddedPixelsY:addPixelsY];
}
- (CGSize)sizeForString:(NSString *)string font:(UIFont *)font constrainedToSize:(CGSize)constrainedSize lineBreakMode:(NSLineBreakMode)lineBreakMode {
@@ -234,7 +257,10 @@ static UIView *prevToast = NULL;
return CGSizeMake(ceilf(boundingRect.size.width), ceilf(boundingRect.size.height));
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
return [string sizeWithFont:font constrainedToSize:constrainedSize lineBreakMode:lineBreakMode];
#pragma clang diagnostic pop
}
- (UIView *)viewForMessage:(NSString *)message title:(NSString *)title image:(UIImage *)image {
+1
View File
@@ -3,5 +3,6 @@
@interface Toast : CDVPlugin
- (void)show:(CDVInvokedUrlCommand*)command;
- (void)hide:(CDVInvokedUrlCommand*)command;
@end
+9 -1
View File
@@ -11,6 +11,7 @@
NSString *message = [options objectForKey:@"message"];
NSString *duration = [options objectForKey:@"duration"];
NSString *position = [options objectForKey:@"position"];
NSNumber *addPixelsY = [options objectForKey:@"addPixelsY"];
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'"];
@@ -29,7 +30,14 @@
return;
}
[self.webView makeToast:message duration:durationInt position:position];
[self.webView makeToast:message duration:durationInt position:position addPixelsY:addPixelsY == nil ? 0 : [addPixelsY intValue]];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[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];
+18 -3
View File
@@ -39,6 +39,9 @@ namespace WPCordovaClassLib.Cordova.Commands
[DataMember(IsRequired = true, Name = "position")]
public string position { get; set; }
[DataMember(IsRequired = false, Name = "addPixelsY")]
public int addPixelsY { get; set; }
}
public void show(string options)
@@ -60,6 +63,7 @@ namespace WPCordovaClassLib.Cordova.Commands
var message = toastOptions.message;
var duration = toastOptions.duration;
var position = toastOptions.position;
int addPixelsY = toastOptions.addPixelsY;
string aliasCurrentCommandCallbackId = args[1];
@@ -104,17 +108,17 @@ namespace WPCordovaClassLib.Cordova.Commands
if ("top".Equals(position))
{
popup.VerticalAlignment = VerticalAlignment.Top;
popup.VerticalOffset = 20;
popup.VerticalOffset = 20 + addPixelsY;
}
else if ("bottom".Equals(position))
{
popup.VerticalAlignment = VerticalAlignment.Bottom;
popup.VerticalOffset = -100; // TODO can do better
popup.VerticalOffset = -100 + addPixelsY; // TODO can do better
}
else if ("center".Equals(position))
{
popup.VerticalAlignment = VerticalAlignment.Center;
popup.VerticalOffset = -50; // TODO can do way better
popup.VerticalOffset = -50 + addPixelsY; // TODO can do way better
}
else
{
@@ -145,6 +149,17 @@ namespace WPCordovaClassLib.Cordova.Commands
});
}
public void hide(string options)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
if (popup != null && popup.IsOpen)
{
popup.IsOpen = false;
}
});
}
private async void hidePopup(int delay)
{
await Task.Delay(delay);
+10 -6
View File
@@ -1,5 +1,5 @@
exports.defineAutoTests = function() {
var fail = function (done) {
expect(true).toBe(false);
done();
@@ -20,6 +20,14 @@ exports.defineAutoTests = function() {
expect(window.plugins.toast.show).toBeDefined();
});
it("should define showWithOptions", function() {
expect(window.plugins.toast.showWithOptions).toBeDefined();
});
it("should define optionsBuilder", function() {
expect(window.plugins.toast.optionsBuilder).toBeDefined();
});
it("should define showShortTop", function() {
expect(window.plugins.toast.showShortTop).toBeDefined();
});
@@ -47,11 +55,7 @@ exports.defineAutoTests = function() {
describe('Invalid usage', function () {
it("should fail due to an invalid position", function(done) {
window.plugins.toast.show('hi', 'short', 'nowhere', fail.bind(null, done), succeed.bind(null, done));
});
it("should fail due to an invalid duration", function(done) {
window.plugins.toast.show('hi', 'medium', 'top', fail.bind(null, done), succeed.bind(null, done));
window.plugins.toast.show('hi', 'short', 'nowhere', fail.bind(null, done), succeed.bind(null, done));
});
});
};
+12 -1
View File
@@ -7,6 +7,7 @@ Toast.prototype.optionsBuilder = function () {
var message = null;
var duration = "short";
var position = "center";
var addPixelsY = 0;
return {
withMessage: function(m) {
@@ -24,11 +25,17 @@ Toast.prototype.optionsBuilder = function () {
return this;
},
withAddPixelsY: function(y) {
addPixelsY = y;
return this;
},
build: function() {
return {
message: message,
duration: duration,
position: position
position: position,
addPixelsY: addPixelsY
}
}
}
@@ -74,6 +81,10 @@ Toast.prototype.showLongBottom = function (message, successCallback, errorCallba
this.show(message, "long", "bottom", successCallback, errorCallback);
};
Toast.prototype.hide = function (successCallback, errorCallback) {
cordova.exec(successCallback, errorCallback, "Toast", "hide", []);
};
Toast.install = function () {
if (!window.plugins) {
window.plugins = {};