最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
react-native DatePicker日期选择组件的实现代码
时间:2022-11-14 22:04:49 编辑:袖梨 来源:一聚教程网
本教程的实现效果如下:
为了实现其淡入/淡出的覆盖效果, 还有取消按钮, 在此用了一个三方的组件, 大家可以先安装一下:
三方组件的地址:https://github.com/eyaleizenberg/react-native-custom-action-sheet (可以看看,也可以直接按我的步骤走)
1. 在terminal的该工程目录下运行: npm install react-native-custom-action-sheet --save
2. 然后运行: npm start
3. 具体实现代码如下:
import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View, TouchableHighlight, DatePickerIOS } from 'react-native'; //这是一个三方组件 github地址:https://github.com/eyaleizenberg/react-native-custom-action-sheet var CustomActionSheet = require('react-native-custom-action-sheet'); class Demo extends Component { state = { datePickerModalVisible: false, //选择器显隐标记 chooseDate: new Date() //选择的日期 }; _showDatePicker () { //切换显隐标记 this.setState({datePickerModalVisible: !this.state.datePickerModalVisible}); }; _onDateChange (date) { //改变日期state alert(date); //弹出提示框: 显示你选择日期 this.setState({ chooseDate: date }); }; render() { let datePickerModal = ( //日期选择器组件 (根据标记赋值为 选择器 或 空) this.state.datePickerModalVisible ?this._showDatePicker()}> //点击取消按钮 触发事件 : null ); return (); } } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, datePickerContainer: { flex: 1, borderRadius: 5, justifyContent: 'center', alignItems: 'center', backgroundColor: 'white', marginBottom: 10, }, }); AppRegistry.registerComponent('Demo', () => Demo); this._showDatePicker()} //按钮: 点击触发方法 underlayColor='gray' > {datePickerModal} //日期选择组件show DatePick
相关文章
- 以闪亮之名曳梦捏脸数据id攻略 04-25
- 火影忍者手游忍具修行卡购买有什么 04-25
- 深空之眼铃兰之弦雅典娜技能怎么样 04-25
- 心动小镇咖啡伞如何获取 04-25
- 奇迹暖暖辉心圣歌有哪些玩法 04-25
- 崩坏3星火重燃灼烁打法配置指南 04-25