Gathering detailed insights and metrics for react-native-modal-selector
Gathering detailed insights and metrics for react-native-modal-selector
Gathering detailed insights and metrics for react-native-modal-selector
Gathering detailed insights and metrics for react-native-modal-selector
react-native-modal
An enhanced React Native modal
react-native-modal-datetime-picker
A react-native datetime-picker for Android and iOS
react-native-modal-selector-searchable
A cross-platform (iOS / Android), selector/picker component for React Native that is filterable, highly customizable and supports sections.
react-native-date-picker
A datetime picker for React Native. In-modal or inlined. Supports Android and iOS.
A cross-platform (iOS / Android), selector/picker component for React Native that is highly customizable and supports sections.
npm install react-native-modal-selector
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
368 Stars
175 Commits
129 Forks
9 Watching
2 Branches
3 Contributors
Updated on 23 Nov 2024
TypeScript (67.88%)
JavaScript (32.12%)
Cumulative downloads
Total Downloads
Last day
-4.8%
38,547
Compared to previous day
Last week
-0.5%
180,759
Compared to previous week
Last month
11.8%
779,025
Compared to previous month
Last year
31.1%
7,666,032
Compared to previous year
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.
1npm install react-native-modal-selector
You can either use this component in its default mode, as a wrapper around your existing component or provide a custom component (where you need to control opening of the modal yourself). In default mode a customizable button is rendered.
See SampleApp
for an example how to use this component.
1import ModalSelector from 'react-native-modal-selector' 2 3class SampleApp extends Component { 4 5 constructor(props) { 6 super(props); 7 8 this.state = { 9 textInputValue: '' 10 } 11 } 12 13 render() { 14 let index = 0; 15 const data = [ 16 { key: index++, section: true, label: 'Fruits' }, 17 { key: index++, label: 'Red Apples' }, 18 { key: index++, label: 'Cherries' }, 19 { key: index++, label: 'Cranberries', accessibilityLabel: 'Tap here for cranberries' }, 20 // etc... 21 // Can also add additional custom keys which are passed to the onChange callback 22 { key: index++, label: 'Vegetable', customKey: 'Not a fruit' } 23 ]; 24 25 return ( 26 <View style={{flex:1, justifyContent:'space-around', padding:50}}> 27 28 // Default mode 29 <ModalSelector 30 data={data} 31 initValue="Select something yummy!" 32 onChange={(option)=>{ alert(`${option.label} (${option.key}) nom nom nom`) }} /> 33 34 // Wrapper 35 <ModalSelector 36 data={data} 37 initValue="Select something yummy!" 38 supportedOrientations={['landscape']} 39 accessible={true} 40 scrollViewAccessibilityLabel={'Scrollable options'} 41 cancelButtonAccessibilityLabel={'Cancel Button'} 42 onChange={(option)=>{ this.setState({textInputValue:option.label})}}> 43 44 <TextInput 45 style={{borderWidth:1, borderColor:'#ccc', padding:10, height:30}} 46 editable={false} 47 placeholder="Select something yummy!" 48 value={this.state.textInputValue} /> 49 50 </ModalSelector> 51 52 // Custom component 53 <ModalSelector 54 data={data} 55 ref={selector => { this.selector = selector; }} 56 customSelector={<Switch onValueChange={() => this.selector.open()} />} 57 /> 58 </View> 59 ); 60 } 61}
The selector accepts a specific format of data:
1[{ key: 5, label: 'Red Apples' }]
Optionally provide a component
key which overrides the default label text. Optionally provide a unique testID
for each item:
1[{ 2 key: 5, 3 label: 'Red Apples', 4 // The next keys are optional -- 5 component: <View style={{backgroundColor: 'red'}}><Text style={{color: 'white'}}>Red Apples custom component ☺</Text></View>, 6 testID: '5-red-apples' 7}]
If your data has a specific format, you can define extractors of data, example:
1this.setState({data: [{ id: 5, name: 'Red Apples' }]}); 2 3return ( 4 <ModalSelector 5 data={this.state.data} 6 keyExtractor= {item => item.id} 7 labelExtractor= {item => item.name} 8 /> 9);
Prop | Type | Optional | Default | Description |
---|---|---|---|---|
data | array | No | [] | array of objects with a unique key and label to select in the modal. Optional component overrides label text. Optional unique testID for each item. |
onChange | function | Yes | () => {} | callback function, when the users has selected an option |
onModalOpen | function | Yes | () => {} | callback function, when modal is opening |
onModalClose | function | Yes | (item) => {} | callback function, when modal is closing. Returns the selected item. |
keyExtractor | function | Yes | (data) => data.key | extract the key from the data item |
labelExtractor | function | Yes | (data) => data.label | extract the label from the data item |
componentExtractor | function | Yes | (data) => data.component | extract the component from the data item |
visible | bool | Yes | false | control open/close state of modal |
closeOnChange | bool | Yes | true | control if modal closes on select |
initValue | string | Yes | Select me! | text that is initially shown on the button |
cancelText | string | Yes | cancel | text of the cancel button |
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 |
listType | string | Yes | SCROLLVIEW | scroller type: SCROLLVIEW or FLATLIST |
animationType | string | Yes | slide | type of animation to be used to show the modal. Must be one of none , slide or fade . |
style | object | Yes | style definitions for the root element | |
childrenContainerStyle | object | Yes | {} | style definitions for the children container view |
touchableStyle | object | Yes | {} | style definitions for the touchable element |
touchableActiveOpacity | number | Yes | 0.2 | opacity for the touchable element on touch |
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 |
selectedItemTextStyle | object | Yes | {} | style definitions for the currently selected 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 |
initValueTextStyle | object | Yes | {} | style definitions for the initValue 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 |
passThruProps | object | Yes | {} | props to pass through to the container View and each option TouchableOpacity (e.g. testID for testing) |
selectTextPassThruProps | object | Yes | {} | props to pass through to the select text component |
optionTextPassThruProps | object | Yes | {} | props to pass through to the options text components in the modal |
cancelTextPassThruProps | object | Yes | {} | props to pass through to the cancel text components in the modal |
scrollViewPassThruProps | object | Yes | {} | props to pass through to the internal ScrollView |
openButtonContainerAccessible | bool | Yes | false | true enables accessibility for the open button container. Note: if false be sure to define accessibility props directly in the wrapped component. |
listItemAccessible | bool | Yes | false | true enables accessibility for data items. Note: data items should have an accessibilityLabel property if this is enabled |
cancelButtonAccessible | bool | Yes | false | true enables accessibility for cancel button. |
scrollViewAccessible | bool | Yes | false | true enables accessibility for the scroll view. Only enable this if you don't want to interact with individual data items. |
scrollViewAccessibilityLabel | string | Yes | undefined | Accessibility label for the modal ScrollView |
cancelButtonAccessibilityLabel | string | Yes | undefined | Accessibility label for the cancel button |
modalOpenerHitSlop | object | Yes | {} | How far touch can stray away from touchable that opens modal (RN docs) |
customSelector | node | Yes | undefined | Render a custom node instead of the built-in select box. |
selectedKey | any | Yes | '' | Key of the item to be initially selected |
enableShortPress | bool | Yes | true | enables short press. This is regular touch behavior. |
enableLongPress | bool | Yes | false | enables long press. When true, onModalOpen returns {longPress: true} |
optionsTestIDPrefix | string | Yes | 'default' | This prefixes each selectable option's testID prop if no testID keys are provided in props.data array objects. Default for each option's testID: 'default-<optionLabel>' |
header | node | Yes | undefined | Render a header above the list |
onEndReached | function | Yes | undefined | Called once when the scroll position gets of the rendered content. |
open()
: open the modal.close()
: close the modal.getSelectedItem()
: get current selected item, updated by onChange event.No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 9/30 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More