Skip to content

Commit

Permalink
Angular demo updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
NazimMertBilgi committed Jun 25, 2020
1 parent 059a4ce commit b26c600
Show file tree
Hide file tree
Showing 6 changed files with 316 additions and 14 deletions.
13 changes: 10 additions & 3 deletions demo-angular/src/app/home/home.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<ActionBar>
<Label text="Home"></Label>
<Label text="NativeScript SweetAlert"></Label>
</ActionBar>

<GridLayout>
<!-- Add your page content here -->
<GridLayout rows="*,*,*,*,*,*,*,*" verticalAlignment="top">
<Button row="0" text="SweetAlert NORMAL" (tap)="showNormal()"></Button>
<Button row="1" text="SweetAlert ERROR" (tap)="showError()"></Button>
<Button row="2" text="SweetAlert SUCCESS" (tap)="showSuccess()"></Button>
<Button row="3" text="SweetAlert WARNING" (tap)="showWarning()"></Button>
<Button row="4" text="SweetAlert CUSTOM IMAGE" (tap)="showCustomImage()"></Button>
<Button row="5" text="SweetAlert DARK MODE" (tap)="showDarkMode()"></Button>
<Button row="6" text="SweetAlert TEXTVIEW" (tap)="showText()"></Button>
<Button row="7" text="SweetAlert CHECKBOX" (tap)="showCheckbox()"></Button>
</GridLayout>
114 changes: 108 additions & 6 deletions demo-angular/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,118 @@
import { Component, OnInit } from "@angular/core";
import { Component } from "@angular/core";
import { SweetAlert } from "nativescript-sweet-alert";
import { ShowCustomImage, ShowWarning, ShowSuccess, ShowError, ShowNormal, ShowText, ShowCheckbox, SweetAlertDialogTypes } from 'nativescript-sweet-alert/classes';
import * as application from "tns-core-modules/application";

const Toast = android.widget.Toast;
const context = application.android.startActivity;

@Component({
selector: "Home",
templateUrl: "./home.component.html"
})
export class HomeComponent implements OnInit {
export class HomeComponent {

showNormal() {
const options: ShowNormal = {
text: "Merhaba",
contentText: "İlk Alert Denemesi",
confirmButtonText: "Tamam",
cancelButtonText: "Kapat",
successMessageText: "Başarılı!",
successMessageContentText: "Başarıyla tamamlandı.",
successMessageButtonText: "Kapat"
}
SweetAlert.showNormal(options).then(value => {
Toast.makeText(context, "result: " + value, Toast.LENGTH_SHORT).show();
});
}

showError() {
const options: ShowError = {
text: "Merhaba",
contentText: "İlk Alert Denemesi",
confirmButtonText: "Tamam",
cancelButtonText: "Kapatt"
}
SweetAlert.showError(options).then(value => {
Toast.makeText(context, "result: " + value, Toast.LENGTH_SHORT).show();
});
}

showSuccess() {
const options: ShowSuccess = {
text: "Merhaba",
contentText: "İlk Alert Denemesi",
confirmButtonText: "Tamam",
cancelButtonText: "Kapat"
}
SweetAlert.showSuccess(options).then(value => {
Toast.makeText(context, "result: " + value, Toast.LENGTH_SHORT).show();
});
}

showWarning() {
const options: ShowWarning = {
text: "Merhaba",
contentText: "İlk Alert Denemesi",
confirmButtonText: "Tamam",
cancelButtonText: "Kapat"
}
SweetAlert.showWarning(options).then(value => {
Toast.makeText(context, "result: " + value, Toast.LENGTH_SHORT).show();
});
}

showCustomImage() {
const options: ShowCustomImage = {
imagePath: "~/assets/images/nmb.jpeg",
text: "Merhaba",
contentText: "Big <font color='green'>green </font><b><i> bold</i></b>",
confirmButtonText: "Tamam",
cancelButtonText: "Kapat"
}
SweetAlert.showCustomImage(options).then(value => {
Toast.makeText(context, "result: " + value, Toast.LENGTH_SHORT).show();
});
}

showDarkMode() {
const options: ShowSuccess = {
text: "Merhaba",
contentText: "İlk Alert Denemesi",
confirmButtonText: "Tamam",
cancelButtonText: "Kapat",
darkMode: true
}
SweetAlert.showSuccess(options).then(value => {
Toast.makeText(context, "result: " + value, Toast.LENGTH_SHORT).show();
});
}

constructor() {
// Use the component constructor to inject providers.
showText() {
const options: ShowText = {
text: "Merhaba",
confirmButtonText: "Tamam",
cancelButtonText: "Kapat",
textViewText: "I'm text field.",
customImage: "~/assets/images/nmb.jpeg"
}
SweetAlert.showText(options).then(value => {
Toast.makeText(context, "result: " + value, Toast.LENGTH_SHORT).show();
});
}

ngOnInit(): void {
// Init your component properties here.
showCheckbox() {
const options: ShowCheckbox = {
text: "Merhaba",
checkBoxChecked: true,
checkBoxText: "Notification Sound",
confirmButtonText: "Tamam",
cancelButtonText: "Kapat",
customImage: SweetAlertDialogTypes.SUCCESS_TYPE
}
SweetAlert.showCheckbox(options).then(value => {
Toast.makeText(context, "result: " + value, Toast.LENGTH_SHORT).show();
});
}
}
Binary file added package/nativescript-sweet-alert-1.0.3.tgz
Binary file not shown.
81 changes: 81 additions & 0 deletions publish/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
SweetAlert library for NativeScript Android.

Based on:

- Android [F0RIS/sweet-alert-dialog](https://github.com/F0RIS/sweet-alert-dialog)

# Install

### NativeScript 6x

```bash
tns plugin add nativescript-sweet-alert
```

![Sample Android](screenshots/alert-android.gif)


# Android Specifications

#### Usage Examples

NOTE: "options" may vary according to each method.

```js
import { SweetAlert } from 'nativescript-sweet-alert';
import { ShowSuccess , ShowError } from 'nativescript-sweet-alert/classes';


// showSuccess
const options: ShowSuccess = {
text: "Hello",
contentText: "Alert Content Text",
confirmButtonText: "Ok",
cancelButtonText: "Close"
}
SweetAlert.showSuccess(options).then(value => {
// result: true, false, CLOSED
});

// showError
const options: ShowError = {
text: "Hello",
contentText: "Alert Content Text",
confirmButtonText: "Ok",
cancelButtonText: "Close"
}
SweetAlert.showError(options).then(value => {
// result: true, false, CLOSED
});

```

#### NativeScript SweetAlert - Methods

- `showNormal(options: ShowNormal): Promise<any>`
- `showError(options: ShowError): Promise<any>`
- `showSuccess(options: ShowSuccess): Promise<any>`
- `showWarning(options: ShowWarning): Promise<any>`
- `showCustomImage(options: ShowCustomImage): Promise<any>`
- `showText(options: ShowText): Promise<any>`
- `showCheckbox(options: ShowCheckbox): Promise<any>`


## Why the TNS prefixed name?

`TNS` stands for **T**elerik **N**ative**S**cript

iOS uses classes prefixed with `NS` (stemming from the [NeXTSTEP](https://en.wikipedia.org/wiki/NeXTSTEP) days of old):
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/

To avoid confusion with iOS native classes, `TNS` is used instead.

## Demo

Need extra help getting these SweetAlert working in your application? Check out these tutorials that make use of the plugin:

[SweetAlert in a NativeScript Core Demo](https://github.com/NazimMertBilgi/nativescript-sweet-alert/blob/master/demo/app/home/home-page.ts)

## License

MIT
111 changes: 111 additions & 0 deletions publish/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nativescript-sweet-alert",
"version": "1.0.0",
"description": "Your awesome NativeScript plugin.",
"version": "1.0.3",
"description": "SweetAlert library for NativeScript Android.",
"main": "sweet-alert",
"typings": "index.d.ts",
"nativescript": {
Expand Down Expand Up @@ -34,11 +34,12 @@
"NativeScript",
"JavaScript",
"Android",
"iOS"
"iOS",
"SweetAlert"
],
"author": {
"name": "Your Name",
"email": "youremail@yourdomain.com"
"name": "Nazım Mert Bilgi",
"email": "nmbjobs@outlook.com.tr"
},
"bugs": {
"url": "https://github.com/NazimMertBilgi/nativescript-sweet-alert/issues"
Expand Down

0 comments on commit b26c600

Please sign in to comment.