2018-03-09 22:59:12 +02:00
|
|
|
const Setting = require('lib/models/Setting.js');
|
2018-03-26 19:52:49 +02:00
|
|
|
const { Platform } = require('react-native');
|
2020-06-10 23:08:59 +02:00
|
|
|
const { themeById } = require('lib/theme');
|
2017-08-01 19:59:01 +02:00
|
|
|
|
2020-06-10 23:08:59 +02:00
|
|
|
const baseStyle = {
|
|
|
|
appearance: 'light',
|
2017-07-30 23:04:26 +02:00
|
|
|
fontSize: 16,
|
2020-06-10 23:08:59 +02:00
|
|
|
noteViewerFontSize: 16,
|
2017-07-21 23:40:02 +02:00
|
|
|
margin: 15, // No text and no interactive component should be within this margin
|
2017-07-30 23:04:26 +02:00
|
|
|
itemMarginTop: 10,
|
|
|
|
itemMarginBottom: 10,
|
|
|
|
fontSizeSmaller: 14,
|
2018-01-25 21:01:14 +02:00
|
|
|
disabledOpacity: 0.2,
|
2020-06-10 23:08:59 +02:00
|
|
|
lineHeight: '1.6em',
|
2017-07-21 23:40:02 +02:00
|
|
|
};
|
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const themeCache_ = {};
|
2017-08-01 19:59:01 +02:00
|
|
|
|
2018-03-26 19:52:49 +02:00
|
|
|
function addExtraStyles(style) {
|
2020-06-10 23:08:59 +02:00
|
|
|
style.marginRight = style.margin;
|
|
|
|
style.marginLeft = style.margin;
|
|
|
|
style.marginTop = style.margin;
|
|
|
|
style.marginBottom = style.margin;
|
|
|
|
|
2018-03-26 19:52:49 +02:00
|
|
|
style.icon = {
|
|
|
|
color: style.color,
|
|
|
|
fontSize: 30,
|
|
|
|
};
|
|
|
|
|
|
|
|
style.lineInput = {
|
|
|
|
color: style.color,
|
|
|
|
backgroundColor: style.backgroundColor,
|
2018-12-15 02:42:19 +02:00
|
|
|
borderBottomWidth: 1,
|
2020-06-10 23:08:59 +02:00
|
|
|
borderColor: style.dividerColor,
|
2018-12-15 02:42:19 +02:00
|
|
|
paddingBottom: 0,
|
2018-03-26 19:52:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (Platform.OS === 'ios') {
|
2019-02-03 18:57:29 +02:00
|
|
|
delete style.lineInput.borderBottomWidth;
|
|
|
|
delete style.lineInput.borderColor;
|
2018-03-26 19:52:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
style.buttonRow = {
|
|
|
|
flexDirection: 'row',
|
|
|
|
borderTopWidth: 1,
|
|
|
|
borderTopColor: style.dividerColor,
|
|
|
|
paddingTop: 10,
|
|
|
|
};
|
|
|
|
|
|
|
|
style.normalText = {
|
|
|
|
color: style.color,
|
|
|
|
fontSize: style.fontSize,
|
|
|
|
};
|
|
|
|
|
2018-03-27 19:41:19 +02:00
|
|
|
style.urlText = {
|
2020-06-10 23:08:59 +02:00
|
|
|
color: style.urlColor,
|
2018-03-27 19:41:19 +02:00
|
|
|
fontSize: style.fontSize,
|
|
|
|
};
|
|
|
|
|
2019-06-08 01:23:17 +02:00
|
|
|
style.headerStyle = {
|
|
|
|
color: style.color,
|
|
|
|
fontSize: style.fontSize * 1.2,
|
|
|
|
fontWeight: 'bold',
|
|
|
|
};
|
|
|
|
|
|
|
|
style.headerWrapperStyle = {
|
|
|
|
backgroundColor: style.headerBackgroundColor,
|
|
|
|
};
|
|
|
|
|
2020-04-17 00:35:31 +02:00
|
|
|
style.keyboardAppearance = style.appearance;
|
|
|
|
|
2018-03-26 19:52:49 +02:00
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
2019-09-17 22:32:00 +02:00
|
|
|
function editorFont(fontId) {
|
|
|
|
// IMPORTANT: The font mapping must match the one in Setting.js
|
|
|
|
const fonts = {
|
|
|
|
[Setting.FONT_DEFAULT]: null,
|
|
|
|
[Setting.FONT_MENLO]: 'Menlo',
|
|
|
|
[Setting.FONT_COURIER_NEW]: 'Courier New',
|
|
|
|
[Setting.FONT_AVENIR]: 'Avenir',
|
|
|
|
[Setting.FONT_MONOSPACE]: 'monospace',
|
|
|
|
};
|
|
|
|
if (!fontId) {
|
|
|
|
console.warn('Editor font not set! Falling back to default font."');
|
|
|
|
fontId = Setting.FONT_DEFAULT;
|
|
|
|
}
|
|
|
|
return fonts[fontId];
|
|
|
|
}
|
|
|
|
|
2017-08-01 19:59:01 +02:00
|
|
|
function themeStyle(theme) {
|
2018-04-16 15:15:29 +02:00
|
|
|
if (!theme) {
|
2019-09-17 22:32:00 +02:00
|
|
|
console.warn('Theme not set! Defaulting to Light theme.');
|
2018-04-16 15:15:29 +02:00
|
|
|
theme = Setting.THEME_LIGHT;
|
|
|
|
}
|
2018-03-27 19:41:19 +02:00
|
|
|
|
2020-06-10 23:08:59 +02:00
|
|
|
const cacheKey = [theme].join('-');
|
|
|
|
if (themeCache_[cacheKey]) return themeCache_[cacheKey];
|
2020-03-27 14:13:22 +02:00
|
|
|
|
2020-06-10 23:08:59 +02:00
|
|
|
const output = Object.assign({}, baseStyle, themeById(theme));
|
|
|
|
themeCache_[cacheKey] = addExtraStyles(output);
|
|
|
|
return themeCache_[cacheKey];
|
2017-08-01 19:59:01 +02:00
|
|
|
}
|
|
|
|
|
2020-06-10 23:08:59 +02:00
|
|
|
module.exports = { themeStyle, editorFont };
|