Change to use theme utils from mattermost-redux (#1531)
* Change to use theme utils from mattermost-redux * Updated yarn.lock
This commit is contained in:
parent
bb726fd029
commit
8decb29d52
2 changed files with 611 additions and 79 deletions
|
|
@ -3,74 +3,17 @@
|
|||
|
||||
import {StyleSheet} from 'react-native';
|
||||
|
||||
import * as ThemeUtils from 'mattermost-redux/utils/theme_utils';
|
||||
|
||||
export function makeStyleSheetFromTheme(getStyleFromTheme) {
|
||||
let lastTheme = null;
|
||||
let style = null;
|
||||
|
||||
return (theme) => {
|
||||
if (theme !== lastTheme) {
|
||||
style = StyleSheet.create(getStyleFromTheme(theme));
|
||||
lastTheme = theme;
|
||||
}
|
||||
|
||||
return style;
|
||||
};
|
||||
return ThemeUtils.makeStyleFromTheme((theme) => {
|
||||
return StyleSheet.create(getStyleFromTheme(theme));
|
||||
});
|
||||
}
|
||||
|
||||
function normalizeColor(oldColor) {
|
||||
let color = oldColor;
|
||||
if (color.length && color[0] === '#') {
|
||||
color = color.slice(1);
|
||||
}
|
||||
export const changeOpacity = ThemeUtils.changeOpacity;
|
||||
|
||||
if (color.length === 3) {
|
||||
const tempColor = color;
|
||||
color = '';
|
||||
|
||||
color += tempColor[0] + tempColor[0];
|
||||
color += tempColor[1] + tempColor[1];
|
||||
color += tempColor[2] + tempColor[2];
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
export function changeOpacity(oldColor, opacity) {
|
||||
const color = normalizeColor(oldColor);
|
||||
|
||||
const r = parseInt(color.substring(0, 2), 16);
|
||||
const g = parseInt(color.substring(2, 4), 16);
|
||||
const b = parseInt(color.substring(4, 6), 16);
|
||||
|
||||
return `rgba(${r},${g},${b},${opacity})`;
|
||||
}
|
||||
|
||||
function blendComponent(background, foreground, opacity) {
|
||||
return ((1 - opacity) * background) + (opacity * foreground);
|
||||
}
|
||||
|
||||
export function blendColors(background, foreground, opacity) {
|
||||
const backgroundNormalized = normalizeColor(background);
|
||||
const foregroundNormalized = normalizeColor(foreground);
|
||||
|
||||
const r = blendComponent(
|
||||
parseInt(backgroundNormalized.substring(0, 2), 16),
|
||||
parseInt(foregroundNormalized.substring(0, 2), 16),
|
||||
opacity
|
||||
);
|
||||
const g = blendComponent(
|
||||
parseInt(backgroundNormalized.substring(2, 4), 16),
|
||||
parseInt(foregroundNormalized.substring(2, 4), 16),
|
||||
opacity
|
||||
);
|
||||
const b = blendComponent(
|
||||
parseInt(backgroundNormalized.substring(4, 6), 16),
|
||||
parseInt(foregroundNormalized.substring(4, 6), 16),
|
||||
opacity
|
||||
);
|
||||
|
||||
return `rgb(${r},${g},${b})`;
|
||||
}
|
||||
export const blendColors = ThemeUtils.blendColors;
|
||||
|
||||
export function concatStyles(...styles) {
|
||||
return [].concat(styles);
|
||||
|
|
|
|||
Loading…
Reference in a new issue