1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-04-17 11:26:26 +02:00

42 lines
846 B
JavaScript
Raw Normal View History

2017-07-13 00:01:15 +01:00
import DialogBox from 'react-native-dialogbox';
2017-07-15 17:25:33 +01:00
import { Keyboard } from 'react-native';
2017-07-13 00:01:15 +01:00
// Add this at the bottom of the component:
//
// <DialogBox ref={dialogbox => { this.dialogbox = dialogbox }}/>
let dialogs = {};
dialogs.confirm = (parentComponent, message) => {
if (!'dialogbox' in parentComponent) throw new Error('A "dialogbox" component must be defined on the parent component!');
return new Promise((resolve, reject) => {
2017-07-15 17:25:33 +01:00
Keyboard.dismiss();
2017-07-13 00:01:15 +01:00
parentComponent.dialogbox.confirm({
content: message,
ok: {
callback: () => {
resolve(true);
}
},
cancel: {
callback: () => {
resolve(false);
}
},
});
2017-07-15 17:25:33 +01:00
});
};
dialogs.error = (parentComponent, message) => {
Keyboard.dismiss();
return parentComponent.dialogbox.alert(message);
2017-07-13 00:01:15 +01:00
}
2017-07-15 17:25:33 +01:00
dialogs.DialogBox = DialogBox
2017-07-13 00:01:15 +01:00
export { dialogs };