You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

react-native-modal-selector

Package Overview
Dependencies
Maintainers
2
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-modal-selector

A cross-platform (iOS / Android), selector/picker component for React Native that is highly customizable and supports sections.

0.0.23
Source
npmnpm
Version published
Weekly downloads
145K
7.43%
Maintainers
2
Weekly downloads
 
Created
Source

react-native-modal-selector npm version

A cross-platform (iOS / Android), selector/picker component for React Native that is highly customizable and supports sections.

This project is the official continuation of the abandoned react-native-modal-picker repo. Contributors are welcome to request a promotion to collaborator status.

Demo

Install

npm i react-native-modal-selector --save

Usage

You can either use this component as an wrapper around your existing component or use it in its default mode. In default mode a customizable button is rendered.

See SampleApp for an example how to use this component.


import ModalSelector from 'react-native-modal-selector'

class SampleApp extends Component {

    constructor(props) {
        super(props);

        this.state = {
            textInputValue: ''
        }
    }

    render() {
        let index = 0;
        const data = [
            { key: index++, section: true, label: 'Fruits' },
            { key: index++, label: 'Red Apples' },
            { key: index++, label: 'Cherries' },
            { key: index++, label: 'Cranberries' },
            // etc...
            // Can also add additional custom keys which are passed to the onChange callback
            { key: index++, label: 'Vegetable', customKey: 'Not a fruit' }
        ];

        return (
            <View style={{flex:1, justifyContent:'space-around', padding:50}}>

                // Default mode
                <ModalSelector
                    data={data}
                    initValue="Select something yummy!"
                    onChange={(option)=>{ alert(`${option.label} (${option.key}) nom nom nom`) }} />

                // Wrapper
                <ModalSelector
                    data={data}
                    initValue="Select something yummy!"
                    supportedOrientations={['landscape']}
                    onChange={(option)=>{ this.setState({textInputValue:option.label})}}>

                    <TextInput
                        style={{borderWidth:1, borderColor:'#ccc', padding:10, height:30}}
                        editable={false}
                        placeholder="Select something yummy!"
                        value={this.state.textInputValue} />

                </ModalSelector>
            </View>
        );
    }
}

API

Props

PropTypeOptionalDefaultDescription
dataarrayNo[]array of objects with a unique key and label to select in the modal.
onChangefunctionYes() => {}callback function, when the users has selected an option
initValuestringYesSelect me!text that is initially shown on the button
cancelTextstringYescanceltext of the cancel button
animationTypestringYesslidetype of animation to be used to show the modal. Must be one of none, slide or fade.
disabledboolYesfalsetrue disables opening of the modal
supportedOrientations['portrait', 'landscape']Yesbothorientations the modal supports
keyboardShouldPersistTapsstring / boolYesalwayspassed to underlying ScrollView
styleobjectYesstyle definitions for the root element
selectStyle      object  Yes    {}        style definitions for the select element (available in default mode only!). NOTE: Due to breaking changes in React Native, RN < 0.39.0 should pass flex:1 explicitly to selectStyle as a prop.
selectTextStyleobjectYes{}style definitions for the select element (available in default mode only!)
overlayStyleobjectYes{ flex: 1, padding: '5%', justifyContent: 'center', backgroundColor: 'rgba(0,0,0,0.7)' }style definitions for the overlay background element. RN <= 0.41 should override this with pixel value for padding.
sectionStyleobjectYes{}style definitions for the section element
sectionTextStyleobjectYes{}style definitions for the select text element
optionStyleobjectYes{}style definitions for the option element
optionTextStyleobjectYes{}style definitions for the option text element
optionContainerStyleobjectYes{}style definitions for the option container element
cancelStyleobjectYes{}style definitions for the cancel element
cancelTextStyleobjectYes{}style definitions for the cancel text element
backdropPressToCloseboolYesfalsetrue makes the modal close when the overlay is pressed

Keywords

react-native

FAQs

Package last updated on 25 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts