/** * Copyright (c) 2015-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @providesModule TimePickerAndroidExample */ 'use strict'; var React = require('react'); var ReactNative = require('react-native'); var { TimePickerAndroid, StyleSheet, Text, TouchableWithoutFeedback, } = ReactNative; var RNTesterBlock = require('./RNTesterBlock'); var RNTesterPage = require('./RNTesterPage'); class TimePickerAndroidExample extends React.Component { static title = 'TimePickerAndroid'; static description = 'Standard Android time picker dialog'; state = { isoFormatText: 'pick a time (24-hour format)', presetHour: 4, presetMinute: 4, presetText: 'pick a time, default: 4:04AM', simpleText: 'pick a time', clockText: 'pick a time', spinnerText: 'pick a time', defaultText: 'pick a time', }; showPicker = async (stateKey, options) => { try { const {action, minute, hour} = await TimePickerAndroid.open(options); var newState = {}; if (action === TimePickerAndroid.timeSetAction) { newState[stateKey + 'Text'] = _formatTime(hour, minute); newState[stateKey + 'Hour'] = hour; newState[stateKey + 'Minute'] = minute; } else if (action === TimePickerAndroid.dismissedAction) { newState[stateKey + 'Text'] = 'dismissed'; } this.setState(newState); } catch ({code, message}) { console.warn(`Error in example '${stateKey}': `, message); } }; render() { return ( {this.state.simpleText} {this.state.clockText} {this.state.spinnerText} {this.state.defaultText} {this.state.presetText} {this.state.isoFormatText} ); } } /** * Returns e.g. '3:05'. */ function _formatTime(hour, minute) { return hour + ':' + (minute < 10 ? '0' + minute : minute); } var styles = StyleSheet.create({ text: { color: 'black', }, }); module.exports = TimePickerAndroidExample;