Skip to content

Commit

Permalink
Merge pull request #19 from bradmartin/master
Browse files Browse the repository at this point in the history
Enhancements: color/background color and default positioning
  • Loading branch information
bradmartin authored Jun 17, 2019
2 parents 2e4ae14 + fb6580c commit ec5347c
Show file tree
Hide file tree
Showing 12 changed files with 280 additions and 74 deletions.
35 changes: 29 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ const toast = new Toasty('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('Some Message').setToastDuration(ToastDuration.LONG).show();
new Toasty('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('Somethign something...');
toasty.position = ToastPosition.CENTER;
toasty.position = ToastPosition.NO_SETTING;
toasty.duration = ToastDuration.SHORT;
toasty.textColor = '#fff';
toasty.backgroundColor = new Color('purple');
toasty.show();
```

Expand All @@ -37,10 +44,13 @@ toast.show();
### API

```typescript

constructor(
text: string,
duration?: ToastDuration,
position?: ToastPosition
position?: ToastPosition,
textColor?: Color | string,
backgroundColor?: Color | string
)

/**
Expand All @@ -58,11 +68,23 @@ toast.show();
*/
setToastPosition(value: ToastPosition): Toasty;


/**
* Sets the Toast duration.
*/
setToastDuration(value: ToastDuration: Toasty);
setToastDuration(value: ToastDuration): Toasty;

/**
* Set the text color of the toast.
* @param value [Color | string] - Color of the string message.
*/
setTextColor(value: Color | string): Toasty;

/**
* Set the background color of the toast.
* @param value [Color | string] - Color of the background.
* On Android this currently removes the default Toast rounded borders.
*/
setBackgroundColor(value: Color | string): Toasty;
```

```typescript
Expand All @@ -74,6 +96,7 @@ export enum ToastDuration {
export enum ToastPosition {
'BOTTOM',
'CENTER',
'TOP'
'TOP',
'NO_SETTING'
}
```
16 changes: 0 additions & 16 deletions demo/app/README.md

This file was deleted.

22 changes: 15 additions & 7 deletions demo/app/main-page.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
import { ToastDuration, ToastPosition, Toasty } from 'nativescript-toasty';
import { Color } from 'tns-core-modules/color/color';

export function shortToast() {
new Toasty('Short Toast').show();
}

export function longToast() {
new Toasty('Long Toast', ToastDuration.LONG)
.setToastPosition(ToastPosition.BOTTOM)
new Toasty('Long Toast with Red Text', ToastDuration.LONG)
.setTextColor(new Color('white'))
.setToastPosition(ToastPosition.NO_SETTING)
.setBackgroundColor('#ff9999')
.show();
}

export function chainedToast() {
new Toasty('Chained Toast Methods')
const t = new Toasty('Chained Toast Methods')
.setToastDuration(ToastDuration.LONG)
.setToastPosition(ToastPosition.CENTER)
.show();
.setTextColor('blue');
t.backgroundColor = 'white';
t.show();
}

export function positionToast() {
const toast = new Toasty('Position Toast');
console.log('setting position');
toast.position = ToastPosition.TOP;
toast.position = ToastPosition.BOTTOM;
toast.duration = ToastDuration.SHORT;
toast.textColor = 'black';
toast.backgroundColor = new Color('#fff000');
toast.show();
}

export function cancelToast() {
const toast = new Toasty('Canceling after 1 sec');
const toast = new Toasty('Canceling after 1 sec').setToastPosition(
ToastPosition.CENTER
);
toast.show();
setTimeout(() => {
toast.cancel();
Expand Down
3 changes: 3 additions & 0 deletions demo/nsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"useLegacyWorkflow": false
}
16 changes: 11 additions & 5 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,30 @@
"readme": "NativeScript Application",
"repository": "<fill-your-repository-here>",
"nativescript": {
"id": "org.nativescript.demo"
"id": "org.nativescript.demo",
"tns-android": {
"version": "5.4.0"
},
"tns-ios": {
"version": "5.4.2"
}
},
"dependencies": {
"nativescript-toasty": "file:../src",
"nativescript-theme-core": "~1.0.4",
"nativescript-unit-test-runner": "^0.5.0",
"tns-core-modules": "^5.2.2"
"tns-core-modules": "^5.4.1"
},
"devDependencies": {
"jasmine-core": "3.3.0",
"karma": "4.0.1",
"karma-jasmine": "1.1.2",
"karma-nativescript-launcher": "0.4.0",
"nativescript-dev-typescript": "~0.8.0",
"nativescript-dev-webpack": "^0.20.2",
"nativescript-dev-webpack": "0.24.1",
"tns-platform-declarations": "^5.2.2",
"tslint": "~5.13.1",
"typescript": "~3.1.6"
"tslint": "~5.17.0",
"typescript": "~3.4.5"
},
"scripts": {
"build.plugin": "cd ../src && npm run build",
Expand Down
51 changes: 31 additions & 20 deletions demo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"skipLibCheck": true,
"noImplicitAny": false,
"removeComments": true,
"preserveConstEnums": true,
"declaration": false,
"noLib": false,
"noEmitHelpers": true,
"experimentalDecorators": true,
"lib": ["es6", "dom"],
"baseUrl": ".",
"paths": {
"*": ["./node_modules/tns-core-modules/*", "./node_modules/*"],
"~/*": ["app/*"]
}
},
"exclude": ["node_modules", "platforms"]
}
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"skipLibCheck": true,
"noImplicitAny": false,
"removeComments": true,
"preserveConstEnums": true,
"declaration": false,
"noLib": false,
"noEmitHelpers": true,
"experimentalDecorators": true,
"lib": [
"es6",
"dom"
],
"baseUrl": ".",
"paths": {
"*": [
"./node_modules/tns-core-modules/*",
"./node_modules/*"
],
"~/*": [
"app/*"
]
}
},
"exclude": [
"node_modules",
"platforms"
]
}
7 changes: 7 additions & 0 deletions demo/tsconfig.tns.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"module": "es2015",
"moduleResolution": "node"
}
}
26 changes: 24 additions & 2 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
export declare class Toasty {
constructor(text: string, duration?: ToastDuration, position?: ToastPosition);
constructor(
text: string,
duration?: ToastDuration,
position?: ToastPosition,
textColor?: Color | string,
backgroundColor?: Color | string
);
position: ToastPosition;
duration: ToastDuration;
textColor: Color | string;
backgroundColor: Color | string;

/**
* Shows the toast message.
Expand All @@ -20,6 +28,19 @@ export declare class Toasty {
* @param value [ToastDuration] - Duration of toast.
*/
setToastDuration(value: ToastDuration): this;

/**
* Set the text color of the toast.
* @param value [Color | string] - Color of the string message.
*/
setTextColor(value: Color | string): this;

/**
* Set the background color of the toast.
* @param value [Color | string] - Color of the background.
* On Android this currently removes the default Toast rounded borders.
*/
setBackgroundColor(value: Color | string): this;
}

export enum ToastDuration {
Expand All @@ -30,5 +51,6 @@ export enum ToastDuration {
export enum ToastPosition {
'BOTTOM' = 'bottom',
'CENTER' = 'center',
'TOP' = 'top'
'TOP' = 'top',
'NO_SETTING' = 'no_setting'
}
8 changes: 4 additions & 4 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-toasty",
"version": "1.3.1",
"version": "1.4.0",
"description": "NativeScript toast plugin",
"main": "toasty",
"typings": "index.d.ts",
Expand Down Expand Up @@ -54,12 +54,12 @@
"homepage": "https://github.com/triniwiz/nativescript-toasty",
"readmeFilename": "README.md",
"devDependencies": {
"tns-core-modules": "^5.2.2",
"tns-platform-declarations": "^5.2.2",
"tns-core-modules": "^5.4.1",
"tns-platform-declarations": "^5.4.1",
"lint-staged": "^8.1.5",
"husky": "^1.3.1",
"prettier": "~1.16.4",
"typescript": "~3.1.6",
"typescript": "~3.4.5",
"tslint": "5.13.1",
"prompt": "^1.0.0",
"rimraf": "^2.6.3",
Expand Down
3 changes: 2 additions & 1 deletion src/toast.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export enum ToastDuration {
export enum ToastPosition {
'BOTTOM' = 'bottom',
'CENTER' = 'center',
'TOP' = 'top'
'TOP' = 'top',
'NO_SETTING' = 'no_setting'
}
Loading

0 comments on commit ec5347c

Please sign in to comment.