UNPKG

@oxyhq/services

Version:

OxyHQ Expo/React Native SDK — UI components, screens, and native features

67 lines (57 loc) 1.53 kB
import type { ColorValue } from 'react-native'; import colorUtil from 'color'; import type { InternalTheme } from '../types'; const getUnderlayColor = ({ theme, calculatedRippleColor, underlayColor, }: { theme: InternalTheme; calculatedRippleColor: ColorValue; underlayColor?: string; }) => { if (underlayColor != null) { return underlayColor; } if (theme.isV3) { return typeof calculatedRippleColor === 'string' ? calculatedRippleColor : '#000000'; } return colorUtil(typeof calculatedRippleColor === 'string' ? calculatedRippleColor : '#000000').fade(0.5).rgb().string(); }; const getRippleColor = ({ theme, rippleColor, }: { theme: InternalTheme; rippleColor?: ColorValue; }) => { if (rippleColor) { return rippleColor; } if (theme.isV3) { return colorUtil(theme.colors.onSurface).alpha(0.12).rgb().string(); } if (theme.dark) { return colorUtil(theme.colors.onSurface || theme.colors.text || '#000000').alpha(0.32).rgb().string(); } return colorUtil(theme.colors.text || theme.colors.onSurface || '#000000').alpha(0.2).rgb().string(); }; export const getTouchableRippleColors = ({ theme, rippleColor, underlayColor, }: { theme: InternalTheme; rippleColor?: ColorValue; underlayColor?: string; }) => { const calculatedRippleColor = getRippleColor({ theme, rippleColor }); return { calculatedRippleColor, calculatedUnderlayColor: getUnderlayColor({ theme, calculatedRippleColor, underlayColor, }), }; };