Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea
npm-debug.log
node_modules

# vim
*.sw*
51 changes: 27 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

import React,{
PropTypes
} from 'react';
import React from 'react';

import {
View,
Expand All @@ -15,6 +13,8 @@ import {
Platform
} from 'react-native';

import PropTypes from 'prop-types';

import styles from './style';
import BaseComponent from './BaseComponent';

Expand All @@ -38,7 +38,8 @@ const propTypes = {

const defaultProps = {
data: [],
onChange: ()=> {},
onChange: () => {
},
initValue: 'Select me!',
style: {},
selectStyle: {},
Expand Down Expand Up @@ -79,9 +80,9 @@ export default class ModalPicker extends BaseComponent {
}

componentWillReceiveProps(nextProps) {
if (nextProps.initValue != this.props.initValue) {
this.setState({selected: nextProps.initValue});
}
if (nextProps.initValue != this.props.initValue) {
this.setState({selected: nextProps.initValue});
}
}

onChange(item) {
Expand All @@ -91,30 +92,30 @@ export default class ModalPicker extends BaseComponent {
}

close() {
this.setState({
modalVisible: false
});
this.setState({
modalVisible: false
});
}

open() {
this.setState({
modalVisible: true
});
this.setState({
modalVisible: true
});
}

renderSection(section) {
return (
<View key={section.key} style={[styles.sectionStyle,this.props.sectionStyle]}>
<Text style={[styles.sectionTextStyle,this.props.sectionTextStyle]}>{section.label}</Text>
<View key={section.key} style={[styles.sectionStyle, this.props.sectionStyle]}>
<Text style={[styles.sectionTextStyle, this.props.sectionTextStyle]}>{section.label}</Text>
</View>
);
}

renderOption(option) {
return (
<TouchableOpacity key={option.key} onPress={()=>this.onChange(option)}>
<TouchableOpacity key={option.key} onPress={() => this.onChange(option)}>
<View style={[styles.optionStyle, this.props.optionStyle]}>
<Text style={[styles.optionTextStyle,this.props.optionTextStyle]}>{option.label}</Text>
<Text style={[styles.optionTextStyle, this.props.optionTextStyle]}>{option.label}</Text>
</View>
</TouchableOpacity>)
}
Expand All @@ -129,18 +130,19 @@ export default class ModalPicker extends BaseComponent {
});

return (
<View style={[styles.overlayStyle, this.props.overlayStyle]} key={'modalPicker'+(componentIndex++)}>
<View style={[styles.overlayStyle, this.props.overlayStyle]} key={'modalPicker' + (componentIndex++)}>
<View style={styles.optionContainer}>
<ScrollView keyboardShouldPersistTaps>
<View style={{paddingHorizontal:10}}>
<View style={{paddingHorizontal: 10}}>
{options}
</View>
</ScrollView>
</View>
<View style={styles.cancelContainer}>
<TouchableOpacity onPress={this.close}>
<View style={[styles.cancelStyle, this.props.cancelStyle]}>
<Text style={[styles.cancelTextStyle,this.props.cancelTextStyle]}>{this.props.cancelText}</Text>
<Text
style={[styles.cancelTextStyle, this.props.cancelTextStyle]}>{this.props.cancelText}</Text>
</View>
</TouchableOpacity>
</View>
Expand All @@ -150,7 +152,7 @@ export default class ModalPicker extends BaseComponent {

renderChildren() {

if(this.props.children) {
if (this.props.children) {
return this.props.children;
}
return (
Expand All @@ -163,9 +165,10 @@ export default class ModalPicker extends BaseComponent {
render() {

const dp = (
<Modal transparent={true} ref="modal" visible={this.state.modalVisible} onRequestClose={this.close} animationType={this.state.animationType}>
{this.renderOptionList()}
</Modal>
<Modal transparent={true} ref="modal" visible={this.state.modalVisible} onRequestClose={this.close}
animationType={this.state.animationType}>
{this.renderOptionList()}
</Modal>
);

return (
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"type": "git",
"url": "https://github.com/d-a-n/react-native-modal-picker.git"
},
"dependencies": {
"react": "^16.0.0-alpha.12",
"prop-types": "^15.6.0"
},
"keywords": [
"react-native",
"dropdown",
Expand Down