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

Overview

npm version

react-native-modal-picker

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

Demo

Install

npm i react-native-modal-picker --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 ModalPicker from 'react-native-modal-picker'

[..]

class SampleApp extends Component {

    constructor() {
        super();

        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' },
            { key: index++, label: 'Pink Grapefruit' },
            { key: index++, label: 'Raspberries' },
            { key: index++, section: true, label: 'Vegetables' },
            { key: index++, label: 'Beets' },
            { key: index++, label: 'Red Peppers' },
            { key: index++, label: 'Radishes' },
            { key: index++, label: 'Radicchio' },
            { key: index++, label: 'Red Onions' },
            { key: index++, label: 'Red Potatoes' },
            { key: index++, label: 'Rhubarb' },
            { key: index++, label: 'Tomatoes' }
        ];

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

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

                <ModalPicker
                    data={data}
                    initValue="Select something yummy!"
                    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} />
                        
                </ModalPicker>
            </View>
        );
    }
}

Props

  • data - [] required, array of objects with a unique key and label
  • style - object optional, style definitions for the root element
  • onChange - function optional, callback function, when the users has selected an option
  • initValue - string optional, text that is initially shown on the button
  • cancelText - string optional, text of the cancel button
  • selectStyle - object optional, style definitions for the select element (available in default mode only!)
  • selectTextStyle - object optional, style definitions for the select element (available in default mode only!)
  • overlayStyle - object optional, style definitions for the overly/background element
  • sectionStyle - object optional, style definitions for the section element
  • sectionTextStyle - object optional, style definitions for the select text element
  • optionStyle - object optional, style definitions for the option element
  • optionTextStyle - object optional, style definitions for the option text element
  • cancelStyle - object optional, style definitions for the cancel element
  • cancelTextStyle - object optional, style definitions for the cancel text element
Comments
  • Add value property

    Add value property

    By default data need to be formatted in this way:

                { key: index++,  label: 'Fruits' },
                { key: index++, label: 'Red Apples' },
                { key: index++, label: 'Cherries' },
                { key: index++, label: 'Cranberries' },
    

    I really need a value property like React Native Picker. For example input data will be:

                { key: index++,  label: 'Fruits', value: 'fruit1' },
                { key: index++, label: 'Red Apples', value: 'fruit5' },
                { key: index++, label: 'Cherries',value: 'fruit3'},
                { key: index++, label: 'Cranberries',value: 'fruit11' },
    

    How I can do this?

    opened by matteo-pennisi 2
  • Changed keyboardShouldPersistTaps from boolean prop to string

    Changed keyboardShouldPersistTaps from boolean prop to string

    Boolean keyboardShouldPersistTaps is deprecated, and is now a string prop with possible values "always", "handled", "never". See discussion in https://github.com/facebook/react-native/pull/10628

    opened by mikaello 2
  • Feature/fix touchable opacity styles

    Feature/fix touchable opacity styles

    This provides an ability to style the TouchableOpacity element as well as default styles to fix an issue in RN v0.36 .

    Also updated the SampleApp to that RN version and fixed the layout issues introduced by that.

    Let me know if you want me to change anything

    opened by IkeLutra 2
  • Getting the Red Screen of Death

    Getting the Red Screen of Death

    I ran react 0.14.8 and react-native 0.25.1. I also checked with the latest versions: react 15.0.2 and react-native 0.26.0.

    I copied and pasted the code of the README.md file of the github repository. And also cloned the rep and build it locally. Got the same result: Red Screen of Death.

    I also followed the steps in the Red Screen of Death but also no luck with it.

    I would appreciate any suggestions.

    screen shot 2016-05-21 at 23 33 23

    opened by orhanmaden 2
  • Update deprecations

    Update deprecations

    https://reactjs.org/blog/2017/04/07/react-v15.5.0.html In 15.5, instead of accessing PropTypes from the main React object, install the prop-types package and import them from there

    https://github.com/facebook/react-native/issues/13999 import ViewPropTypes from 'react-native' package like this: import {Text, View, ViewPropTypes} from 'react-native';

    https://reactjs.org/docs/react-component.html Note: These methods are considered legacy and you should avoid them in new code: UNSAFE_componentWillReceiveProps() https://reactjs.org/docs/react-component.html#static-getderivedstatefromprops static getDerivedStateFromProps(nextProps, prevState)

    https://facebook.github.io/react-native/docs/scrollview#keyboardshouldpersisttaps true, deprecated, use 'always' instead

    opened by BitterDone 1
  • fix PropTypes import for React 15.5

    fix PropTypes import for React 15.5

    As of react 15.5, PropTypes has moved to its own library. Also fixed a warning about keyboardShouldPersistTaps needing to be "always" rather than {true}.

    opened by ktownsend-cbre 1
  • Add optionContainerStyle prop

    Add optionContainerStyle prop

    I made this because I was asked to do this for the project I'm working on. I created this pull request so if you think it may add value to the project, you can merge it.

    opened by fcmatteo 1
  • Crashing in debug mode

    Crashing in debug mode

    The application crash and close when it's in debug mode without throwing any exception but it works fine without debugging. Does anybody know what's happening?

    opened by cosivox 1
  • Requiring unknown module rebound

    Requiring unknown module rebound

    Just trying to configure it locally, but the app fails to start because of

    "Requiring unknown module rebound"

    And actually it's really missing in the sources

    opened by undef1ned 1
  • Warnings when passing in custom styles

    Warnings when passing in custom styles

    When passing in a custom style like so:

    <ModalPicker
            data={this.state.data}
            selectStyle={Styles.SearchPage.selectorButton}
            selectTextStyle={Styles.SearchPage.labelBlackText}
            initValue="Select Category"
            cancelTextStyle={Styles.SearchPage.cancelTextStyle}
            optionTextStyle={Styles.SearchPage.optionTextStyle}
            optionStyle={Styles.SearchPage.optionStyle}
            cancelText="Cancel"
          />
    

    I'm getting these warnings:

    index.ios.bundle:58540Warning: Failed propType: Invalid props.optionTextStyle key `color` supplied to `ModalPicker`.
    Bad object: {
      "color": "black",
      "fontSize": 25
    }
    Valid keys: [
      "width",
      "height",
      "top",
      "left",
      "right",
      "bottom",
      "margin",
      "marginVertical",
      "marginHorizontal",
      "marginTop",
      "marginBottom",
      "marginLeft",
      "marginRight",
      "padding",
      "paddingVertical",
      "paddingHorizontal",
      "paddingTop",
      "paddingBottom",
      "paddingLeft",
      "paddingRight",
      "borderWidth",
      "borderTopWidth",
      "borderRightWidth",
      "borderBottomWidth",
      "borderLeftWidth",
      "position",
      "flexDirection",
      "flexWrap",
      "justifyContent",
      "alignItems",
      "alignSelf",
      "flex",
      "shadowColor",
      "shadowOffset",
      "shadowOpacity",
      "shadowRadius",
      "transform",
      "transformMatrix",
      "scaleX",
      "scaleY",
      "rotation",
      "translateX",
      "translateY",
      "backfaceVisibility",
      "backgroundColor",
      "borderColor",
      "borderTopColor",
      "borderRightColor",
      "borderBottomColor",
      "borderLeftColor",
      "borderRadius",
      "borderTopLeftRadius",
      "borderTopRightRadius",
      "borderBottomLeftRadius",
      "borderBottomRightRadius",
      "borderStyle",
      "opacity",
      "overflow",
      "elevation"
    ] Check the render method of `CategoryList`.
    
    opened by WilsonChiang 1
  • Warning: 'keyboardShouldPersistTaps={true}' is deprecated...

    Warning: 'keyboardShouldPersistTaps={true}' is deprecated...

    When the modal is opened, a warning is show...

    Warning: 'keyboardShouldPersistTaps={true}' is deprecated. Use 'keyboardShouldPersistTaps="always"' instead.

    Please correct. Thanks

    opened by ghost 0
  • Addition of multi-select feature.

    Addition of multi-select feature.

    • Added multi select option.
    • Added husky, making auto linting possible.
    • Upgraded RN to the latest version.

    PS: Messed up the previous PR so created a new one.

    opened by allroundexperts 0
  • some fixes required to align with React 15.5 and React-Native 0.44

    some fixes required to align with React 15.5 and React-Native 0.44

    React 15.5 moved PropTypes to its own module prop-types. React-Native 0.44 deprecated View.propTypes in favor of ViewPropTypes. ScrollView property keyboardShouldPersistTaps expects "always" value instead of implied value; currently just results in a warning.

    opened by ktownsend-cbre 1
  • Show saved item (when editing)

    Show saved item (when editing)

    Ok, the title might not be clear, let me try to explain.

    I have the modal picker with a key and label on a page. I am storing the key somewhere and when go to that same page again (to edit), I want to show the item I had stored. I know there is a initialValue, but like I mentioned I have stored the key and not the label.

    So have can I compare what I have stored and set the correct label as initialValue?

    Cheers,

    opened by udarts 0
Owner
Dan
Full Stack Developer
Dan
A cross-platform (iOS / Android), full-featured, highly customizable web browser module for React Native apps.

react-native-webbrowser A cross-platform (iOS / Android), full-featured in-app web browser component for React Native that is highly customizable. Cur

Dan 196 Nov 23, 2022
A React Native library provides Image blur shadows, highly customizable and mutable component. Supports Android, iOS and Web.

A React Native library provides Image Blur Shadows, highly customizable and mutable component. Supports Android, iOS and Web.

Vivek Verma 82 Dec 20, 2022
An awesome and cross-platform React Native date picker and calendar component for iOS and Android

react-native-common-date-picker An awesome and cross-platform React Native date picker and calendar component for iOS and Android. This package is des

chenlong 96 Jan 2, 2023
A react-native dropdown/picker/selector component for both Android & iOS.

react-native-modal-dropdown A react-native dropdown/picker/selector component for both Android & iOS. Features Pure JS. Compatible with both iOS and A

Rex Rao 1.2k Jan 1, 2023
react-native-wheel-picker ★190 - React native cross platform picker.

react-native-wheel-picker Introduction Cross platform Picker component based on React-native. Since picker is originally supported by ios while Androi

Yu Zheng (Sam) 308 Jan 1, 2023
Platform independent (Android / iOS) Selectbox | Picker | Multi-select | Multi-picker.

react-native-multi-selectbox Platform independent (Android / iOS) Selectbox | Picker | Multi-select | Multi-picker. The idea is to bring out the commo

Saurav Gupta 180 Jan 2, 2023
A cross-platform (iOS / Android) single and multiple-choice React Native component.

react-native-multiple-choice A cross-platform (iOS / Android) single and multiple-choice React Native component. Install npm i react-native-multiple-c

Dan 67 Sep 24, 2022
A Cross Platform(Android & iOS) ActionSheet with a flexible api, native performance and zero dependency code for react native. Create anything you want inside ActionSheet.

react-native-actions-sheet A highly customizable cross platform ActionSheet for react native. Screenshots Features Cross Platform (iOS and Android) Na

Ammar Ahmed 1000 Jan 9, 2023
react-native-wheel-picker-android ★186 - Simple and flexible React native wheel picker for Android, including DatePicker and TimePicker.

React native wheel picker V2 A simple Wheel Picker for Android (For IOs is using Picker from react-native) Example You can clone the repo and run exam

Kalon.Tech 336 Dec 15, 2022
React Native template for a quick start with React Navigation5 and TypeScript. It's cross-platform runs on Android, iOS, and the web.

对此项目的规划 出于兴趣把自己做 android、ios 开发过程中经验积累沉淀一下,此工程架构会定期更新升级依赖到最新版本,并不断的积累 App 中常用组件和基础页面功能,也会不断优化代码组织架构 此项目对以下情形会有帮助 想用前端技术做 app 开发却无从下手 想在项目中运用 typescrip

Benson 6 Dec 4, 2022
Cross Platform Material Alert and Prompt Dialogs for React Native. Imperative API, Android, IOS, Web

React Native Paper Alerts Cross Platform Material Alert and Prompt for React Native. It tries to follow the API and function signature of React Native

Arafat Zahan 13 Nov 21, 2022
react-native-select is a highly customizable dropdownlist for android and ios.

rect-native-select react-native-select is a highly customizable dropdownlist for android and ios.

null 3 Dec 21, 2021
A react native modals library. Swipeable. Highly customizable. Support multi modals & Support custom animation. For IOS & Android.

React Native Modals React Native Modals Library for iOS & Android. How to thank me ? Just click on ⭐️ button ?? Try it with Exponent BREAKING CHANGE A

Jack Lam 2.1k Dec 25, 2022
A android like toast for android and ios, android use native toast, ios use UIView+Toast

React Native Toast (remobile) A android like toast for react-native support for ios and android Installation npm install @remobile/react-native-toast

YunJiang.Fang 345 Nov 11, 2022
Smooth and fast cross platform Material Design date and time picker for React Native Paper

Smooth and fast cross platform Material Design date and time picker for React Native Paper

webRidge 432 Dec 27, 2022
react-native-select-dropdown is a highly customized dropdown | select | picker | menu for react native that works for andriod and iOS platforms.

react-native-select-dropdown react-native-select-dropdown is a highly customized dropdown | select | picker | menu for react native that works for and

Adel Reda 177 Jan 4, 2023
Picker is a cross-platform UI component for selecting an item from a list of options.

@react-native-picker/picker Android iOS PickerIOS Windows MacOS Supported Versions @react-native-picker/picker react-native react-native-windows >= 2.

null 1.1k Jan 9, 2023
A gesture password component for React Native. It supports both iOS and Android since it's written in pure JavaScript.

react-native-gesture-password A gesture password component for React Native (web). It supports both iOS, Android and Web since it's written in pure Ja

null 543 Dec 22, 2022