Readme update

This commit is contained in:
ElNinjaGaiden 2016-05-31 18:04:50 -06:00
parent 0b76cb8811
commit 37a73baa1f

View File

@ -185,6 +185,24 @@ function hide() {
} }
``` ```
When the toast gets hidden, your success callback will be called (in case you have defined one) with the `event` property equals to `hide` (more details about the callback in the next section).
```js
window.plugins.toast.showWithOptions({
message: 'My message',
// More config here...
},
//Success callback
function(args) {
console.log(args.event);
//This will print 'hide'
},
function(error) {
console.error('toast error: ', error);
}
);
```
### Receiving a callback when a Toast is tapped ### Receiving a callback when a Toast is tapped
On iOS and Android the success handler of your `show` function will be notified (again) when the toast was tapped. On iOS and Android the success handler of your `show` function will be notified (again) when the toast was tapped.
@ -203,17 +221,21 @@ called again. You can distinguish between those events of course:
// implement the success callback // implement the success callback
function(result) { function(result) {
if (result && result.event) { if (result && result.event) {
console.log("The toast was tapped"); console.log("The toast was tapped or got hidden, see the value of result.event");
console.log("Event: " + result.event); // will be defined, with a value of "touch" when it was tapped by the user console.log("Event: " + result.event); // "touch" when the toast was touched by the user or "hide" when the toast geot hidden
console.log("Message: " + result.message); // will be equal to the message you passed in 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 console.log("data.foo: " + result.data.foo); // .. retrieve passed in data here
} else {
if (result.event === 'hide') {
console.log("The toast has been shown"); console.log("The toast has been shown");
} }
} }
}
); );
``` ```
The success callback is useful when your toast is binded to a notification id in your backend and you have to mark it as `read` when the toast is done, or to update the notifications counter for iOS. The usage of this will be defined by your application logic. Use the `result.data` object to support your specific logic.
### Styling ### Styling
Since version 2.4.0 you can pass an optional `styling` object to the plugin. Since version 2.4.0 you can pass an optional `styling` object to the plugin.
The defaults make sure the Toast looks the same as when you would not pass in the `styling` object at all. The defaults make sure the Toast looks the same as when you would not pass in the `styling` object at all.