1.1.4 • Published 6 years ago

react-native-button-modal v1.1.4

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

ButtonModal

Demo (source code in example file)

Alt Text

Installation

If react-native-vector-icons and native-base haven't been installed already, use the following:

$ npm install native-base --save
$ npm install react-native-vector-icons --save
$ npm install react-native-button-modal --save

If both have been installed, use the following:

$ npm install react-native-button-modal --save

Usage

Import the ModalButton

import ModalButton from 'react-native-modal-button';

Initialize the state variables (inside the constructor of the parent component)

constructor(props) {
    super(props);
    this.state = {
      displayPopup: false,
    };
 }

Create the ModalButton

<ButtonModal
    success={false}
    reference='popup'
    content={
        <Popup/>
    }
    buttonMessage={'Click here to display popup'}
    buttonType={'rectangle'}
    isVisible={this.state.displayPopup}
    showModal={() => this.setState({displayPopUp: true})}
    hideModal={() => this.setState({displayPopup: false})}
/>

Full Example

Initialize the state variables and the handler

import React, {Component} from 'react';
import {Button} from 'react-native';
import ModalButton from 'react-native-modal-button';

export default class ParentExample extends Component{
    constructor(props) {
        super(props);
        this.state = {
          counter: 0,
          modalSuccess: false,
          isModalVisible: false, //YOU MUST HAVE A STATE VARIABLE TO DECIDE MODAL VISIBILITY
        };
        this.updateCounter = this.updateCounter.bind(this)
    }

    updateCounter(){
    if(this.state.counter < 10){
      this.setState({
        counter: this.state.counter + 1,
      })
    }else{
      this.setState({
        counter: 10,
        modalSuccess: true, //the button will turn green after ten clicks
      })
    }
  }

    render(){
        return(
            <ButtonModal
                success={this.state.modalSuccess}
                content={
                    <Button onPress={this.updateCounter}></Button>
                }
                buttonMessage={'Click here to display popup'}
                buttonType={'rectangle'}
                isVisible={this.state.isModalVisible}
                showModal={() => this.setState({isModalVisible: true})} //OPENS THE MODAL
                hideModal={() => this.setState({isModalVisible: false})} //HIDES THE MODAL
            />
        );
    }
}
PropTypeDefault ValueDescription
isModalVisiblebooleanFALSEDecides if the modal will display
buttonTypeStringrectangleDecides the type of initial button to display (either 'rectangle' or 'icon')
iconNameStringrectangleReact Native Vector Icon name (can only be used if buttonType == 'icon')
buttonMessageStringClick hereThe message inside the initial button (can only be used if buttonType=='rectangle')
contentnodenullThe content to be displayed inside the modal
iconSizeint27Specifies the size of the icon
buttonTextSizeint15Font size of the text inside the initial button
confirmTextSizeint15Font size of the text inside the confirm button
allowClickintTRUEAllow the modal to be opened. If set to false, the initial button will grey out. If true, the initial button will be darker.
allowCloseintTRUEAllow the modal to be closed. If set to false, the confirm button will grey out. If true, the initial button will display dark blue.
successbooleanFALSEChanges the color of the initial button to green.
showModalfunctionnullSpecifies the function to open the modal
hideModalfunctionnullSpecifies the function to close the modal.
closeButtonTextStringConfirmMessage on close button.
disableConfirmBooleanFALSEDisable the confirm button, but allows the modal to be closed with the back arrow and swipe down.
hideConfirmButtonBooleanFALSEHide the confirm button.
openButtonBackgroundColorStringwhiteButton to open modal's background color
openButtonTextColorStringblackButton to open modal's text color
closeButtonBackgroundColorStringblueButton to close modal's background color
closeButtonTextColorStringblackButton to close modal's text color
1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago