mirror of
https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git
synced 2026-07-31 00:02:14 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39dd68c7c0 | ||
|
|
d175358f36 | ||
|
|
9c269fc9ba | ||
|
|
5eb202fd54 | ||
|
|
7ada5fbaa7 | ||
|
|
4593549f41 | ||
|
|
69f1fbaa80 |
@@ -118,16 +118,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" />
|
||||
<gap:plugin name="nl.x-services.plugins.toast" source="plugins.cordova.io" />
|
||||
```
|
||||
or to use this exact version:
|
||||
or to use a specific version:
|
||||
```xml
|
||||
<gap:plugin name="nl.x-services.plugins.toast" version="1.0" />
|
||||
<gap:plugin name="nl.x-services.plugins.toast" source="plugins.cordova.io" version="2.0.6" />
|
||||
```
|
||||
|
||||
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'
|
||||
@@ -148,6 +150,15 @@ 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>
|
||||
```
|
||||
|
||||
### 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 quircks
|
||||
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.
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
<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">
|
||||
version="2.0.6">
|
||||
|
||||
<name>Toast</name>
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ 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;
|
||||
|
||||
@@ -28,7 +29,14 @@ public class Toast extends CordovaPlugin {
|
||||
|
||||
@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;
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
- (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;
|
||||
|
||||
@@ -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;
|
||||
@@ -93,9 +93,7 @@ static UIView *prevToast = NULL;
|
||||
}
|
||||
|
||||
- (void)showToast:(UIView *)toast duration:(NSTimeInterval)duration position:(id)point {
|
||||
if(prevToast){
|
||||
[self hideToast:prevToast];
|
||||
}
|
||||
[self hideToast];
|
||||
prevToast = toast;
|
||||
toast.center = [self centerPointForPosition:point withToast:toast];
|
||||
toast.alpha = 0.0;
|
||||
@@ -123,6 +121,12 @@ static UIView *prevToast = NULL;
|
||||
|
||||
}
|
||||
|
||||
- (void)hideToast {
|
||||
if (prevToast){
|
||||
[self hideToast:prevToast];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)hideToast:(UIView *)toast {
|
||||
[UIView animateWithDuration:CSToastFadeDuration
|
||||
delay:0.0
|
||||
|
||||
@@ -3,5 +3,6 @@
|
||||
@interface Toast : CDVPlugin
|
||||
|
||||
- (void)show:(CDVInvokedUrlCommand*)command;
|
||||
- (void)hide:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
@end
|
||||
@@ -35,4 +35,11 @@
|
||||
[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];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -145,6 +145,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
@@ -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));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -74,6 +74,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 = {};
|
||||
|
||||
Reference in New Issue
Block a user