Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed prop types dependency #77

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
95 changes: 49 additions & 46 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';

import React,{
PropTypes
} from 'react';
import React from 'react';
import PropTypes from 'prop-types';

import {
View,
Expand All @@ -12,7 +11,8 @@ import {
Text,
ScrollView,
TouchableOpacity,
Platform
Platform,
TouchableNativeFeedback
} from 'react-native';

import styles from './style';
Expand All @@ -38,7 +38,7 @@ const propTypes = {

const defaultProps = {
data: [],
onChange: ()=> {},
onChange: () => { },
initValue: 'Select me!',
style: {},
selectStyle: {},
Expand All @@ -51,7 +51,7 @@ const defaultProps = {
overlayStyle: {},
cancelText: 'cancel'
};

const Touchable = Platform.OS === 'android' ? TouchableNativeFeedback : TouchableOpacity;
export default class ModalPicker extends BaseComponent {

constructor() {
Expand All @@ -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 (
<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)}>
<Touchable 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>)
</Touchable>)
}

renderOptionList() {
Expand All @@ -129,28 +129,32 @@ export default class ModalPicker extends BaseComponent {
});

return (
<View style={[styles.overlayStyle, this.props.overlayStyle]} key={'modalPicker'+(componentIndex++)}>
<View style={styles.optionContainer}>
<ScrollView keyboardShouldPersistTaps>
<View style={{paddingHorizontal:10}}>
{options}
</View>
</ScrollView>
<Touchable
activeOpacity={1}
onPressOut={this.close}
>
<View style={[styles.overlayStyle, this.props.overlayStyle]} key={'modalPicker' + (componentIndex++)}>
<View style={styles.optionContainer}>
<ScrollView keyboardShouldPersistTaps="always">
<View style={{ paddingHorizontal: 10 }}>
{options}
</View>
</ScrollView>
</View>
<View style={styles.cancelContainer}>
<Touchable onPress={this.close}>
<View style={[styles.cancelStyle, this.props.cancelStyle]}>
<Text style={[styles.cancelTextStyle, this.props.cancelTextStyle]}>{this.props.cancelText}</Text>
</View>
</Touchable>
</View>
</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>
</View>
</TouchableOpacity>
</View>

</View>);
</Touchable>);
}

renderChildren() {

if(this.props.children) {
if (this.props.children) {
return this.props.children;
}
return (
Expand All @@ -161,19 +165,18 @@ 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 (
<View style={this.props.style}>
{dp}
<TouchableOpacity onPress={this.open}>
<Touchable onPress={this.open}>
{this.renderChildren()}
</TouchableOpacity>
</Touchable>
</View>
);
}
Expand Down