import * as React from 'react'; import { themeStyle } from '@joplin/lib/theme'; import { _ } from '@joplin/lib/locale'; const { View, Button, Text } = require('react-native'); const PopupDialog = require('react-native-popup-dialog').default; const { DialogTitle, DialogButton } = require('react-native-popup-dialog'); const time = require('@joplin/lib/time').default; const DateTimePickerModal = require('react-native-modal-datetime-picker').default; export default class SelectDateTimeDialog extends React.PureComponent { private dialog_: any = null; private shown_: boolean = false; constructor(props: any) { super(props); this.state = { date: null, mode: 'date', showPicker: false, }; this.onReject = this.onReject.bind(this); this.onPickerConfirm = this.onPickerConfirm.bind(this); this.onPickerCancel = this.onPickerCancel.bind(this); this.onSetDate = this.onSetDate.bind(this); } UNSAFE_componentWillReceiveProps(newProps: any) { if (newProps.date != this.state.date) { this.setState({ date: newProps.date }); } if ('shown' in newProps && newProps.shown != this.shown_) { this.show(newProps.shown); } } show(doShow: boolean = true) { if (doShow) { this.dialog_.show(); } else { this.dialog_.dismiss(); } this.shown_ = doShow; } dismiss() { this.show(false); } onAccept() { if (this.props.onAccept) this.props.onAccept(this.state.date); } onReject() { if (this.props.onReject) this.props.onReject(); } onClear() { if (this.props.onAccept) this.props.onAccept(null); } onPickerConfirm(selectedDate: Date) { this.setState({ date: selectedDate, showPicker: false }); } onPickerCancel() { this.setState({ showPicker: false }); } onSetDate() { this.setState({ showPicker: true }); } renderContent() { if (!this.shown_) return ; const theme = themeStyle(this.props.themeId); return ( { this.state.date && {time.formatDateToLocal(this.state.date)} }