0.4.4 • Published 10 months ago

@manhtruongwang/react-native-alert-dialog v0.4.4

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

react-native-alert-dialog

Example Dialog Box

Theme LightTheme Dark

Example Toast Notification

Theme LightTheme Dark

Installation

- Installing:

yarn add react-native-alert-dialog

- Installing dependencies:

  • For Native project:
yarn add react-native-safe-area-context

pod install
  • For Expo project:
expo install react-native-safe-area-context

Usage

import { ALERT_TYPE, Dialog, AlertNotificationRoot, Toast } from 'react-native-alert-notification';

<AlertNotificationRoot>
  <View>
    // dialog box with single button
    <Button
      title={'dialog box'}
      onPress={() =>
        Dialog.show({
          type: ALERT_TYPE.SUCCESS,
          title: 'Success',
          textBody: 'Congrats! this is dialog box success',
          button: 'close',
        })
      }
    />
    // dialog box with cancel & confirm buttons
    <Button
      title={'confirmation dialog'}
      onPress={() =>
        Dialog.show({
          type: ALERT_TYPE.WARNING,
          title: 'Confirm Action',
          textBody: 'Are you sure you want to proceed with this action?',
          cancelButton: 'Cancel',
          confirmButton: 'Proceed',
          onPressCancel: () => console.log('Action cancelled'),
          onPressConfirm: () => console.log('Action confirmed'),
        })
      }
    />
    // toast notification
    <Button
      title={'toast notification'}
      onPress={() =>
        Toast.show({
          type: ALERT_TYPE.SUCCESS,
          title: 'Success',
          textBody: 'Congrats! this is toast notification success',
          paddingTop: 45, // custom top padding
        })
      }
    />
  </View>
</AlertNotificationRoot>;

Documentation:

Root Component

A React node that will be most likely wrapping your whole app.

NameDescriptionRequireDefaultType
themeselect theme light dark (by default is auto)auto'light','dark'
colorscustom colorsIColors, IColors
dialogConfigconfig dialog box global{closeOnOverlayTap:bool, autoClose:bool / number}
toastConfigconfig toast global{autoClose:bool / number, titleStyle?: StyleProp , textBodyStyle?: StyleProp}
type IProps = {
  dialogConfig?: Pick<IConfigDialog, 'closeOnOverlayTap' | 'autoClose'>;
  toastConfig?: Pick<IConfigToast, 'autoClose' | 'titleStyle' | 'textBodyStyle'>;
  theme?: 'light' | 'dark';
  colors?: [IColors, IColors] /** ['light_colors' , 'dark_colors'] */;
};
type IColors = {
  label: string;
  card: string;
  overlay: string;
  success: string;
  danger: string;
  warning: string;
};

Dialog Box Component

NameDescriptionRequireDefaultType
titleThe title textString
typeDefines the type ("Success", "Warning" or "Error")true"SUCCESS", "DANGER", "WARNING"
textBodyThe text bodyString
buttonname button (for hide button: undefined)String
cancelButtonText for cancel button in dual-button layoutString
confirmButtonText for confirm button in dual-button layoutString
autoCloseDefines time auto close dialog box in msfacebool / number
closeOnOverlayTapallow close if click in overlaytruebool
onPressButton(if not declared and isset button action is close)String() => void
onPressCancelAction when cancel button is pressed() => void
onPressConfirmAction when confirm button is pressed() => void
onShowaction after end animation open() => void
onHideaction after end animation close() => void
type IConfig = {
  type: ALERT_TYPE;
  title?: string;
  textBody?: string;
  button?: string;
  cancelButton?: string;
  confirmButton?: string;
  autoClose?: number | boolean;
  closeOnOverlayTap?: boolean;
  onPressButton?: () => void;
  onPressCancel?: () => void;
  onPressConfirm?: () => void;
  onShow?: () => void;
  onHide?: () => void;
};

Toast Notification Component

NameDescriptionRequireDefaultType
titleThe title textString
typeDefines the type ("Success", "Warning" or "Error")"SUCCESS", "DANGER", "WARNING"
textBodyThe text bodyString
autoCloseDefines time auto close dialog box in ms5000bool / number
paddingTopSpecify custom top padding0number
onPressaction click in cardbool
onShowevent after end animation open() => void
onHideevent after end animation close() => void
type IConfig = {
  type?: ALERT_TYPE;
  title?: string;
  textBody?: string;
  autoClose?: number | boolean;
  paddingTop?: number;
  titleStyle?: StyleProp<TextStyle>;
  textBodyStyle?: StyleProp<TextStyle>;
  onPress?: () => void;
  onShow?: () => void;
  onHide?: () => void;
};

For Close popup

// For Dialog Box
Dialog.hide();

// For Toast Notification
Toast.hide();

Author

Truong Quang Manh | https://vietgigs.vn

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT