@applicaster/zapp-react-native-ui-components
Version:
Applicaster Zapp React Native ui components for the Quick Brick App
58 lines (45 loc) • 1.7 kB
text/typescript
import { transformColorCode as fixColorHexCode } from "@applicaster/zapp-react-native-utils/transform";
import * as R from "ramda";
import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
import { styleKeys } from "@applicaster/zapp-react-native-utils/styleKeysUtils";
export const ACTIVE_COLOR = "ACTIVE_COLOR";
export const BACKGROUND_COLOR = "BACKGROUND_COLOR";
export const MAIN_TEXT_COLOR = "MAIN_TEXT_COLOR";
export const FOCUSED_TEXT_COLOR = "FOCUSED_TEXT_COLOR";
const platformKey = styleKeys?.style_namespace;
const colorKeyPath = (keyName) => [
isTV() ? platformKey : "universal",
keyName,
"color",
];
const colorKeyPerPlatform = (keyName) => ["fire_tv", keyName, "color"];
const COLORS = {
[ACTIVE_COLOR]: {
path: colorKeyPath("active"),
newSDKPath: colorKeyPerPlatform("active"),
default: "rgba(252,70,27,1.0)",
},
[BACKGROUND_COLOR]: {
path: colorKeyPath("background"),
newSDKPath: colorKeyPerPlatform("background"),
default: "rgba(47,47,47,1.0)",
},
[MAIN_TEXT_COLOR]: {
path: colorKeyPath("main_text"),
newSDKPath: colorKeyPerPlatform("main_text"),
default: "rgba(239,239,239,1.0)",
},
[FOCUSED_TEXT_COLOR]: {
path: colorKeyPath("focused_text_color"),
newSDKPath: colorKeyPerPlatform("focused_text_color"),
default: "rgba(239,239,239,1.0)",
},
};
export const getColor = (name, styles) => {
const colorKeyPath = R.path([name, "path"], COLORS);
const colorNewSDKPath = R.path([name, "newSDKPath"], COLORS);
const color =
fixColorHexCode(R.path(colorKeyPath, styles)) ||
fixColorHexCode(R.path(colorNewSDKPath, styles));
return color || R.path([name, "default"], COLORS);
};