react native 中时间选择插件

npm install react-native-datepicker --save
import DatePicker from 'react-native-datepicker';

<View>
<DatePicker
style={{width: 200}}
date={this.state.date}
mode="date"
placeholder="select date"
format="YYYY-MM-DD"
minDate={this.state.date}
confirmBtnText="Confirm"
cancelBtnText="Cancel"
customStyles={{
dateIcon: {
position: 'absolute',
left: 0,
top: 8/1536*width,
marginLeft: 0
},
dateInput: {
marginLeft: 72/1536*width,
borderRadius:10/1536*width
}
// ... You can check the source to find the other keys.
}}
onDateChange={(date) => {
this.setState({date: date});
this.load();
}}
/>
</View>

注意:这里的date类型是string,所以date类型初始化的时候需要tostring,例如moment(new Date()).format(‘YYYY-MM-DD’)

Properties

PropDefaultTypeDescription
style-objectSpecify the style of the DatePicker, eg. width, height...
date-string | date | Moment instanceSpecify the display date of DatePicker. string type value must match the specified format
mode'date'enumThe enum of datedatetime and time
androidMode'default'enumThe enum of defaultcalendar and spinner (only Android)
format'YYYY-MM-DD'stringSpecify the display format of the date, which using moment.js. The default value change according to the mode.
confirmBtnText'确定'stringSpecify the text of confirm btn in ios.
cancelBtnText'取消'stringSpecify the text of cancel btn in ios.
iconSource-{uri: string} | numberSpecify the icon. Same as the sourceof Image, always using require()
minDate-string | dateRestricts the range of possible date values.
maxDate-string | dateRestricts the range of possible date values.
duration300numberSpecify the animation duration of datepicker.
customStyles-objectThe hook of customize datepicker style, same as the native style. dateTouchBodydateInput...
showIcontruebooleanController whether or not show the icon
hideTextfalsebooleanController whether or not show the dateText
iconComponent-elementSet the custom icon
disabledfalsebooleanController whether or not disable the picker
is24Hour-booleanSet the TimePicker is24Hour flag. The default value depend on format. Only work in Android
allowFontScalingtruebooleanSet to false to disable font scaling for every text component
placeholder''stringThe placeholder show when this.props.date is falsy
onDateChange-functionThis is called when the user confirm the picked date or time in the UI. The first and only argument is a date or time string representing the new date and time formatted by moment.js with the given format property.
onOpenModal-functionThis is called when the DatePicker Modal open.
onCloseModal-functionThis is called when the DatePicker Modal close
onPressMask-functionThis is called when clicking the ios modal mask
modalOnResponderTerminationRequest-functionSet the callback for React Native's Gesture Responder System's call to onResponderTerminationRequest. By default this will reject a termination request, but can be overidden in case the View under the Modal is implementing custom gesture responders, and you wish for those to be overidden in certain cases.
TouchableComponentTouchableHighlightComponentReplace the TouchableHighlight with a custom Component. For example : TouchableOpacity
getDateStr-FunctionA function to override how to format the date into a String for display, receives a Date instance

转载于:https://www.cnblogs.com/yuxingxingstar/p/9817874.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值