1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-04-14 11:18:47 +02:00
joplin/ReactNativeClient/lib/components/select-date-time-dialog.js

97 lines
2.2 KiB
JavaScript
Raw Normal View History

2018-03-09 17:49:35 +00:00
import React, { Component } from "react";
import { Keyboard, View, Button, Text, StyleSheet, Linking, Image } from "react-native";
import PopupDialog, { DialogTitle, DialogButton } from "react-native-popup-dialog";
import DatePicker from "react-native-datepicker";
import moment from "moment";
import { _ } from "lib/locale.js";
2017-09-10 17:56:27 +01:00
class SelectDateTimeDialog extends Component {
constructor() {
super();
this.dialog_ = null;
this.shown_ = false;
this.state = { date: null };
}
componentWillReceiveProps(newProps) {
if (newProps.date != this.state.date) {
this.setState({ date: newProps.date });
}
2018-03-09 17:49:35 +00:00
if ("shown" in newProps) {
2017-09-10 17:56:27 +01:00
this.show(newProps.shown);
}
}
show(doShow = true) {
if (doShow) {
this.dialog_.show();
} else {
this.dialog_.dismiss();
}
this.shown_ = doShow;
}
dismiss() {
this.show(false);
}
dateTimeFormat() {
return "MM/DD/YYYY HH:mm";
}
stringToDate(s) {
return moment(s, this.dateTimeFormat()).toDate();
}
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);
}
render() {
const popupActions = [
<DialogButton text="Save alarm" align="center" onPress={() => this.onAccept()} key="saveButton" />,
<DialogButton text="Clear alarm" align="center" onPress={() => this.onClear()} key="clearButton" />,
<DialogButton text="Cancel" align="center" onPress={() => this.onReject()} key="cancelButton" />,
];
return (
<PopupDialog
2018-03-09 17:49:35 +00:00
ref={dialog => {
this.dialog_ = dialog;
}}
dialogTitle={<DialogTitle title={_("Set alarm")} />}
2017-09-10 17:56:27 +01:00
actions={popupActions}
width={0.9}
height={350}
2018-03-09 17:49:35 +00:00
>
<View style={{ flex: 1, margin: 20, alignItems: "center" }}>
2017-09-10 17:56:27 +01:00
<DatePicker
date={this.state.date}
mode="datetime"
2018-03-09 17:49:35 +00:00
placeholder={_("Select date")}
2017-09-10 17:56:27 +01:00
format={this.dateTimeFormat()}
2018-03-09 17:49:35 +00:00
confirmBtnText={_("Confirm")}
cancelBtnText={_("Cancel")}
onDateChange={date => {
this.setState({ date: this.stringToDate(date) });
}}
style={{ width: 300 }}
2017-09-10 17:56:27 +01:00
/>
</View>
</PopupDialog>
);
}
}
2018-03-09 17:49:35 +00:00
export { SelectDateTimeDialog };