0.2.0 • Published 3 years ago

react-native-awesome-modal v0.2.0

Weekly downloads
96
License
MIT
Repository
github
Last release
3 years ago

react-native-awesome-modal

A flexible and reusable modal.

Install

 npm install react-native-awesome-modal --save

or

 yarn add react-native-awesome-modal

Usage

import {AwesomeModal} from 'react-native-awesome-modal'

const App: () => React$Node = () => {
  // Have to use the useRef hook to control the modal 
  // from the parent component
  const modalRef = useRef(null);
  return (
    <AwesomeModal
        enableScroll
        onClose={() => console.log('close')}
        onPressOutside={() => console.log('outside')}
        modalBottomMargin={0}
        modalRef={(ref) => {modalRef.current = ref}}
        modalContainerStyle={{
          width: "99%",
          maxHeight: 600,
          borderTopRightRadius: 20,
          borderTopLeftRadius: 20,
        }}
        modalOverlayStyle={{
          backgroundColor: 'grey'
        }}
      >
        // Place modal's content here as the component's child
        <Text>HELLO!</Text> 
        <TouchableOpacity onPress={() => modalRef.current.scrollToTop()} style={styles.buttonStyle}>
            <Text style={styles.buttonTextStyle}>Scroll to top</Text>
        </TouchableOpacity>
        <TouchableOpacity onPress={() => modalRef.current.close()} style={styles.buttonStyle}>
            <Text style={styles.buttonTextStyle}>Close Modal</Text>
        </TouchableOpacity>
    </AwesomeModal>
  )
};
.....

Props

The props below are used to configure and style the modal.

PropTypeOptionalDefaultDescription
enableScrollbooleanYesfalseContainer of the modal's content will be a ScrollView instead of a View if set to true.
hasTabBarbooleanYesfalseWhether the app has a tab bar (i.e. requires bottom padding for the modal)
overflowShowbooleanYesfalseWhether to show overflown elements.
closeOnPressOutsidebooleanYestrueWhether to close the modal on press outside of it
modalBottomMarginnumberYes45The bottom margin of modal.
isCenteredbooleanYesfalseWhether the modal is centered on the screen. The value supplied to modalBottomMargin will be ignored if isCentered is set to True.
onClose() => voidYesFunction to call when the modal closes.
onPressOutside() => voidYesFunction to call when the user presses outside of the modal.
modalContainerStyleStylePropYesSee awesome-modal.tsxThe modal's container style.
modalInnerContainerStyleStylePropYesSee awesome-modal.tsxThe modal's content container style.
modalOverlayStyleStylePropYesSee awesome-modal.tsxThe modal's overlay style (i.e the translucent overlay behind the modal).
modalRef(ref: AwesomeModalundefined) => voidYesThe modal's ref to control the modal from the parent component.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

0.2.0

3 years ago

0.1.0

3 years ago

0.1.1

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.1

3 years ago