React Native入门篇—react-native-datepicker的安装和使用

注意:未经允许不可私自转载,违者必究

React Native官方文档:https://reactnative.cn/docs/getting-started/

react-native-datepicker官方文档:https://github.com/xgfe/react-native-datepicker

项目地址GitHub地址:https://github.com/zhouwei1994/nativeCase.git

安装react-native-datepicker

在项目目录下cmd里面运行以下命令:

yarn add react-native-datepicker

没有安装yarn镜像的请看教程:https://blog.csdn.net/weixin_40614372/article/details/86154119

使用方法

import React, { Component } from 'react';
import { ScrollView, StyleSheet, Text, View } from 'react-native';
import DatePicker from 'react-native-datepicker';
class Home extends Component {
    static navigationOptions = {
        title: '日期/时间选择器',
    };
    constructor(props) {
        super(props);
        this.state = {
            date: "2016-05-15"
        }
    }
    render() {
        return (
            <ScrollView>
                <Text style={{ fontSize: 30 }}>DatePicker</Text>
                <DatePicker
                    style={{ width: 200 }}
                    date={this.state.date}
                    mode="date"
                    androidMode="spinner"
                    placeholder="选择日期"
                    format="YYYY-MM-DD"
                    confirmBtnText="确定"
                    cancelBtnText="取消"
                    showIcon={false}
                    minDate="2018-05-01"
                    maxDate="2019-06-01"
                    customStyles={{
                        dateIcon: {
                        },
                        dateInput: {
                            
                        }
                    }}
                    onDateChange={(date) => { this.setState({ date: date }) }}
                />
                <DatePicker
                    style={{ width: 200 }}
                    date={this.state.date}
                    mode="datetime"
                    placeholder="选择日期/时间"
                    androidMode="spinner"
                    format="YYYY-MM-DD HH:mm"
                    confirmBtnText="确定"
                    cancelBtnText="取消"
                    minDate="2018-05-01"
                    maxDate="2019-06-01"
                    customStyles={{
                        dateIcon: {
                            position: 'absolute',
                            left: 0,
                            top: 4,
                            marginLeft: 0
                        },
                        dateInput: {
                            marginLeft: 36
                        }
                    }}
                    minuteInterval={10}
                    onDateChange={(date) => { this.setState({ date: date }) }}
                />
            </ScrollView>
        );
    }
}
export default Home;
const styles = StyleSheet.create({

});

项目地址GitHub地址:https://github.com/zhouwei1994/nativeCase.git

注意:未经允许不可私自转载,违者必究

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值