{"size": 962, "ext": "js", "max_stars_repo_path": "src/DatePicker.ios.js", "max_stars_repo_name": "vuongductuanktmt/ReactNativeWheelPicker", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/DatePicker.ios.js", "max_issues_repo_name": "vuongductuanktmt/ReactNativeWheelPicker", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/DatePicker.ios.js", "max_forks_repo_name": "vuongductuanktmt/ReactNativeWheelPicker", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 19.6326530612, "max_line_length": 71, "alphanum_fraction": 0.6237006237}
/**
 * @prettier
 * @flow
 * */

import React from 'react'
import { StyleSheet, Dimensions } from 'react-native'
import DateTimePicker from '@react-native-community/datetimepicker';

type Props = {
  onDateSelected: Date => void,
  date: Date
}

type State = {
  chosenDate: Date
}

export default class DatePicker extends React.Component<Props, State> {
  constructor(props: Props){
    super(props)
    this.state = { chosenDate: props.date || new Date() }
  }

  setDate = (event, newDate) => {
    this.setState({chosenDate: newDate})
    const { onDateSelected } = this.props
    if (onDateSelected) onDateSelected(newDate)
  }

  render(){
    return (
        <DateTimePicker
          display="spinner"
          {...this.props}
          style={styles.picker}
          value={this.state.chosenDate}
          onChange={this.setDate}
        />
    )
  }
}

let styles = StyleSheet.create({
  picker: {
    width: Dimensions.get('screen').width
  },
})
