2018-03-09 22:59:12 +02:00
|
|
|
const React = require('react');
|
|
|
|
const { Text, Modal, View, StyleSheet, Button } = require('react-native');
|
2020-11-05 18:58:23 +02:00
|
|
|
const { themeStyle } = require('./global-style.js');
|
2020-11-07 17:59:37 +02:00
|
|
|
const { _ } = require('@joplin/lib/locale');
|
2018-02-22 20:58:15 +02:00
|
|
|
|
|
|
|
class ModalDialog extends React.Component {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.styles_ = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
styles() {
|
2020-09-15 15:01:07 +02:00
|
|
|
const themeId = this.props.themeId;
|
2018-02-22 20:58:15 +02:00
|
|
|
const theme = themeStyle(themeId);
|
|
|
|
|
|
|
|
if (this.styles_[themeId]) return this.styles_[themeId];
|
|
|
|
this.styles_ = {};
|
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const styles = {
|
2018-02-22 20:58:15 +02:00
|
|
|
modalWrapper: {
|
|
|
|
flex: 1,
|
2018-03-09 22:59:12 +02:00
|
|
|
justifyContent: 'center',
|
2018-02-22 20:58:15 +02:00
|
|
|
},
|
|
|
|
modalContentWrapper: {
|
2019-07-29 15:43:53 +02:00
|
|
|
flex: 1,
|
2018-03-09 22:59:12 +02:00
|
|
|
flexDirection: 'column',
|
2018-02-22 20:58:15 +02:00
|
|
|
backgroundColor: theme.backgroundColor,
|
|
|
|
borderWidth: 1,
|
2019-07-29 15:43:53 +02:00
|
|
|
borderColor: theme.dividerColor,
|
2018-02-22 20:58:15 +02:00
|
|
|
margin: 20,
|
|
|
|
padding: 10,
|
2018-03-18 01:00:01 +02:00
|
|
|
borderRadius: 5,
|
2018-02-22 20:58:15 +02:00
|
|
|
},
|
|
|
|
modalContentWrapper2: {
|
2019-07-29 15:43:53 +02:00
|
|
|
flex: 1,
|
2018-02-22 20:58:15 +02:00
|
|
|
},
|
2018-03-26 19:52:49 +02:00
|
|
|
title: Object.assign({}, theme.normalText, {
|
2018-02-22 20:58:15 +02:00
|
|
|
borderBottomWidth: 1,
|
|
|
|
borderBottomColor: theme.dividerColor,
|
|
|
|
paddingBottom: 10,
|
2018-03-18 01:00:01 +02:00
|
|
|
fontWeight: 'bold',
|
2018-03-26 19:52:49 +02:00
|
|
|
}),
|
2018-02-22 20:58:15 +02:00
|
|
|
buttonRow: {
|
2018-03-09 22:59:12 +02:00
|
|
|
flexDirection: 'row',
|
2018-02-22 20:58:15 +02:00
|
|
|
borderTopWidth: 1,
|
|
|
|
borderTopColor: theme.dividerColor,
|
2018-03-26 19:52:49 +02:00
|
|
|
paddingTop: 10,
|
2018-02-22 20:58:15 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
this.styles_[themeId] = StyleSheet.create(styles);
|
|
|
|
return this.styles_[themeId];
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const ContentComponent = this.props.ContentComponent;
|
2018-03-18 01:00:01 +02:00
|
|
|
const buttonBarEnabled = this.props.buttonBarEnabled !== false;
|
2018-02-22 20:58:15 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={this.styles().modalWrapper}>
|
2019-07-29 15:43:53 +02:00
|
|
|
<Modal transparent={true} visible={true} onRequestClose={() => {}}>
|
2018-03-18 01:00:01 +02:00
|
|
|
<View elevation={10} style={this.styles().modalContentWrapper}>
|
|
|
|
<Text style={this.styles().title}>{this.props.title}</Text>
|
2019-07-29 15:43:53 +02:00
|
|
|
<View style={this.styles().modalContentWrapper2}>{ContentComponent}</View>
|
2018-02-22 20:58:15 +02:00
|
|
|
<View style={this.styles().buttonRow}>
|
2019-07-29 15:43:53 +02:00
|
|
|
<View style={{ flex: 1 }}>
|
2018-03-18 01:00:01 +02:00
|
|
|
<Button disabled={!buttonBarEnabled} title={_('OK')} onPress={this.props.onOkPress}></Button>
|
2018-02-22 20:58:15 +02:00
|
|
|
</View>
|
2019-07-29 15:43:53 +02:00
|
|
|
<View style={{ flex: 1, marginLeft: 5 }}>
|
2018-03-18 01:00:01 +02:00
|
|
|
<Button disabled={!buttonBarEnabled} title={_('Cancel')} onPress={this.props.onCancelPress}></Button>
|
2018-02-22 20:58:15 +02:00
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
</Modal>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
module.exports = ModalDialog;
|