/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @format */ 'use strict'; var React = require('react'); var ReactNative = require('react-native'); var { DatePickerAndroid, StyleSheet, Text, TouchableWithoutFeedback, } = ReactNative; var RNTesterBlock = require('./RNTesterBlock'); var RNTesterPage = require('./RNTesterPage'); class DatePickerAndroidExample extends React.Component { static title = 'DatePickerAndroid'; static description = 'Standard Android date picker dialog'; state = { presetDate: new Date(2020, 4, 5), simpleDate: new Date(2020, 4, 5), spinnerDate: new Date(2020, 4, 5), calendarDate: new Date(2020, 4, 5), defaultDate: new Date(2020, 4, 5), allDate: new Date(2020, 4, 5), simpleText: 'pick a date', spinnerText: 'pick a date', calendarText: 'pick a date', defaultText: 'pick a date', minText: 'pick a date, no earlier than today', maxText: 'pick a date, no later than today', presetText: 'pick a date, preset to 2020/5/5', allText: 'pick a date between 2020/5/1 and 2020/5/10', }; showPicker = async (stateKey, options) => { try { var newState = {}; const {action, year, month, day} = await DatePickerAndroid.open(options); if (action === DatePickerAndroid.dismissedAction) { newState[stateKey + 'Text'] = 'dismissed'; } else { var date = new Date(year, month, day); newState[stateKey + 'Text'] = date.toLocaleDateString(); newState[stateKey + 'Date'] = date; } this.setState(newState); } catch ({code, message}) { console.warn(`Error in example '${stateKey}': `, message); } }; render() { return ( {this.state.simpleText} {this.state.spinnerText} {this.state.calendarText} {this.state.defaultText} {this.state.presetText} {this.state.minText} {this.state.maxText} {this.state.allText} ); } } var styles = StyleSheet.create({ text: { color: 'black', }, }); module.exports = DatePickerAndroidExample;