Skip to content

Commit

Permalink
feat(datepicker): add support for custom styles with customStyles pro…
Browse files Browse the repository at this point in the history
…perty
  • Loading branch information
feyy committed May 6, 2016
1 parent 7ffbe43 commit cb254e4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ You can check [index.js](https://github.com/xgfe/react-native-datepicker/blob/ma
| date | - | `string | date` | Specify the display date of DatePicker. `string` type value must match the specified format |
| mode | 'date' | `enum` | The `enum` of `date`, `datetime` and `time` |
| format | 'YYYY-MM-DD' | `string` | Specify the display format of the date, which using [moment.js](http://momentjs.com/). The default value change according to the mode. |
| confirmBtnText | - | `string` | Specify the text of confirm btn in ios. |
| cancelBtnText | - | `string` | Specify the text of cancel btn in ios. |
| confirmBtnText | '确定' | `string` | Specify the text of confirm btn in ios. |
| cancelBtnText | '取消' | `string` | Specify the text of cancel btn in ios. |
| iconSource | - | `{uri: string} | number` | Specify the icon. Same as the `source` of Image, always using `require()` |
| minDate | - | `string | date` | Restricts the range of possible date values. |
| maxDate | - | `string | date` | Restricts the range of possible date values. |
| duration | 300 | `number` | Specify the animation duration of datepicker.
| duration | 300 | `number` | Specify the animation duration of datepicker.|
| customStyles | - | `number` | The hook of customize datepicker style, same as the native style. `dateTouchBody`, `dateInput`...|

## Methods

Expand Down
22 changes: 12 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class DatePicker extends Component {
cancelBtnText = this.props.cancelBtnText || '取消';

iconSource = this.props.iconSource || require('./date_icon.png');
customStyles = this.props.customStyles || {};

state = {
date: this.getDate(),
Expand Down Expand Up @@ -201,12 +202,12 @@ class DatePicker extends Component {
underlayColor={'transparent'}
onPress={this.onPressDate}
>
<View style={Style.dateTouchBody}>
<View style={[Style.dateInput, this.state.disabled && Style.disabled]}>
<Text style={Style.dateText}>{this.getDateStr()}</Text>
<View style={[Style.dateTouchBody, this.customStyles.dateTouchBody]}>
<View style={[Style.dateInput, this.customStyles.dateInput, this.state.disabled && Style.disabled]}>
<Text style={[Style.dateText, this.customStyles.dateText]}>{this.getDateStr()}</Text>
</View>
<Image
style={Style.dateIcon}
style={[Style.dateIcon, this.customStyles.dateIcon]}
source={this.iconSource}
/>
{Platform.OS === 'ios' && <Modal
Expand All @@ -216,34 +217,35 @@ class DatePicker extends Component {
>
<TouchableHighlight
style={Style.datePickerMask}
activeOpacity={1}
underlayColor={'#00000077'}
onPress={this.onPressCancel}
>
<TouchableHighlight
underlayColor={'#fff'}
>
<Animated.View style={[Style.datePickerCon, {height: this.state.animatedHeight}]}>
<Animated.View style={[Style.datePickerCon, {height: this.state.animatedHeight}, this.customStyles.datePickerCon]}>
<DatePickerIOS
date={this.state.date}
mode={this.mode}
minimumDate={this.props.minDate && this.getDate(this.props.minDate)}
maximumDate={this.props.maxDate && this.getDate(this.props.maxDate)}
onDateChange={(date) => this.setState({date: date})}
style={Style.datePicker}
style={[Style.datePicker, this.customStyles.datePicker]}
/>
<TouchableHighlight
underlayColor={'transparent'}
onPress={this.onPressCancel}
style={[Style.btnText, Style.btnCancel]}
style={[Style.btnText, Style.btnCancel, this.customStyles.btnCancel]}
>
<Text style={[Style.btnTextText, Style.btnTextCancel]}>{this.cancelBtnText}</Text>
<Text style={[Style.btnTextText, Style.btnTextCancel, this.customStyles.btnTextCancel]}>{this.cancelBtnText}</Text>
</TouchableHighlight>
<TouchableHighlight
underlayColor={'transparent'}
onPress={this.onPressConfirm}
style={[Style.btnText, Style.btnConfirm]}
style={[Style.btnText, Style.btnConfirm, this.customStyles.btnConfirm]}
>
<Text style={Style.btnTextText}>{this.confirmBtnText}</Text>
<Text style={[Style.btnTextText, this.customStyles.btnTextConfirm]}>{this.confirmBtnText}</Text>
</TouchableHighlight>
</Animated.View>
</TouchableHighlight>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-datepicker",
"version": "1.0.3",
"version": "1.1.0",
"description": "react native datePicker component for both Android and IOS, useing DatePikcerAndroid, TimePickerAndroid and DatePickerIOS",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit cb254e4

Please sign in to comment.