forked from Ivasoft/mattermost-mobile
* Added DrawerItem component
* WIP Account Screen
* Added react-native-paper
* Added StatusLabel Component
* Extracted i18n
* TS fix DrawerItem component
* WIP Account Screen
* Added server name label under log out
* Updated translation
* WIP
* Fixes the Offline text style
* Added Metropolis fonts
* WIP
* Typo clean up
* WIP
* WIP
* WIP
* Added server display name
* Writing OpenSans properly
* WIP
* WIP
* Added OptionsModal
* Opening OptionsModal
* Added translation keys
* Writes status to local db
* Fix missing translation
* Fix OptionModal not dismissing
* Pushing status to server
* Refactored
* Added CustomStatusExpiry component
* Added sub components
* Added CustomLabel
* CustomStatus WIP
* Added Custom Status screen WIP
* WIP - unsetCustomStatus and CustomStatus constant
* WIP
* WIP
* WIP
* WIP
* WIP
* WIP
* WIP
* Retrieving RecentCustomStatuses from Preferences table
* WIP
* WIP
* WIP
* Added Clear After Modal
* WIP - Transations
* WIP
* Done with showing modal cst
* wip
* Clear After Modal - DONE
* fix
* Added missing API calls
* wip
* Causing screen refresh
* wip
* WIP
* WIP
* WIP
* Code clean up
* Added OOO alert box
* Refactored Options-Item
* Refactored OptionsModalList component
* Opening 'status' in BottomSheet instead of OptionsModal
* AddReaction screen - WIP
* Add Reaction screen - WIP
* Added EmojiPickerRow
* Added @components/emoji_picker - WIP
* Emoji Picker - WIP
* WIP
* WIP
* WIP
* SectionList - WIP
* Installed react-native-section_list_get_item_layout
* Adding API calls - WIP
* WIP
* Search Bar component - WIP
* WIP
* WIP
* WIP
* Rendering Emoticons now - have to tackle some fixmes
* Code clean up
* Code clean up - WIP
* Code clean up
* WIP
* Major clean up
* wip
* WIP
* Fix rendering issue with SectionIcons and SearchBar
* Tackled the CustomEmojiPage
* Code clean up
* WIP
* Done with loading User Profiles for Custom Emoji
* Code clean up
* Code Clean up
* Fix screen Account
* Added missing sql file for IOS Pod
* Updated Podfile.lock
* Using queryConfig instead of queryCommonSystemValues
* Fix - Custom status
* Fix - Custom Status - Error
* Fix - Clear Pass Status - WIP
* Fix - Custom Status Clear
* Need to fix CST clear
* WIP
* Status clear - working
* Using catchError operator
* remove unnecessary prop
* Status BottomSheet now has colored indicators
* Added KeyboardTrackingView from 'react-native-keyboard-tracking-view'
* Code clean up
* WIP
* code clean up
* Added a safety check
* Fix - Display suggestions
* Code clean up based on PR Review
* Code clean up
* Code clean up
* Code clean up
* Corrections
* Fix tsc
* TS fix
* Removed unnecessary prop
* Fix SearchBar Ts
* Updated tests
* Delete search_bar.test.js.snap
* Merge branch 'gekidou' into gekidou_account_screen
* Revert "Merge branch 'gekidou' into gekidou_account_screen"
This reverts commit 5defc31321.
* Fix fonts
* Refactor home account screen
* fix theme provider
* refactor bottom sheet
* remove paper provider
* update drawer item snapshots
* Remove options modal screen
* remove react-native-ui-lib dependency
* Refactor & fix custom status & navigation (including tablet)
* Refactor emoji picker
Co-authored-by: Avinash Lingaloo <>
Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
265 lines
7.1 KiB
TypeScript
265 lines
7.1 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {StyleSheet} from 'react-native';
|
|
import tinyColor from 'tinycolor2';
|
|
|
|
import {Preferences, Screens} from '@constants';
|
|
import {mergeNavigationOptions} from '@screens/navigation';
|
|
import EphemeralStore from '@store/ephemeral_store';
|
|
|
|
import type {Options} from 'react-native-navigation';
|
|
|
|
const MODAL_SCREENS_WITHOUT_BACK = [
|
|
'AddReaction',
|
|
'ChannelInfo',
|
|
'ClientUpgrade',
|
|
'CreateChannel',
|
|
'EditPost',
|
|
'ErrorTeamsList',
|
|
'MoreChannels',
|
|
'MoreDirectMessages',
|
|
'Permalink',
|
|
'SelectTeam',
|
|
'Settings',
|
|
'TermsOfService',
|
|
'UserProfile',
|
|
];
|
|
|
|
const rgbPattern = /^rgba?\((\d+),(\d+),(\d+)(?:,([\d.]+))?\)$/;
|
|
|
|
export function getComponents(inColor: string): {red: number; green: number; blue: number; alpha: number} {
|
|
let color = inColor;
|
|
|
|
// RGB color
|
|
const match = rgbPattern.exec(color);
|
|
if (match) {
|
|
return {
|
|
red: parseInt(match[1], 10),
|
|
green: parseInt(match[2], 10),
|
|
blue: parseInt(match[3], 10),
|
|
alpha: match[4] ? parseFloat(match[4]) : 1,
|
|
};
|
|
}
|
|
|
|
// Hex color
|
|
if (color[0] === '#') {
|
|
color = color.slice(1);
|
|
}
|
|
|
|
if (color.length === 3) {
|
|
const tempColor = color;
|
|
color = '';
|
|
|
|
color += tempColor[0] + tempColor[0];
|
|
color += tempColor[1] + tempColor[1];
|
|
color += tempColor[2] + tempColor[2];
|
|
}
|
|
|
|
return {
|
|
red: parseInt(color.substring(0, 2), 16),
|
|
green: parseInt(color.substring(2, 4), 16),
|
|
blue: parseInt(color.substring(4, 6), 16),
|
|
alpha: 1,
|
|
};
|
|
}
|
|
|
|
export function makeStyleSheetFromTheme(getStyleFromTheme: (a: any) => any): (a: any) => any {
|
|
let lastTheme: any;
|
|
let style: any;
|
|
return (theme: any) => {
|
|
if (!style || theme !== lastTheme) {
|
|
style = StyleSheet.create(getStyleFromTheme(theme));
|
|
lastTheme = theme;
|
|
}
|
|
|
|
return style;
|
|
};
|
|
}
|
|
|
|
export function changeOpacity(oldColor: string, opacity: number): string {
|
|
const {
|
|
red,
|
|
green,
|
|
blue,
|
|
alpha,
|
|
} = getComponents(oldColor);
|
|
|
|
return `rgba(${red},${green},${blue},${alpha * opacity})`;
|
|
}
|
|
|
|
export function concatStyles<T>(...styles: T[]) {
|
|
return ([] as T[]).concat(...styles);
|
|
}
|
|
|
|
export function setNavigatorStyles(componentId: string, theme: Theme) {
|
|
const options: Options = {
|
|
topBar: {
|
|
title: {
|
|
color: theme.sidebarHeaderTextColor,
|
|
},
|
|
background: {
|
|
color: theme.sidebarHeaderBg,
|
|
},
|
|
leftButtonColor: theme.sidebarHeaderTextColor,
|
|
rightButtonColor: theme.sidebarHeaderTextColor,
|
|
},
|
|
layout: {
|
|
componentBackgroundColor: theme.centerChannelBg,
|
|
},
|
|
};
|
|
|
|
if (!MODAL_SCREENS_WITHOUT_BACK.includes(componentId) && options.topBar) {
|
|
options.topBar.backButton = {
|
|
color: theme.sidebarHeaderTextColor,
|
|
};
|
|
}
|
|
|
|
mergeNavigationOptions(componentId, options);
|
|
}
|
|
|
|
export function setNavigationStackStyles(theme: Theme) {
|
|
EphemeralStore.allNavigationComponentIds.forEach((componentId) => {
|
|
if (componentId !== Screens.BOTTOM_SHEET) {
|
|
setNavigatorStyles(componentId, theme);
|
|
}
|
|
});
|
|
}
|
|
|
|
export function getKeyboardAppearanceFromTheme(theme: Theme) {
|
|
return tinyColor(theme.centerChannelBg).isLight() ? 'light' : 'dark';
|
|
}
|
|
|
|
export function hexToHue(hexColor: string) {
|
|
let {red, green, blue} = getComponents(hexColor);
|
|
red /= 255;
|
|
green /= 255;
|
|
blue /= 255;
|
|
|
|
const channelMax = Math.max(red, green, blue);
|
|
const channelMin = Math.min(red, green, blue);
|
|
const delta = channelMax - channelMin;
|
|
let hue = 0;
|
|
|
|
if (delta === 0) {
|
|
hue = 0;
|
|
} else if (channelMax === red) {
|
|
hue = ((green - blue) / delta) % 6;
|
|
} else if (channelMax === green) {
|
|
hue = ((blue - red) / delta) + 2;
|
|
} else {
|
|
hue = ((red - green) / delta) + 4;
|
|
}
|
|
|
|
hue = Math.round(hue * 60);
|
|
|
|
if (hue < 0) {
|
|
hue += 360;
|
|
}
|
|
|
|
return hue;
|
|
}
|
|
|
|
function blendComponent(background: number, foreground: number, opacity: number): number {
|
|
return ((1 - opacity) * background) + (opacity * foreground);
|
|
}
|
|
|
|
export function blendColors(background: string, foreground: string, opacity: number, hex = false): string {
|
|
const backgroundComponents = getComponents(background);
|
|
const foregroundComponents = getComponents(foreground);
|
|
|
|
const red = Math.floor(blendComponent(
|
|
backgroundComponents.red,
|
|
foregroundComponents.red,
|
|
opacity,
|
|
));
|
|
const green = Math.floor(blendComponent(
|
|
backgroundComponents.green,
|
|
foregroundComponents.green,
|
|
opacity,
|
|
));
|
|
const blue = Math.floor(blendComponent(
|
|
backgroundComponents.blue,
|
|
foregroundComponents.blue,
|
|
opacity,
|
|
));
|
|
const alpha = blendComponent(
|
|
backgroundComponents.alpha,
|
|
foregroundComponents.alpha,
|
|
opacity,
|
|
);
|
|
|
|
if (hex) {
|
|
let r = red.toString(16);
|
|
let g = green.toString(16);
|
|
let b = blue.toString(16);
|
|
|
|
if (r.length === 1) {
|
|
r = '0' + r;
|
|
}
|
|
if (g.length === 1) {
|
|
g = '0' + g;
|
|
}
|
|
if (b.length === 1) {
|
|
b = '0' + b;
|
|
}
|
|
|
|
return `#${r + g + b}`;
|
|
}
|
|
|
|
return `rgba(${red},${green},${blue},${alpha})`;
|
|
}
|
|
|
|
const themeTypeMap: ThemeTypeMap = {
|
|
Mattermost: 'denim',
|
|
Organization: 'sapphire',
|
|
'Mattermost Dark': 'indigo',
|
|
'Windows Dark': 'onyx',
|
|
Denim: 'denim',
|
|
Sapphire: 'sapphire',
|
|
Quartz: 'quartz',
|
|
Indigo: 'indigo',
|
|
Onyx: 'onyx',
|
|
custom: 'custom',
|
|
};
|
|
|
|
// setThemeDefaults will set defaults on the theme for any unset properties.
|
|
export function setThemeDefaults(theme: Theme): Theme {
|
|
const themes = Preferences.THEMES as Record<ThemeKey, Theme>;
|
|
const defaultTheme = themes.denim;
|
|
|
|
const processedTheme = {...theme};
|
|
|
|
// If this is a system theme, return the source theme object matching the theme preference type
|
|
if (theme.type && theme.type !== 'custom' && Object.keys(themeTypeMap).includes(theme.type)) {
|
|
return Preferences.THEMES[themeTypeMap[theme.type]];
|
|
}
|
|
|
|
for (const key of Object.keys(defaultTheme)) {
|
|
if (theme[key]) {
|
|
// Fix a case where upper case theme colours are rendered as black
|
|
processedTheme[key] = theme[key]?.toLowerCase();
|
|
}
|
|
}
|
|
|
|
for (const property in defaultTheme) {
|
|
if (property === 'type' || (property === 'sidebarTeamBarBg' && theme.sidebarHeaderBg)) {
|
|
continue;
|
|
}
|
|
if (theme[property] == null) {
|
|
processedTheme[property] = defaultTheme[property];
|
|
}
|
|
|
|
// Backwards compatability with old name
|
|
if (!theme.mentionBg && theme.mentionBj) {
|
|
processedTheme.mentionBg = theme.mentionBj;
|
|
}
|
|
}
|
|
|
|
if (!theme.sidebarTeamBarBg && theme.sidebarHeaderBg) {
|
|
processedTheme.sidebarTeamBarBg = blendColors(theme.sidebarHeaderBg, '#000000', 0.2, true);
|
|
}
|
|
|
|
return processedTheme as Theme;
|
|
}
|