I am following a tutorial that in a part of code it uses this fuction:
addToFavorites() {
if (!this.favorite) {
console.log('Adding to Favorites', this.dish.id);
this.favorite = this.favoriteservice.addFavorite(this.dish.id);
const toast = new Toasty("Added Dish "+ this.dish.id, "short", "bottom");
toast.show();
}
}
But I get this error message because of this line of the code const toast = new Toasty("Added Dish "+ this.dish.id, "short", "bottom");
:
Expected 1 arguments, but got 3.ts(2554)
It seems the Toasty
class/interface is changed, but I don't know how can I edit my code to get the same functionality?
Toasty is expecting 1 argument, like this: const toast = new Toasty({ text: 'Toast message' }) You need to use: position: ToastPosition and duration: ToastDuration
Example:
const toasty = new Toasty({
text: 'Somethign something...',
position: ToastPosition.TOP,
duration: ToastDuration.SHORT
});
Full description:
import { Toasty } from 'nativescript-toasty';
// Toasty accepts an object for customizing its behavior/appearance. The only REQUIRED value is text
which is the message for the toast.
const toast = new Toasty({ text: 'Toast message' });
toast.show();
// you can also chain the methods together and there's no need to create a reference to the Toasty instance with this approach
new Toasty({ text: 'Some Message' })
.setToastDuration(ToastDuration.LONG)
.setToastPosition(ToastPosition.BOTTOM)
.setTextColor(new Color('white'))
.setBackgroundColor('#ff9999')
.show();
// or you can set the properties of the Toasty instance
const toasty = new Toasty({
text: 'Somethign something...',
position: ToastPosition.TOP,
android: { yAxisOffset: 100 },
ios: {
anchorView: someButton.ios, // must be the native iOS view instance (button, page, action bar, tabbar, etc.)
displayShadow: true,
shadowColor: '#fff000',
cornerRadius: 24
}
});
toasty.duration = ToastDuration.SHORT;
toasty.textColor = '#fff';
toasty.backgroundColor = new Color('purple');
toasty.show();