SelectTime.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import React, { Component } from 'react'
  2. import {
  3. StyleSheet,
  4. View,
  5. Dimensions,
  6. PixelRatio,
  7. TouchableOpacity,
  8. Text,
  9. DatePickerIOS,
  10. } from 'react-native'
  11. import ModalEcx from '../../components/Modal'
  12. import moment from 'moment'
  13. const { width, height } = Dimensions.get('window')
  14. // @connect(({ theme }) => ({ ...theme }))
  15. class SelectTime extends Component {
  16. constructor(props) {
  17. super(props)
  18. this.state = {
  19. //动态state
  20. date: new Date(),
  21. timeZoneOffsetInHours: -1 * new Date().getTimezoneOffset(),
  22. time: '',
  23. mark: '',
  24. }
  25. }
  26. _closeModal() {
  27. this.showTime._setModalVisible(false)
  28. }
  29. _openModal = va => {
  30. this.showTime._setModalVisible(true)
  31. this.setState({ mark: va })
  32. }
  33. _renderModalContent() {
  34. return (
  35. <View
  36. style={{
  37. width: width,
  38. backgroundColor: '#FFF',
  39. alignSelf: 'center',
  40. borderRadius: 8,
  41. }}
  42. >
  43. <View
  44. style={{
  45. flexDirection: 'row',
  46. justifyContent: 'space-between',
  47. padding: 15,
  48. }}
  49. >
  50. <TouchableOpacity onPress={() => this._closeModal()}>
  51. <Text style={{ fontSize: 18, lineHeight: 22, color: '#333' }}>
  52. 取消
  53. </Text>
  54. </TouchableOpacity>
  55. <TouchableOpacity
  56. onPress={() => {
  57. this._closeModal()
  58. this.props.cb(this.state.time, this.state.mark)
  59. }}
  60. >
  61. <Text style={{ fontSize: 18, lineHeight: 22, color: '#333' }}>
  62. 确定
  63. </Text>
  64. </TouchableOpacity>
  65. </View>
  66. <DatePickerIOS
  67. date={this.state.date}
  68. // minimumDate={new Date()}
  69. mode="date"
  70. timeZoneOffsetInMinutes={this.state.timeZoneOffsetInHours}
  71. onDateChange={date => {
  72. this.setState({
  73. date: date,
  74. time: date,
  75. })
  76. // this.props.cb(date);
  77. }} //当内容改变的时候出发此函数
  78. />
  79. </View>
  80. )
  81. }
  82. render() {
  83. return (
  84. <ModalEcx
  85. ref={showTime => (this.showTime = showTime)}
  86. content={this._renderModalContent()}
  87. />
  88. )
  89. }
  90. }
  91. export default SelectTime