forked from henninghall/react-native-date-picker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatePickerIOS.js
63 lines (57 loc) · 1.79 KB
/
DatePickerIOS.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import React from 'react'
import { StyleSheet, View, requireNativeComponent } from 'react-native'
import { throwIfInvalidProps } from './propChecker'
const RCTDatePickerIOS = requireNativeComponent('RNDatePicker')
export default class DatePickerIOS extends React.Component {
_picker = null
componentDidUpdate() {
if (this.props.date) {
const propsTimeStamp = this.props.date.getTime()
if (this._picker) {
this._picker.setNativeProps({
date: propsTimeStamp,
})
}
}
}
_onChange = event => {
const nativeTimeStamp = event.nativeEvent.timestamp
this.props.onDateChange &&
this.props.onDateChange(new Date(nativeTimeStamp))
}
render() {
const props = this.props
if (__DEV__) throwIfInvalidProps(props)
return (
<RCTDatePickerIOS
testID={this.props.testID}
key={this.props.textColor} // preventing "Today" string keep old text color when text color changes
ref={picker => {
this._picker = picker
}}
style={[styles.datePickerIOS, props.style]}
date={props.date ? props.date.getTime() : undefined}
locale={props.locale ? props.locale : undefined}
maximumDate={
props.maximumDate ? props.maximumDate.getTime() : undefined
}
minimumDate={
props.minimumDate ? props.minimumDate.getTime() : undefined
}
mode={props.mode}
minuteInterval={props.minuteInterval}
timeZoneOffsetInMinutes={props.timeZoneOffsetInMinutes}
onChange={this._onChange}
onStartShouldSetResponder={() => true}
onResponderTerminationRequest={() => false}
textColor={props.textColor}
/>
)
}
}
const styles = StyleSheet.create({
datePickerIOS: {
height: 216,
width: 310,
},
})