Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/components/Chip/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ const md3 = (theme: InternalTheme) => theme;

const stateOpacity = tokens.md.sys.state.opacity;

// `color(selectedColor).alpha(0.29).rgb().string()` is pure, so the result is
// cached per input color to avoid re-parsing on every Chip render (#4946).
const selectedColorBorderCache = new Map<string, string>();

const getSelectedColorBorder = (selectedColor: string): string => {
let border = selectedColorBorderCache.get(selectedColor);
if (border === undefined) {
border = color(selectedColor).alpha(0.29).rgb().string();
selectedColorBorderCache.set(selectedColor, border);
}
return border;
};

export type ChipAvatarProps = {
style?: StyleProp<ViewStyle>;
};
Expand Down Expand Up @@ -39,7 +52,7 @@ const getBorderColor = ({

if (isSelectedColor) {
if (typeof selectedColor === 'string') {
return color(selectedColor).alpha(0.29).rgb().string();
return getSelectedColorBorder(selectedColor);
}
// PlatformColor / OpaqueColorValue: skip the alpha pass and render opaque.
return selectedColor;
Expand Down
13 changes: 10 additions & 3 deletions src/components/TouchableRipple/TouchableRipple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,19 @@ const TouchableRipple = ({
theme,
rippleColor,
});
const isWeb = Platform.OS === 'web';
// Web-only style. PlatformColor doesn't exist on web, so the calculated
// ripple color is effectively always a string here.
const hoverColor =
typeof calculatedRippleColor === 'string'
// ripple color is effectively always a string here. The `color()` chain is
// pure, so it is memoized and skipped entirely on native platforms where
// `hoverColor` is never applied.
const hoverColor = React.useMemo(() => {
if (!isWeb) {
return calculatedRippleColor;
}
return typeof calculatedRippleColor === 'string'
? color(calculatedRippleColor).fade(0.5).rgb().string()
: calculatedRippleColor;
}, [calculatedRippleColor, isWeb]);
const { rippleEffectEnabled } = React.useContext<Settings>(SettingsContext);

const { onPress, onLongPress, onPressIn, onPressOut } = rest;
Expand Down
Loading