Skip to content

Commit c91d880

Browse files
committed
fix(mobile): chat chips drop their fill and border
1 parent 480002b commit c91d880

4 files changed

Lines changed: 30 additions & 56 deletions

File tree

‎apps/mobile/src/features/threads/ThreadFeed.tsx‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -850,14 +850,11 @@ function useMarkdownStyles(): MarkdownStyleSets {
850850
const markdownCodeText = theme["--color-md-code-text"];
851851
const markdownInlineCodeText = theme["--color-foreground-secondary"];
852852
const markdownHrColor = theme["--color-md-hr"];
853-
const userContextChipBorderColor = flattenThemeColor(
853+
// Native chip drawing parses opaque hex only, and this role is translucent.
854+
const contextChipBorderColor = flattenThemeColor(
854855
theme["--color-border"],
855856
theme["--color-user-bubble"],
856857
);
857-
const assistantContextChipBorderColor = flattenThemeColor(
858-
theme["--color-border"],
859-
theme["--color-thread-canvas"],
860-
);
861858
const markdownUserBodyColor = theme["--color-user-bubble-foreground"];
862859
const markdownUserCodeBg = theme["--color-md-user-code-bg"];
863860
const markdownUserCodeText = theme["--color-md-user-code-text"];
@@ -881,7 +878,7 @@ function useMarkdownStyles(): MarkdownStyleSets {
881878
fileTextColor: markdownUserBodyColor,
882879
quoteMarkerColor: markdownUserBodyColor,
883880
dividerColor: markdownUserBodyColor,
884-
contextChipBorderColor: userContextChipBorderColor,
881+
contextChipBorderColor,
885882
fontSize: nativeMarkdownTypography.fontSize,
886883
lineHeight: nativeMarkdownTypography.lineHeight,
887884
headingFontSizes: nativeMarkdownTypography.headingFontSizes,
@@ -903,7 +900,7 @@ function useMarkdownStyles(): MarkdownStyleSets {
903900
fileTextColor: markdownCodeText,
904901
quoteMarkerColor: markdownBlockquoteBorder,
905902
dividerColor: markdownHrColor,
906-
contextChipBorderColor: assistantContextChipBorderColor,
903+
contextChipBorderColor,
907904
fontSize: nativeMarkdownTypography.fontSize,
908905
lineHeight: nativeMarkdownTypography.lineHeight,
909906
headingFontSizes: nativeMarkdownTypography.headingFontSizes,
@@ -914,8 +911,8 @@ function useMarkdownStyles(): MarkdownStyleSets {
914911
},
915912
};
916913
}, [
917-
assistantContextChipBorderColor,
918914
boldFontFamily,
915+
contextChipBorderColor,
919916
markdownBlockquoteBorder,
920917
markdownBodyColor,
921918
markdownCodeBg,
@@ -931,7 +928,6 @@ function useMarkdownStyles(): MarkdownStyleSets {
931928
markdownUserInlineCodeText,
932929
nativeMarkdownTypography,
933930
regularFontFamily,
934-
userContextChipBorderColor,
935931
]);
936932
}
937933

‎apps/mobile/src/lib/composerChipPresentation.test.ts‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,14 @@ describe("context chip kinds", () => {
103103
});
104104
});
105105

106-
describe("contextChipColors", () => {
107-
it("mixes the accent into the fill, border and text with web's weights", async () => {
108-
const { contextChipColors } = await import("./composerChipPresentation");
109-
expect(contextChipColors("#009f6e", { foreground: "#ffffff", border: "#000000" })).toEqual({
110-
background: "#009f6e1c",
111-
border: "#003626",
112-
foreground: "#c7eadf",
113-
});
106+
describe("contextChipForeground", () => {
107+
it("mixes 22% of the accent into the text color, as web does", async () => {
108+
const { contextChipForeground } = await import("./composerChipPresentation");
109+
expect(contextChipForeground("#009f6e", "#ffffff")).toBe("#c7eadf");
114110
});
115111

116-
it("replaces an alpha byte the theme role already carries", async () => {
117-
const { contextChipColors } = await import("./composerChipPresentation");
118-
expect(
119-
contextChipColors("#ffffffff", { foreground: "#000000ff", border: "#000000" }).background,
120-
).toBe("#ffffff1c");
112+
it("replaces an alpha byte the accent already carries", async () => {
113+
const { contextChipForeground } = await import("./composerChipPresentation");
114+
expect(contextChipForeground("#ffffffff", "#000000")).toBe("#383838");
121115
});
122116
});

‎apps/mobile/src/lib/composerChipPresentation.ts‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,8 @@ export const UNAVAILABLE_CONTEXT_CHIP_PRESENTATION: ContextChipPresentation = {
4848
icon: "circle-dashed",
4949
};
5050

51-
export function contextChipColors(
52-
accent: string,
53-
surface: { readonly foreground: string; readonly border: string },
54-
) {
55-
const opaqueAccent = accent.slice(0, 7);
56-
const alpha = (weight: number) =>
57-
`${opaqueAccent}${Math.round(weight * 255)
58-
.toString(16)
59-
.padStart(2, "0")}`;
60-
return {
61-
background: alpha(0.11),
62-
border: flattenThemeColor(alpha(0.34), surface.border),
63-
foreground: flattenThemeColor(alpha(0.22), surface.foreground),
64-
};
51+
export function contextChipForeground(accent: string, foreground: string) {
52+
return flattenThemeColor(`${accent.slice(0, 7)}38`, foreground);
6553
}
6654

6755
export function composerChipSizeSuffix(record?: {

‎apps/mobile/src/native/useEnrichedLinkVariants.ts‎

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
MarkdownStyle,
77
} from "react-native-enriched-markdown";
88
import type { ComposerContextRecord } from "@t3tools/contracts";
9-
import { contextChipColors, contextChipPresentation } from "../lib/composerChipPresentation";
9+
import { contextChipForeground, contextChipPresentation } from "../lib/composerChipPresentation";
1010
import { CONTEXT_CHIP_ICON_SOURCES } from "../lib/contextChipIcons.generated";
1111
import { FONT_FAMILIES } from "../lib/fontFamilies";
1212
import { markdownFileIconSource } from "../lib/markdownFileIcons";
@@ -89,17 +89,14 @@ export function useEnrichedLinkVariants(
8989
}
9090
return byUrl;
9191
}, [assets, linkCustomization, skills, textStyle]);
92-
const chips = useMemo(
92+
const chipForegrounds = useMemo(
9393
() =>
9494
new Map(
9595
[...links].map(([url, link]) => [
9696
url,
9797
link.chip
98-
? contextChipColors(link.chip.accent ?? textStyle.color, {
99-
foreground: textStyle.color,
100-
border: textStyle.contextChipBorderColor ?? textStyle.dividerColor,
101-
})
102-
: null,
98+
? contextChipForeground(link.chip.accent ?? textStyle.color, textStyle.color)
99+
: undefined,
103100
]),
104101
),
105102
[links, textStyle],
@@ -108,27 +105,26 @@ export function useEnrichedLinkVariants(
108105
() =>
109106
Object.fromEntries(
110107
[...links].map(([url, link]) => {
111-
const colors = chips.get(url);
112-
const composerChipEm = textStyle.fontSize * 0.86 * 0.5;
108+
const chipForeground = chipForegrounds.get(url);
113109
return [
114110
enrichedLinkVariantPattern(url),
115111
{
116112
pill: {
117-
borderColor: colors?.border ?? "transparent",
118-
borderWidth: colors ? 1 : 0,
119-
borderRadius: colors ? composerChipEm : 6,
120-
paddingHorizontal: colors ? composerChipEm : 5,
121-
paddingVertical: colors ? 0 : 2,
113+
borderColor: "transparent",
114+
borderWidth: 0,
115+
borderRadius: 6,
116+
paddingHorizontal: 5,
117+
paddingVertical: 2,
122118
},
123-
fontFamily: colors ? FONT_FAMILIES.medium : textStyle.fontFamily,
124-
color: colors?.foreground ?? link.color ?? textStyle.fileTextColor,
119+
fontFamily: chipForeground ? FONT_FAMILIES.medium : textStyle.fontFamily,
120+
color: chipForeground ?? link.color ?? textStyle.fileTextColor,
125121
underline: false,
126-
backgroundColor: colors?.background ?? "transparent",
122+
backgroundColor: "transparent",
127123
},
128124
];
129125
}),
130126
),
131-
[chips, links, textStyle],
127+
[chipForegrounds, links, textStyle],
132128
);
133129
const linkPillContent = useMemo<Record<string, LinkPillContent>>(
134130
() =>
@@ -138,11 +134,11 @@ export function useEnrichedLinkVariants(
138134
{
139135
label: link.label,
140136
iconUri: link.icon ? Image.resolveAssetSource(link.icon)?.uri : undefined,
141-
iconTintColor: link.chip?.tintsIcon ? chips.get(url)?.foreground : link.iconTintColor,
137+
iconTintColor: link.chip?.tintsIcon ? chipForegrounds.get(url) : link.iconTintColor,
142138
},
143139
]),
144140
),
145-
[chips, links],
141+
[chipForegrounds, links],
146142
);
147143
return { linkVariants, linkPillContent };
148144
}

0 commit comments

Comments
 (0)