GithubHelp home page GithubHelp logo

sewinter / react-native-modal-selector Goto Github PK

View Code? Open in Web Editor NEW

This project forked from peacechen/react-native-modal-selector

0.0 1.0 0.0 1.19 MB

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

License: MIT License

JavaScript 61.17% Python 8.89% Java 7.25% Objective-C 22.69%

react-native-modal-selector's Introduction

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', accessibilityLabel: 'Tap here for 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']}
                    accessible={true}
                    scrollViewAccessibilityLabel={'Scrollable options'}
                    cancelButtonAccessibilityLabel={'Cancel Button'}
                    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

Prop Type Optional Default Description
data array No [] array of objects with a unique key and label to select in the modal.
onChange function Yes () => {} callback function, when the users has selected an option
initValue string Yes Select me! text that is initially shown on the button
cancelText string Yes cancel text of the cancel button
animationType string Yes slide type of animation to be used to show the modal. Must be one of none, slide or fade.
disabled bool Yes false true disables opening of the modal
supportedOrientations ['portrait', 'landscape'] Yes both orientations the modal supports
keyboardShouldPersistTaps string / bool Yes always passed to underlying ScrollView
style object Yes style 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.
selectTextStyle object Yes {} style definitions for the select element (available in default mode only!)
overlayStyle object Yes { 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.
sectionStyle object Yes {} style definitions for the section element
sectionTextStyle object Yes {} style definitions for the select text element
optionStyle object Yes {} style definitions for the option element
optionTextStyle object Yes {} style definitions for the option text element
optionContainerStyle object Yes {} style definitions for the option container element
cancelStyle object Yes {} style definitions for the cancel element
cancelTextStyle object Yes {} style definitions for the cancel text element
cancelContainerStyle object Yes {} style definitions for the cancel container
backdropPressToClose bool Yes false true makes the modal close when the overlay is pressed
accessible bool Yes false true enables accessibility for modal and options. Note: data items should have an accessibilityLabel property if this is enabled
scrollViewAccessibilityLabel string Yes undefined Accessibility label for the modal ScrollView
cancelButtonAccessibilityLabel string Yes undefined Accessibility label for the cancel button

react-native-modal-selector's People

Contributors

annieday avatar antonsivogrivov avatar b3ni avatar changedlater avatar chriscohoat avatar d-a-n avatar fabriziomoscon avatar flyingace avatar kilihorse avatar mienaikoe avatar mvanroon avatar peacechen avatar rajkissu avatar sewinter avatar terohotti avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.