• Stars
    star
    149
  • Rank 248,619 (Top 5 %)
  • Language
    TypeScript
  • License
    Other
  • Created over 8 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fancy alerts for NativeScript.

NativeScript 7 or higher

If using 6 and below, see the following:

Fancy alerts for NativeScript.

Based on:

Install

NativeScript 4x

tns plugin add nativescript-fancyalert

NativeScript 3x and older

tns plugin add [email protected]

Sample iOS

Sample Android

iOS Specifications

Usage Examples

import { TNSFancyAlert, TNSFancyAlertButton } from "nativescript-fancyalert";

// show success
TNSFancyAlert.showSuccess(
  "Success!",
  "Fancy alerts are nice.",
  "Yes they are!"
);

// set customizations
TNSFancyAlert.showAnimationType =
  TNSFancyAlert.SHOW_ANIMATION_TYPES.SlideInFromLeft;
TNSFancyAlert.hideAnimationType =
  TNSFancyAlert.HIDE_ANIMATION_TYPES.SlideOutToRight;
TNSFancyAlert.backgroundType = TNSFancyAlert.BACKGROUND_TYPES.Blur;
TNSFancyAlert.soundURL = "bell.mp3";
TNSFancyAlert.showSuccess(
  "Sound?",
  "You can use sound and customize many aspects like animation in/out, color, background style and much more.",
  "Amazing!"
);

// show custom image
TNSFancyAlert.showCustomImage(
  "nativescript.png",
  "#2B33FF",
  "Custom Image",
  `Using your own images is sure nice.`,
  "Yes!"
);

// show custom button timer
TNSFancyAlert.showCustomButtonTimer(
  0,
  true,
  undefined,
  undefined,
  "Mission Impossible",
  `This will self-destruct in 5 seconds.`,
  "Ok"
);

// show custom buttons
let buttons = [
  new TNSFancyAlertButton({
    label: "One",
    action: () => {
      console.log("One");
    }
  }),
  new TNSFancyAlertButton({
    label: "Two",
    action: () => {
      console.log("Two");
    }
  }),
  new TNSFancyAlertButton({
    label: "Three",
    action: () => {
      console.log("Three");
    }
  }),
  new TNSFancyAlertButton({
    label: "Four",
    action: () => {
      console.log("Four");
    }
  }),
  new TNSFancyAlertButton({
    label: "Really? More?",
    action: () => {
      console.log("more");
    }
  })
];
TNSFancyAlert.showCustomButtons(
  buttons,
  undefined,
  undefined,
  "Got Buttons?",
  `Add as many as you'd like.`,
  "Ok"
);

// show with custom width
TNSFancyAlert.showSuccess(
  "Success!",
  "This uses a custom width of 300.",
  `Oh that's nice.`,
  0,
  300
);

// show textfield
let initialValue = null;
TNSFancyAlert.showTextField(
  "Enter your name",
  initialValue,
  new TNSFancyAlertButton({
    label: "Save",
    action: (value: any) => {
      console.log(`User entered ${value}`);
    }
  }),
  undefined,
  undefined,
  "User Input?",
  `Yeah, sure we can.`,
  "Ok, lots of options."
);

// show switch
TNSFancyAlert.showSwitch(
  `Don't show again`,
  "#58B136",
  new TNSFancyAlertButton({
    label: "Save",
    action: (isSelected: boolean) => {
      console.log(`Don't show again was selected: ${isSelected}`);
    }
  }),
  "switch.png",
  "#B3714F",
  "Need a switch?",
  `It can be useful.`,
  "Got it."
);

TNSFancyAlert - Properties

Property Description
TNSFancyAlert.SUPPORTED_TYPES: IFancyAlertSupportedTypes Different supported style types.
TNSFancyAlert.shouldDismissOnTapOutside: boolean Should dismiss when tapped outside.
TNSFancyAlert.dismissCallback: () => void Callback for when alert is dismissed.
TNSFancyAlert.hideAnimationType: IFancyAlertHideAnimationTypes Use TNSFancyAlert.HIDE_ANIMATION_TYPES to set. Supports: FadeOut, SlideOutToBottom, SlideOutToTop, SlideOutToLeft, SlideOutToRight, SlideOutToCenter, SlideOutFromCenter.
TNSFancyAlert.showAnimationType: IFancyAlertShowAnimationTypes Use TNSFancyAlert.SHOW_ANIMATION_TYPES to set. Supports: FadeIn, SlideInFromBottom, SlideInFromTop, SlideInFromLeft, SlideInFromRight, SlideInFromCenter, SlideInToCenter.
TNSFancyAlert.backgroundType: IFancyAlertBackgroundTypes Use TNSFancyAlert.BACKGROUND_TYPES to set. Supports: Shadow, Blur, Transparent.
TNSFancyAlert.customViewColor: string Overwrite (Buttons, top circle and borders) colors.
TNSFancyAlert.iconTintColor: string Set custom tint color for icon image.
TNSFancyAlert.titleColor: string Set custom title color.
TNSFancyAlert.bodyTextColor: string Set custom body text color.
TNSFancyAlert.tintTopCircle: string Override top circle tint color with background color
TNSFancyAlert.cornerRadius: number Set custom corner radius.
TNSFancyAlert.backgroundViewColor: string Overwrite background color
TNSFancyAlert.useLargerIcon: boolean Make the top circle icon larger
TNSFancyAlert.soundURL: string Use mp3 from App_Resources when alert shows.
TNSFancyAlert.textDisplayOptions: IFancyAlertTextOptions IOS Only. Text display options

TNSFancyAlert - Methods

  • showSuccess(title: string, subTitle?: string, closeBtnTitle?: string, duration?: number, width?: number, buttons?: Array<TNSFancyAlertButton>)
  • showError(title: string, subTitle?: string, closeBtnTitle?: string, duration?: number, width?: number, buttons?: Array<TNSFancyAlertButton>)
  • showNotice(title: string, subTitle?: string, closeBtnTitle?: string, duration?: number, width?: number, buttons?: Array<TNSFancyAlertButton>)
  • showWarning(title: string, subTitle?: string, closeBtnTitle?: string, duration?: number, width?: number, buttons?: Array<TNSFancyAlertButton>)
  • showInfo(title: string, subTitle?: string, closeBtnTitle?: string, duration?: number, width?: number, buttons?: Array<TNSFancyAlertButton>)
  • showEdit(title: string, subTitle?: string, closeBtnTitle?: string, duration?: number, width?: number, buttons?: Array<TNSFancyAlertButton>)
  • showWaiting(title: string, subTitle?: string, closeBtnTitle?: string, duration?: number, width?: number)
  • showQuestion(title: string, subTitle?: string, closeBtnTitle?: string, duration?: number, width?: number, buttons?: Array<TNSFancyAlertButton>)
  • showCustomButtonTimer(buttonIndex: number, reverse?: boolean, imageName?: string, color?: string, title?: string, subTitle?: string, closeBtnTitle?: string, duration?: number, width?: number)
  • showCustomImage(imageName: string, color: string, title: string, subTitle?: string, closeBtnTitle?: string, duration?: number, width?: number)
  • showCustomButtons(buttons: Array<TNSFancyAlertButton>, imageName: string, color: string, title: string, subTitle?: string, closeBtnTitle?: string, duration?: number, width?: number)
  • showCustomTextAttributes(attributionBlock: Function, button: TNSFancyAlertButton, imageName: string, color: string, title: string, subTitle?: string, closeBtnTitle?: string, duration?: number, width?: number)
  • showTextField(placeholder: string, initialValue: string, button: TNSFancyAlertButton, imageName: string, color: string, title: string, subTitle?: string, closeBtnTitle?: string, duration?: number, width?: number)
  • showSwitch(switchLabel: string, switchColor: string, button: TNSFancyAlertButton, imageName: string, color: string, title: string, subTitle?: string, closeBtnTitle?: string, duration?: number, width?: number)
  • showCustomView(customView: any, imageName?: string, color?: string, title?: string, subTitle?: string, closeBtnTitle?: string, duration?: number, width?: number)
  • show(type: string, title: string, subTitle?: string, closeBtnTitle?: string, duration?: number, width?: number, buttons?: Array<TNSFancyAlertButton>)
  • showCustom(alert: any, imageName: string, color: string, title?: string, subTitle?: string, closeBtnTitle?: string, duration?: number)
  • createAlert(width?: number)

Android Specifications

Usage Examples

NOTE: Android supports only a subset of the iOS features, but will return a Promise on every call:

import { TNSFancyAlert, TNSFancyAlertButton } from "nativescript-fancyalert";

// show success
TNSFancyAlert.showSuccess(
  "Success!",
  "Fancy alerts are nice.",
  "Yes they are!"
).then(() => {
  /* user pressed the button */
});

// show error
TNSFancyAlert.showError("Error!", "Something bad happened.", "Close").then(
  () => {
    /* user pressed the button */
  }
);

TNSFancyAlert - Methods

  • showSuccess(title: string, subTitle?: string, closeBtnTitle?: string): Promise<any>
  • showError(title: string, subTitle?: string, closeBtnTitle?: string): Promise<any>
  • showNotice(title: string, subTitle?: string, closeBtnTitle?: string): Promise<any>
  • showWarning(title: string, subTitle?: string, closeBtnTitle?: string): Promise<any>
  • showInfo(title: string, subTitle?: string, closeBtnTitle?: string): Promise<any>
  • showColorDialog(
      title: string,
      subTitle?: string,
      okBtnTitle?: string,
      cancelBtnTitle?: string,
      backgroundColor?: string,
      titleTextColor?: string,
      contextTextColor?: string,
      contentImage?: any
    ): Promise<any>```
    
    

TNSFancyAlertButton (iOS only)

This class can be instantiated on iOS to configure buttons in the fancy alerts.

export class TNSFancyAlertButton {
  public label: string;
  public action: Function;
  public applyStyle: (btn: any) => void;

  constructor(model?: any) {
    if (model) {
      this.label = model.label;
      this.action = model.action;
      this.applyStyle = model.applyStyle;
    }
  }
}
  • label: display text on the button
  • action: the method to invoke when the button is tapped on
  • applyStyle: a method you can configure to style the button however you'd like using iOS properties. This method will hand back an instance of SLCButton which inherits from UIButton. You can see more of what methods are available on this class here.

Here's an example of how to setup a custom background color:

new TNSFancyAlertButton({
  label: 'Ok',
  action: () => {
    // the action to take
  },
  applyStyle: (btn: UIButton) => {
    // we can use UIButton typing when using tns-platform-declarations
    // however we can cast to any since you are likely not using SLCAlertView typings (they are in this repo if you want to use them :) )
    // refer to https://github.com/dogo/SCLAlertView/blob/develop/SCLAlertView/SCLButton.m on what properties are available to customize

    (<any>btn).buttonFormatBlock = () => {
      // set a custom backgroundColor
      return new (NSDictionary as any)([new Color('#3a3939').ios], ['backgroundColor']);
    }
  }
}),

Why the TNS prefixed name?

TNS stands for Telerik NativeScript

iOS uses classes prefixed with NS (stemming from the 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.

Tutorials

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

Fancy Alerts in a NativeScript with Angular Application

License

MIT

More Repositories

1

angular-seed-advanced

Advanced Angular seed project with support for ngrx/store, ngrx/effects, ngx-translate, angulartics2, lodash, NativeScript (*native* mobile), Electron (Mac, Windows and Linux desktop) and more.
TypeScript
2,262
star
2

ng2-image-lazy-load

Angular2 image lazy loader library.
TypeScript
161
star
3

nativescript-loading-indicator

Progress/Loading indicator with options for NativeScript. iOS + Android.
TypeScript
112
star
4

nativescript-angular-web-components

Experimental: Render NativeScript views on the web.
TypeScript
100
star
5

nativescript-ngx-fonticon

Use custom font icon collections seamlessly with NativeScript + Angular.
TypeScript
77
star
6

nativescript-plugin-seed

66
star
7

nativescript-ng2-magic

Magically turn your Angular2 web app into a NativeScript app.
JavaScript
64
star
8

nativescript-fonticon

Use custom font icon collections seamlessly with NativeScript.
TypeScript
50
star
9

ngTunes

🎵 The Community Angular 2 Music Player. 🎵
JavaScript
48
star
10

template-nativescript-nx

NativeScript template for Nx workspace https://nrwl.io/nx
TypeScript
38
star
11

nativescript-coachmarks

Display user coach marks with shape cutouts over an existing UI for NativeScript.
TypeScript
30
star
12

ShoutOutPlay

The mobile app that allows you to create and record personal dedications using your favorite music playlists for corporate events, parties, weddings and get togethers.
TypeScript
30
star
13

nativescript-spotify

A NativeScript plugin for the Spotify iOS and Android SDK's.
Objective-C
25
star
14

solid-x-platforms

Solid running on Web, iOS, Android and Vision Pro.
Swift
23
star
15

lava-lamp

Credit to @Inncoder_, An Nx workspace with Angular, React, Solid, Svelte, TypeScript and Vue iOS apps all sharing the same SwiftUI files via NativeScript.
TypeScript
20
star
16

MaterialCard

iOS Material Design Card View.
Swift
15
star
17

nativescript-ng2-vscode-snippets

Snippets for NativeScript + Angular 2 Development.
14
star
18

nativescript-ng2-windchimes

A NativeScript + Angular2 wind chime app for iOS and Android.
TypeScript
12
star
19

ns-ultimate-tab-setup

An example repo for exploration into setting up standard mobile Tab navigation via NativeScript.
TypeScript
12
star
20

nativescript-shimmer

Facebook Shimmer effect for your NativeScript app - iOS and Android.
TypeScript
12
star
21

ios18-examples

iOS 18 Highlights with NativeScript
Swift
11
star
22

ionic-nativescript

Angular Ionic app built with Capacitor and NativeScript
TypeScript
10
star
23

nativescript-visionos-explore

Exploring Vision Pro with NativeScript.
TypeScript
10
star
24

nativescript-swiftui-examples

SwiftUI with NativeScript example
TypeScript
9
star
25

nativescript-ezaudio

A NativeScript plugin for EZAudio: the simple, intuitive audio framework for iOS.
TypeScript
9
star
26

raspberrypi-admin

Raspberry PI Web Administration
JavaScript
8
star
27

nx-javascriptisdead

Nx workspace delivering optimal UX across Web, iOS and Android via Analog and NativeScript.
TypeScript
8
star
28

nativescript-ios-metaballs

Metaballs with NativeScript and SwiftUI
Swift
6
star
29

nativescript-ng2-translate

Use ng2-translate with NativeScript + Angular2.
JavaScript
6
star
30

ng-native

TypeScript
6
star
31

nativescript-webpack-import-replace

NativeScript for Angular webpack plugin to rewrite various imports with target platform suffix to allow various Angular Components, Directives, or Pipes to properly AoT compile.
JavaScript
6
star
32

NativeScript-Flutter-Example

A NativeScript with Flutter example highlighting talented work from Roaa, whereby an Action Menu (Flutter) and Card Flipper (Flutter) are populated via an Angular service that interacts with iOS UIMenu and Android PopupMenu.
Dart
6
star
33

vision-pro-angular

Vision Pro 🥽 for Angular Developers
Swift
6
star
34

nativescript-theme-seed

Build a custom NativeScript theme quickly.
TypeScript
5
star
35

ng2-cli-test-lib

JavaScript
4
star
36

nativescript-theme-christmas

A Vintage Christmas theme for NativeScript apps.
TypeScript
4
star
37

SwiftyCam

Swift
3
star
38

ng2-img-pusher-gif

Easily implement native vertical responsive scaling by creating on-the-fly GIFs via base64.
TypeScript
3
star
39

nativescript-christmas-special

TypeScript
2
star
40

nativescript4angular-demo

Sample NativeScript for Angular app demonstrating some key concepts in as simplest way as possible.
TypeScript
2
star
41

PocketRave-App

NativeScript and Angular 2 App for Raves, Light Shows, and other Awesome Things
TypeScript
2
star
42

ioniconf2022

Ioniconf 2022 "Opening Doors with Portals"
TypeScript
2
star
43

todo-list

Simple todo list made in angular 2
JavaScript
1
star
44

nativescript-angular-formly

NativeScript powered forms for Angular. Based on ng2-formly.
TypeScript
1
star
45

ng-7-0-test-with-angular-react-latest

TypeScript
1
star
46

ns-text-stroke

TypeScript
1
star
47

tns-audiokit

Objective-C
1
star
48

nativescript-atom-snippets

Snippets for NativeScript + Angular 2 Development.
CoffeeScript
1
star
49

nx-ns-examples

TypeScript
1
star
50

nativescript-square

JavaScript
1
star
51

nativescript-webview-advanced

A rich webview for your NativeScript app.
TypeScript
1
star
52

ns-collection-view-extra

Blog series example repo highlighting CollectionView, a super powered list control with recycled rows providing you best of class on each platform suited to fit all sorts of needs.
TypeScript
1
star
53

nativescript-ng2-atom-snippets

Snippets for NativeScript + Angular 2 Development.
CoffeeScript
1
star