diff --git a/index.js b/index.js index d65bf4c0..f08d45be 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,7 @@ 'use strict'; -import React,{ - PropTypes -} from 'react'; +import React from 'react'; +import PropTypes from 'prop-types'; import { View, @@ -12,7 +11,8 @@ import { Text, ScrollView, TouchableOpacity, - Platform + Platform, + TouchableNativeFeedback } from 'react-native'; import styles from './style'; @@ -38,7 +38,7 @@ const propTypes = { const defaultProps = { data: [], - onChange: ()=> {}, + onChange: () => { }, initValue: 'Select me!', style: {}, selectStyle: {}, @@ -51,7 +51,7 @@ const defaultProps = { overlayStyle: {}, cancelText: 'cancel' }; - +const Touchable = Platform.OS === 'android' ? TouchableNativeFeedback : TouchableOpacity; export default class ModalPicker extends BaseComponent { constructor() { @@ -74,49 +74,49 @@ export default class ModalPicker extends BaseComponent { } componentDidMount() { - this.setState({selected: this.props.initValue}); - this.setState({cancelText: this.props.cancelText}); + this.setState({ selected: this.props.initValue }); + this.setState({ cancelText: this.props.cancelText }); } 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) { this.props.onChange(item); - this.setState({selected: item.label}); + this.setState({ selected: item.label }); this.close(); } close() { - this.setState({ - modalVisible: false - }); + this.setState({ + modalVisible: false + }); } open() { - this.setState({ - modalVisible: true - }); + this.setState({ + modalVisible: true + }); } renderSection(section) { return ( - - {section.label} + + {section.label} ); } renderOption(option) { return ( - this.onChange(option)}> + this.onChange(option)}> - {option.label} + {option.label} - ) + ) } renderOptionList() { @@ -129,28 +129,32 @@ export default class ModalPicker extends BaseComponent { }); return ( - - - - - {options} - - + + + + + + {options} + + + + + + + {this.props.cancelText} + + + - - - - {this.props.cancelText} - - - - - ); + ); } renderChildren() { - if(this.props.children) { + if (this.props.children) { return this.props.children; } return ( @@ -161,19 +165,18 @@ export default class ModalPicker extends BaseComponent { } render() { - const dp = ( - - {this.renderOptionList()} - + + {this.renderOptionList()} + ); return ( {dp} - + {this.renderChildren()} - + ); }