Skip to content

Fancy Alert

Beautiful, customizable alert dialogs for NativeScript.

Based on:

Installation

bash
npm install @nstudio/nativescript-fancyalert

Demo

iOSAndroid
iOSAndroid

Usage

Basic Alerts

typescript
import { TNSFancyAlert, TNSFancyAlertButton } from '@nstudio/nativescript-fancyalert';

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

// Show error
TNSFancyAlert.showError('Error!', 'Something bad happened.', 'Close');

// Show warning
TNSFancyAlert.showWarning('Warning!', 'Be careful.', 'Got it');

// Show info
TNSFancyAlert.showInfo('Info', 'Here is some information.', 'OK');

// Show notice
TNSFancyAlert.showNotice('Notice', 'Please take note.', 'Understood');

Customization (iOS)

typescript
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 customize animations and more.', 'Amazing!');

Custom Image

typescript
TNSFancyAlert.showCustomImage(
  'nativescript.png', 
  '#2B33FF', 
  'Custom Image', 
  'Using your own images is nice.', 
  'Yes!'
);

Custom Buttons (iOS)

typescript
let buttons = [
  new TNSFancyAlertButton({
    label: 'One',
    action: () => console.log('One'),
  }),
  new TNSFancyAlertButton({
    label: 'Two',
    action: () => console.log('Two'),
  }),
];

TNSFancyAlert.showCustomButtons(
  buttons, 
  undefined, 
  undefined, 
  'Got Buttons?', 
  "Add as many as you'd like.", 
  'Ok'
);

Text Input (iOS)

typescript
TNSFancyAlert.showTextField(
  'Enter your name',
  null,
  new TNSFancyAlertButton({
    label: 'Save',
    action: (value: any) => {
      console.log(`User entered ${value}`);
    },
  }),
  undefined,
  undefined,
  'User Input?',
  'Yeah, sure we can.',
  'Ok'
);

Switch (iOS)

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

iOS Properties

PropertyDescription
shouldDismissOnTapOutsideDismiss when tapped outside
hideAnimationTypeAnimation type when hiding
showAnimationTypeAnimation type when showing
backgroundTypeShadow, Blur, or Transparent
customViewColorOverwrite buttons and borders colors
titleColorCustom title color
bodyTextColorCustom body text color
cornerRadiusCustom corner radius
soundURLPlay mp3 from App_Resources

iOS Methods

  • showSuccess(), showError(), showNotice(), showWarning(), showInfo()
  • showEdit(), showWaiting(), showQuestion()
  • showCustomImage(), showCustomButtons()
  • showTextField(), showSwitch(), showCustomView()

Android Methods

  • showSuccess(), showError(), showNotice(), showWarning(), showInfo()
  • showColorDialog() - Returns a Promise

License

Apache License Version 2.0