0.0.3 • Published 5 years ago

react-native-dropdownalert-click v0.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

react-native-dropdownalert

Platform npm version npm version Build Status codecov License

screenshot screenshot screenshot screenshot

Table of contents

  1. Support
  2. Installation
  3. Demo
  4. Usage
  5. Props
  6. Caveats

A simple alert to notify users about new chat messages, something went wrong or everything is ok. It can be closed by tap, cancel button, automatically with closeInterval, pan responder up gesture or programmatically.

Support

react-native versionpackage versionreason
0.50.0>=3.2.0Added SafeAreaView (iPhone X)
0.44.0>=2.12.0Added ViewPropTypes

Installation

npm i react-native-dropdownalert --save

Demo

screenshot

Usage

// ...
import DropdownAlert from 'react-native-dropdownalert';
export default class App extends Component {
  componentDidMount() {
    this.fetchData();
  }
  fetchData = async () => {
    try {
      await fetch('https://mywebsite.com/endpoint/');
    } catch (error) {
      this.dropdown.alertWithType('error', 'Error', error.message);
    }
  };
  render() {
    return (
      <View>
         // !!! Make sure it is the last component in your document tree.
        <DropdownAlert ref={ref => this.dropdown = ref} />
      </View>
    );
  }
}

Caveats

Props

NameTypeDescriptionDefault
closeIntervalNumberdismiss alert at a certain time in milliseconds4000
imageSrcString or Numberlocal or network source for custom alert typenull
infoImageSrcString or Numberlocal or network source for info alert typerequire('./assets/info.png')
warnImageSrcString or Numberlocal or network source for warn alert typerequire('./assets/warn.png')
errorImageSrcString or Numberlocal or network source for error alert typerequire('./assets/error.png')
successImageSrcString or Numberlocal or network source for success alert typerequire('./assets/success.png')
startDeltaNumberwhere the container starts (changes based on container height onLayout)-100
endDeltaNumberwhere the container ends0
onCloseFunctionInvoked when alert is closed Returns: data = {type, title, message, action}null
cancelBtnImageSrcString or Numberlocal or network sourcerequire('./assets/cancel.png')
titleNumOfLinesNumbernumber of lines1
messageNumOfLinesNumbernumber of lines3
onCancelFunctionCancel button action. Returns: data = {type, title, message, action}null
bashowCancelBoolwhether or not to show cancel buttonfalse
tapToCloseEnabledBoolenable/disable close with taptrue
panResponderEnabledBoolenable/disable close with pan respondertrue
replaceEnabledBoolenables the alert to either state change without dismissal or go to next alert with dismissaltrue
translucentBoolStatusBar propfalse
useNativeDriverBoolenable/disable native driver for animations. For android platform, in some older React Native versions, enable useNativeDriver can cause some problems. See #65true (iOS) / false (Android)
updateStatusBarBoolwhether or not to update status bar stylestrue
activeStatusBarStyleStringStatusBar barStyle when alert is openlight-content
activeStatusBarBackgroundColorStringStatusBar backgroundColor when alert is openIt takes on the backgroundColor of alert if predefined else default or provided prop
inactiveStatusBarStyleStringStatusBar barStyle when alert dismissesStatusBar._defaultProps.barStyle.value
inactiveStatusBarBackgroundColorStringStatusBar backgroundColor when alert dismissesStatusBar._defaultProps.backgroundColor.value
wrapperStyleObjectstyles for the view that wraps the container. For React Native Web support you might want to set this to { position: 'fixed' }null
containerStyleObjectstyles for container for custom type only{ padding: 16, flexDirection: 'row' }
zIndexNumberzIndex attribute on outermost containernull
titleStyleObjectstyles for title for all types{ fontSize: 16, textAlign: 'left', fontWeight: 'bold', color: 'white', backgroundColor: 'transparent' }
messageStyleObjectstyles for message for all types{ fontSize: 14, textAlign: 'left', fontWeight: 'bold', color: 'white', backgroundColor: 'transparent' }
imageStyleObjectstyles for image for all types{ padding: 8, width: 36, height: 36, alignSelf: 'center' }
cancelBtnImageStyleObjectstyles for image for all types{ padding: 8, width: 36, height: 36, alignSelf: 'center' }
successColorStringDefault background color of success message#32A54A
infoColorStringDefault background color of info message#2B73B6
warnColorStringDefault background color of warn message#cd853f
errorColorStringDefault background color of error message#cc3232
elevationNumberAnimated.View elevation1
sensitivityNumberSensitivity for the pan responder up gesture20
defaultContainerObjectStyle for inner view container (override paddingTop with this){ padding: 8, paddingTop: IS_ANDROID ? 0 : 20, flexDirection: 'row' }
defaultTextContainerObjectStyle for inner text container (holds title and message){ flex: 1, padding: 8 }
renderImageFunctionUse to override the left image componentundefined
renderCancelFunctionUse to override the cancel button componentundefined
renderTitleFunctionUse to override the title componentundefined
renderMessageFunctionUse to override the message componentundefined
testIDStringTop level TouchableOpacity's testIDundefined
accessibilityLabelStringTop level TouchableOpacity's accessibilityLabelundefined
accessibleBooleanTop level TouchableOpacity's accessiblefalse
titleTextPropsObjecttitle text props. does not override numOfLines (use titleNumOfLines)undefined
messageTextPropsObjectmessage text props. does not override numOfLines (use messageNumOfLines)undefined

Inspired by: RKDropdownAlert