0.2.17 • Published 7 years ago

react-native-dialog-component v0.2.17

Weekly downloads
326
License
MIT
Repository
github
Last release
7 years ago

React Native Dialog Component

React Native Dialog Component for iOS & Android.

Pull request are welcomed. Please follow Airbnb JS Style Guide

Preview

Try With Exponent

Exponent

Installation

npm install --save react-native-dialog-component
# OR
yarn add react-native-dialog-component

Exposed Modules

  • DialogManager
  • DialogComponent
  • Dialog
  • DialogContent
  • DialogButton
  • DialogTitle
  • Overlay
  • Animation
  • FadeAnimation
  • ScaleAnimation
  • SlideAnimation

Examples

Example

Usage With DialogManager

import DialogManager, { ScaleAnimation, DialogContent } from 'react-native-dialog-component';

show

DialogManager.show({
  title: 'Dialog',
  titleAlign: 'center',
  animationDuration: 200,
  ScaleAnimation: new ScaleAnimation(),
  children: (
    <DialogContent>
      <View>
        <Text>
          React Native Dialog Component
        </Text>
      </View>
    </DialogContent>
  ),
}, () => {
  console.log('callback - show');
});

update

DialogManager.update({
  title: 'Dialog Updated',
  titleAlign: 'center',
  animationDuration: 200,
  ScaleAnimation: new ScaleAnimation(),
  children: (
    <DialogContent>
      <View>
        <Text>
          New Content
        </Text>
      </View>
    </DialogContent>
  ),
}, () => {
  console.log('callback - update dialog');
});

dismiss

// dismiss dialog
DialogManager.dismiss(() => {
  console.log('callback - dismiss');
});

dismiss all

DialogManager.dismissAll(() => {
  console.log('callback - dismiss all');
});

Usage with DialogComponent

import { DialogComponent }from 'react-native-dialog-component';

<View style={styles.container}>
  <Button
    text="Show Dialog"
    onPress={() => {
      this.dialogComponent.show();
    }}
  />
  <DialogComponent
    ref={(dialogComponent) => { this.dialogComponent = dialogComponent; }}
  >
    <View>
      <Text>Hello</Text>
    </View>
  </DialogComponent>
</View>

Usage - With Animation

import { DialogComponent, SlideAnimation } from 'react-native-dialog-component';

<View style={styles.container}>
  <Button
    text="Show Dialog"
    onPress={() => {
      this.dialogComponent.show();
    }}
  />
  <DialogComponent
    ref={(dialogComponent) => { this.dialogComponent = dialogComponent; }}
    dialogAnimation = { new SlideAnimation({ slideFrom: 'bottom' }) }
  >
    <View>
      <Text>Hello</Text>
    </View>
  </DialogComponent>
</View>

Usage - With Dialog Dialog Title

import { DialogComponent, DialogTitle } from 'react-native-dialog-component';

<View style={styles.container}>
  <Button
    text="Show Dialog"
    onPress={() => {
      this.dialogComponent.show();
    }}
  />
  <DialogComponent
    dialogTitle={<DialogTitle title="Dialog Title" />}
    ref={(dialogComponent) => { this.dialogComponent = dialogComponent; }}
  >
    <View>
      <Text>Hello</Text>
    </View>
  </DialogComponent>
</View>

Usage - Wrape the content use DialogContent

import { DialogComponent, DialogTitle } from 'react-native-dialog-component';

<View style={styles.container}>
  <Button
    text="Show Dialog"
    onPress={() => {
      this.dialogComponent.show();
    }}
  />
  <DialogComponent
    dialogTitle={<DialogTitle title="Dialog Title" />}
    ref={(dialogComponent) => { this.dialogComponent = dialogComponent; }}
  >
    <DialogContent>
      <View>
        <Text>Hello</Text>
      </View>
    </DialogContent>
  </DialogComponent>
</View>

Props

DialogComponent

PropTypeDefaultNote
dialogTitleReact ElementYou can pass a DialogTitle component or pass a View for customizing titlebar
widthNumberYour device widthThe Width of Dialog, you can use fixed width or use percentage
heightNumber300The Width of Dialog, you can use fixed height or use percentage
dialogAnimationFadeAnimationanimation for dialog
dialogStyleObject or Number
animationDurationNumber200
overlayPointerEventsStringAvailable option: auto, none
overlayBackgroundColorString#000
overlayOpacityNumber0.5
dismissOnTouchOutsideBooltrueWhen touch overlay will close dialog, but if haveOverlay is false then the dismissOnTouchOutside won't work
dismissOnHardwareBackPressBooltrueOnly for Android
haveOverlayBooltrueIf false won't show overlay when dialog show
showBoolfalse
onShownFunctionYou can pass onShown function as a aallback function, will call the function while dialog shown
onDismissedFunctionYou can pass onDismissed function as a callback function, will call the function while dialog dismissed
actionsArrayArray of DialogButton component for example: [<DialogButton text="DISMISS", align="center" onPress={this.dismissDialog}/>]

DialogContent

PropTypeDefaultNote
contentStyleDialog's content container

DialogTitle

PropTypeDefaultNote
titleString
titleStyleObject or Number
titleTextStyleObject or Number
titleAlignStringcenter
haveTitleBarBooltrue

DialogButton

PropTypeDefaultNote
textString
alignStringcenterThe position of the button. Available option: left, center, right
onPressFunction
buttonStyleObject or Number
textStyleObject or Number
textContainerStyleObject or Number
disabledBooleanfalse
activeOpacityNumber

Animation

Params for (*)Animation

FadeAnimation

ParamTypeDefaultNote
toValueNumber0
animationDurationNumber150

ScaleAnimation

ParamTypeDefaultNote
toValueNumber0

SlideAnimation

ParamTypeDefaultNote
toValueNumber0
slideFromStringbottomAvailable option: top, bottom, left, right