0.0.8 • Published 7 months ago

rn-snackbar-component v0.0.8

Weekly downloads
140
License
MIT
Repository
github
Last release
7 months ago

React Native SnackBar (rn-snackbar-component)

A snackbar component for Android and iOS, customizable and simple.

See Google Material Design for more info on Snackbars.

Installation

npm install --save rn-snackbar-component

Basic Usage

import SnackBar from 'rn-snackbar-component'

Code

Simple

<SnackBar
  visible={true}
  message="Hello There!"
  actionHandler={() => {
    console.log("snackbar button clicked!")
  }}
  action="let's go"
/>

Advanced

<SnackBar
  visible={true}
  message={(
      <View style={{ flex: 1, flexDirection: 'column'}}>
        <Text>{title}</Text>
        <TouchableOpacity activeOpacity={0.5} onPress={doSomething}>
          <Text>{subtitle}</Text>
        </TouchableOpacity>
      </View>
  )}
  actionHandler={() => {
    console.log("snackbar button clicked!")
  }}
  action={(
    <Icon name="close" size={20} />
  )}
  autoHidingTime={0}
/>

Options

PropTypeEffectDefault Value
visiblebooleanShow or hide the snackbarnone
messagestring / elementThe main message text / your custom componentnone
actionHandlerfunctionFunction to be called when button is pressed, if absent no action button is shownnone
actionstring / elementThe text of action button, will be uppercased automatically / your custom componentnone
containerStyleViewStyleThe styling of snackbar containernone
actionTextStyleTextStyleaction button text style{ color: 'orange'}
actionContainerStyleViewStyleyour custom component for action's stylenone
messageStyleTextStyleThe style of message text{ color: '#ffffff'}
distanceCallbackfunctionFunction to be caled whenever snackbar moves in and out or changes layout, the function will be supplied a number indicating distance taken up by snackbar on bottom.(distance) => {}
bottomnumberThe starting bottom position of snackbar0
topnumberThe starting top position of snackbar0
positionstringThe position of the snackbar: top, bottombottom
autoHidingTimenumberHow many milliseconds the snackbar will be hidden0 (Do not hide automatically)
nativebooleanUsing native drivertrue

Note

  • When visible prop is changed, the snackbar will be animated in/out of screen
  • When position is top/bottom, you can specify those properties, e.g. position="top" top={10} (or) position="bottom" bottom={10}