react native中有关日期的组件DatePicker 示例
1.用node加载react-native-datepicker包
npm install react-native-datepicker
2.直接上代码
import React, { PureComponent } from 'react';
import DatePicker from 'react-native-datepicker';
class MyDatePicker extends PureComponent {
constructor(props) {
super(props);
this.state = {
data:new Date() //默认显示当前时间,如果为自定义则为('1991-1-1')
};
}
render() {
return (
<DatePicker
style={{ width: 50, justifyContent: 'center', alignItems: 'center' }}
date={this.state.data}
mode="date"
confirmBtnText="Confirm"
cancelBtnText="Cancel"
iconSource={require('./../image/calendar.png')} //自定义图标
customStyles={{
}}
hideText={true} //不显示日期文本
onDateChange={(datetime) => { this.props.storq.datetimeFun(datetime); }}
/>
);
}
}
export default MyDatePicker;
3.在另一个文件中引用