Skip to content

Commit 830b061

Browse files
committed
feat: add blue and orange diff color palette
1 parent 6ba15c0 commit 830b061

24 files changed

Lines changed: 381 additions & 49 deletions

‎apps/mobile/src/features/review/ReviewCommentComposerSheet.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function ReviewCommentComposerSheet(props: ReviewCommentComposerSheetProp
4444
const navigation = useNavigation();
4545
const insets = useSafeAreaInsets();
4646
const { width } = useWindowDimensions();
47-
const { themeAppearance: selectedTheme } = useAppearancePreferences();
47+
const { themeAppearance: selectedTheme, diffColorScheme } = useAppearancePreferences();
4848
const target = useReviewCommentTarget();
4949
const { codeSurface } = useAppearanceCodeSurface();
5050
const { environmentId, threadId } = props.route.params;
@@ -225,7 +225,10 @@ export function ReviewCommentComposerSheet(props: ReviewCommentComposerSheetProp
225225
return (
226226
<View
227227
key={line.id}
228-
className={cn("flex-row items-start", changeTone(line.change))}
228+
className={cn(
229+
"flex-row items-start",
230+
changeTone(line.change, diffColorScheme),
231+
)}
229232
style={{ height: codeSurface.rowHeight }}
230233
>
231234
<ReviewChangeBar change={line.change} height={codeSurface.rowHeight} />

‎apps/mobile/src/features/review/ReviewSheet.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ const ReviewFileNavigatorRow = memo(function ReviewFileNavigatorRow(props: {
163163
readonly selected: boolean;
164164
readonly onSelectFile: (fileId: string | null) => void;
165165
}) {
166+
const { diffColors } = useAppearancePreferences();
166167
const { file, selected, onSelectFile } = props;
167168
// Tapping the selected file again returns to the all-files diff.
168169
const handlePress = useCallback(() => {
@@ -191,8 +192,12 @@ const ReviewFileNavigatorRow = memo(function ReviewFileNavigatorRow(props: {
191192
{file.path}
192193
</Text>
193194
<View className="mt-1 flex-row gap-2">
194-
<Text className="text-2xs font-t3-bold text-emerald-600">+{file.additions}</Text>
195-
<Text className="text-2xs font-t3-bold text-rose-600">-{file.deletions}</Text>
195+
<Text className="text-2xs font-t3-bold" style={{ color: diffColors.addText }}>
196+
+{file.additions}
197+
</Text>
198+
<Text className="text-2xs font-t3-bold" style={{ color: diffColors.deleteText }}>
199+
-{file.deletions}
200+
</Text>
196201
</View>
197202
</Pressable>
198203
);

‎apps/mobile/src/features/review/nativeReviewDiffAdapter.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { DiffColorScheme } from "@t3tools/contracts/settings";
2+
import { getDiffColors } from "../../lib/diffColors";
13
import type { NativeReviewDiffRow, NativeReviewDiffTheme } from "../diffs/nativeReviewDiffSurface";
24
import type {
35
NativeReviewDiffFile,
@@ -143,6 +145,7 @@ export function createNativeReviewDiffTheme(
143145
scheme: TerminalAppearanceScheme,
144146
themeId: MobileThemeId,
145147
appTheme: MobileThemeVariables,
148+
diffColorScheme: DiffColorScheme = "red-green",
146149
): NativeReviewDiffTheme {
147150
const terminalTheme = getMobileTerminalTheme(themeId, scheme);
148151
const [, terminalRed] = terminalTheme.palette;
@@ -169,6 +172,7 @@ export function createNativeReviewDiffTheme(
169172
deleteBar: terminalRed ?? "#ff2e3f",
170173
addText: "#5ECC71",
171174
deleteText: "#FF6762",
175+
...(diffColorScheme === "blue-orange" ? getDiffColors(diffColorScheme, scheme) : {}),
172176
};
173177
}
174178

@@ -188,6 +192,7 @@ export function createNativeReviewDiffTheme(
188192
deleteBar: terminalRed ?? "#ff2e3f",
189193
addText: "#199F43",
190194
deleteText: "#D52C36",
195+
...(diffColorScheme === "blue-orange" ? getDiffColors(diffColorScheme, scheme) : {}),
191196
};
192197
}
193198

‎apps/mobile/src/features/review/reviewDiffRendering.tsx‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Platform, Text as NativeText, View } from "react-native";
22

3+
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
4+
import type { DiffColorScheme } from "@t3tools/contracts/settings";
35
import { cn } from "../../lib/cn";
46
import { MOBILE_CODE_SURFACE } from "../../lib/typography";
57

@@ -19,36 +21,48 @@ export function renderVisibleWhitespace(value: string): string {
1921
return expandedTabs.replace(/^( +)/, (leading) => leading.replaceAll(" ", "\u00A0"));
2022
}
2123

22-
export function changeTone(change: ReviewRenderableLineRow["change"]): string {
23-
if (change === "add") return "bg-emerald-500/10";
24-
if (change === "delete") return "bg-rose-500/10";
24+
export function changeTone(
25+
change: ReviewRenderableLineRow["change"],
26+
scheme: DiffColorScheme = "red-green",
27+
): string {
28+
if (change === "add") return scheme === "blue-orange" ? "bg-blue-500/10" : "bg-emerald-500/10";
29+
if (change === "delete") return scheme === "blue-orange" ? "bg-orange-500/10" : "bg-rose-500/10";
2530
return "bg-card";
2631
}
2732

28-
export function changeBarTone(change: ReviewRenderableLineRow["change"]): string {
29-
if (change === "add") return "bg-emerald-400";
30-
if (change === "delete") return "bg-rose-400";
33+
export function changeBarTone(
34+
change: ReviewRenderableLineRow["change"],
35+
scheme: DiffColorScheme = "red-green",
36+
): string {
37+
if (change === "add") return scheme === "blue-orange" ? "bg-blue-400" : "bg-emerald-400";
38+
if (change === "delete") return scheme === "blue-orange" ? "bg-orange-400" : "bg-rose-400";
3139
return "bg-border/50";
3240
}
3341

34-
function diffHighlightColor(change: ReviewRenderableLineRow["change"]): string | undefined {
35-
if (change === "add") return "rgba(16, 185, 129, 0.24)";
36-
if (change === "delete") return "rgba(244, 63, 94, 0.24)";
42+
function diffHighlightColor(
43+
change: ReviewRenderableLineRow["change"],
44+
scheme: DiffColorScheme,
45+
): string | undefined {
46+
if (change === "add")
47+
return scheme === "blue-orange" ? "rgba(59, 130, 246, 0.24)" : "rgba(16, 185, 129, 0.24)";
48+
if (change === "delete")
49+
return scheme === "blue-orange" ? "rgba(249, 115, 22, 0.24)" : "rgba(244, 63, 94, 0.24)";
3750
return undefined;
3851
}
3952

4053
export function ReviewChangeBar(props: {
4154
readonly change: ReviewRenderableLineRow["change"];
4255
readonly height?: number;
4356
}) {
57+
const { diffColorScheme } = useAppearancePreferences();
4458
const height = props.height ?? REVIEW_DIFF_LINE_HEIGHT;
4559
if (props.change === "delete") {
4660
return (
4761
<View className="w-[5px] overflow-hidden" style={{ height }}>
4862
<View>
4963
{Array.from({ length: Math.ceil(height / 2) }, (_, index) => (
5064
<View key={index}>
51-
<View className="h-px w-[5px] bg-rose-400" />
65+
<View className={cn("h-px w-[5px]", changeBarTone("delete", diffColorScheme))} />
5266
<View className="h-px" />
5367
</View>
5468
))}
@@ -59,7 +73,7 @@ export function ReviewChangeBar(props: {
5973

6074
return (
6175
<View className="w-[5px] overflow-hidden" style={{ height }}>
62-
<View className={cn("h-full w-[5px] flex-1", changeBarTone(props.change))} />
76+
<View className={cn("h-full w-[5px] flex-1", changeBarTone(props.change, diffColorScheme))} />
6377
</View>
6478
);
6579
}
@@ -72,6 +86,7 @@ export function DiffTokenText(props: {
7286
readonly fontSize?: number;
7387
readonly lineHeight?: number;
7488
}) {
89+
const { diffColorScheme } = useAppearancePreferences();
7590
const fontSize = props.fontSize ?? MOBILE_CODE_SURFACE.fontSize;
7691
const lineHeight = props.lineHeight ?? MOBILE_CODE_SURFACE.rowHeight;
7792
if (!props.tokens || props.tokens.length === 0) {
@@ -129,7 +144,7 @@ export function DiffTokenText(props: {
129144
fontStyle,
130145
backgroundColor:
131146
token.diffHighlight && props.change
132-
? diffHighlightColor(props.change)
147+
? diffHighlightColor(props.change, diffColorScheme)
133148
: undefined,
134149
borderRadius: token.diffHighlight ? 4 : undefined,
135150
}}

‎apps/mobile/src/features/review/useNativeReviewDiffBridge.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ export function useNativeReviewDiffBridge(input: {
3131
viewedFileIds,
3232
} = input;
3333
const { nativeReviewDiffStyle } = useAppearanceCodeSurface();
34-
const { themeAppearance: scheme, themeId } = useAppearancePreferences();
34+
const { themeAppearance: scheme, themeId, diffColorScheme } = useAppearancePreferences();
3535
const appTheme = useUniwindTheme();
3636
const [collapsedCommentIds, setCollapsedCommentIds] = useState<ReadonlySet<string>>(
3737
() => new Set(),
3838
);
3939

4040
const theme = useMemo(
41-
() => createNativeReviewDiffTheme(scheme, themeId, appTheme),
42-
[appTheme, scheme, themeId],
41+
() => createNativeReviewDiffTheme(scheme, themeId, appTheme, diffColorScheme),
42+
[appTheme, scheme, themeId, diffColorScheme],
4343
);
4444
const rowsJson = useMemo(() => JSON.stringify(data.rows), [data.rows]);
4545
const collapsedFileIdsJson = useMemo(() => JSON.stringify(collapsedFileIds), [collapsedFileIds]);

‎apps/mobile/src/features/settings/SettingsAppearanceRouteScreen.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useSafeAreaInsets } from "react-native-safe-area-context";
44

55
import { AndroidScreenHeader } from "../../components/AndroidScreenHeader";
66
import { NativeStackScreenOptions } from "../../native/StackHeader";
7+
import { DiffAppearanceSection } from "./appearance/sections/DiffAppearanceSection";
78
import { CodeAppearanceSection } from "./appearance/sections/CodeAppearanceSection";
89
import { TerminalAppearanceSection } from "./appearance/sections/TerminalAppearanceSection";
910
import { TextAppearanceSection } from "./appearance/sections/TextAppearanceSection";
@@ -31,6 +32,7 @@ export function SettingsAppearanceRouteScreen() {
3132
}}
3233
>
3334
<ThemeAppearanceSection />
35+
<DiffAppearanceSection />
3436
<TextAppearanceSection />
3537
<TerminalAppearanceSection />
3638
<CodeAppearanceSection />

‎apps/mobile/src/features/settings/appearance/AppearancePreferencesProvider.tsx‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ import {
3838
type MobileThemeRuntimeState,
3939
} from "../../../lib/mobileThemeRuntime";
4040

41+
import type { DiffColorScheme } from "@t3tools/contracts/settings";
42+
import { getDiffColors } from "../../../lib/diffColors";
43+
4144
interface AppearancePreferencesContextValue {
45+
readonly diffColorScheme: DiffColorScheme;
46+
readonly diffColors: ReturnType<typeof getDiffColors>;
47+
readonly setDiffColorScheme: (value: DiffColorScheme) => void;
4248
/** Effective values with base-size derivation applied. Use this for rendering. */
4349
readonly appearance: ResolvedAppearance;
4450
readonly themeId: MobileThemeId;
@@ -75,6 +81,16 @@ export function AppearancePreferencesProvider(props: { readonly children: ReactN
7581
);
7682
const themeMode = normalizeMobileThemeMode(storedPreferences?.themeMode);
7783
const themeAppearance = themeMode === "system" ? systemColorScheme : themeMode;
84+
const diffColorScheme =
85+
storedPreferences?.diffColorScheme === "blue-orange" ? "blue-orange" : "red-green";
86+
const diffColors = useMemo(
87+
() => getDiffColors(diffColorScheme, themeAppearance),
88+
[diffColorScheme, themeAppearance],
89+
);
90+
const setDiffColorScheme = useCallback(
91+
(value: DiffColorScheme) => savePreferences({ diffColorScheme: value }),
92+
[savePreferences],
93+
);
7894
const resolvedThemeIds = resolveMobileThemeIds(storedPreferences ?? {});
7995
const themeIds = useMemo<MobileThemeIds>(
8096
() => ({ light: resolvedThemeIds.light, dark: resolvedThemeIds.dark }),
@@ -229,6 +245,9 @@ export function AppearancePreferencesProvider(props: { readonly children: ReactN
229245
const value = useMemo(
230246
(): AppearancePreferencesContextValue => ({
231247
appearance,
248+
diffColorScheme,
249+
diffColors,
250+
setDiffColorScheme,
232251
themeId,
233252
themeIds,
234253
themeMode,
@@ -244,6 +263,9 @@ export function AppearancePreferencesProvider(props: { readonly children: ReactN
244263
}),
245264
[
246265
appearance,
266+
diffColorScheme,
267+
diffColors,
268+
setDiffColorScheme,
247269
themeId,
248270
themeIds,
249271
themeMode,
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { useMemo, useState } from "react";
2+
import { Pressable, View } from "react-native";
3+
4+
import { AppText as Text } from "../../../../components/AppText";
5+
import { cn } from "../../../../lib/cn";
6+
import { resolveNativeReviewDiffView } from "../../../diffs/nativeReviewDiffSurface";
7+
import { buildNativeReviewDiffData } from "../../../review/nativeReviewDiffAdapter";
8+
import { buildReviewParsedDiff } from "../../../review/reviewModel";
9+
import { useNativeReviewDiffBridge } from "../../../review/useNativeReviewDiffBridge";
10+
import { SettingsSection } from "../../components/SettingsSection";
11+
import { useAppearancePreferences } from "../AppearancePreferencesProvider";
12+
import { useAppearanceCodeSurface } from "../useAppearanceCodeSurface";
13+
import { AppearancePreviewSeparator } from "../components/AppearancePreviews";
14+
15+
const PREVIEW_DIFF = `diff --git a/greeting.ts b/greeting.ts
16+
--- a/greeting.ts
17+
+++ b/greeting.ts
18+
@@ -1,3 +1,3 @@
19+
function greet(name) {
20+
- return "Hi, " + name;
21+
+ return "Hello, " + name;
22+
}
23+
`;
24+
const PREVIEW_DATA = buildNativeReviewDiffData(buildReviewParsedDiff(PREVIEW_DIFF, "appearance"));
25+
const EMPTY_IDS: ReadonlyArray<string> = [];
26+
const OPTIONS = [
27+
{ value: "red-green", label: "Red & green" },
28+
{ value: "blue-orange", label: "Blue & orange" },
29+
] as const;
30+
31+
export function DiffAppearanceSection() {
32+
const { diffColorScheme, setDiffColorScheme, themeAppearance, isReady } =
33+
useAppearancePreferences();
34+
const { codeSurface, nativeReviewDiffStyle } = useAppearanceCodeSurface();
35+
const [width, setWidth] = useState(320);
36+
const [NativeReviewDiffView] = useState(resolveNativeReviewDiffView);
37+
const bridge = useNativeReviewDiffBridge({
38+
threadKey: null,
39+
sectionId: "appearance",
40+
diff: PREVIEW_DIFF,
41+
data: PREVIEW_DATA,
42+
collapsedFileIds: EMPTY_IDS,
43+
viewedFileIds: EMPTY_IDS,
44+
selectedRowIds: EMPTY_IDS,
45+
canHighlight: true,
46+
});
47+
const styleJson = useMemo(
48+
() => JSON.stringify({ ...nativeReviewDiffStyle, contentWidth: width }),
49+
[nativeReviewDiffStyle, width],
50+
);
51+
52+
return (
53+
<SettingsSection card title="Diff colors">
54+
{NativeReviewDiffView ? (
55+
<View
56+
pointerEvents="none"
57+
style={{ height: nativeReviewDiffStyle.fileHeaderHeight + codeSurface.rowHeight * 5 }}
58+
onLayout={(event) => setWidth(event.nativeEvent.layout.width)}
59+
>
60+
<NativeReviewDiffView
61+
style={{ flex: 1 }}
62+
appearanceScheme={themeAppearance}
63+
contentWidth={width}
64+
rowHeight={codeSurface.rowHeight}
65+
rowsJson={bridge.rowsJson}
66+
themeJson={bridge.themeJson}
67+
styleJson={styleJson}
68+
tokensPatchJson={bridge.tokensPatchJson}
69+
tokensResetKey={bridge.tokensResetKey}
70+
onDebug={bridge.onDebug}
71+
/>
72+
</View>
73+
) : null}
74+
<AppearancePreviewSeparator />
75+
<View className="flex-row gap-2 p-3">
76+
{OPTIONS.map((option) => (
77+
<Pressable
78+
key={option.value}
79+
accessibilityRole="radio"
80+
accessibilityLabel={option.label}
81+
accessibilityState={{ checked: diffColorScheme === option.value, disabled: !isReady }}
82+
disabled={!isReady}
83+
className={cn(
84+
"min-h-11 flex-1 items-center justify-center rounded-xl px-2",
85+
diffColorScheme === option.value ? "bg-subtle-strong" : "active:bg-subtle",
86+
)}
87+
onPress={() => setDiffColorScheme(option.value)}
88+
>
89+
<Text className="text-sm font-t3-medium text-foreground">{option.label}</Text>
90+
</Pressable>
91+
))}
92+
</View>
93+
</SettingsSection>
94+
);
95+
}

‎apps/mobile/src/features/threads/git/GitCommitSheet.tsx‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useAppearancePreferences } from "../../settings/appearance/AppearancePreferencesProvider";
12
import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
23
import { useCallback, useState } from "react";
34
import { Platform, Pressable, ScrollView, View } from "react-native";
@@ -20,6 +21,7 @@ type GitCommitSheetProps = StaticScreenProps<{
2021
}>;
2122

2223
export function GitCommitSheet(_props: GitCommitSheetProps) {
24+
const { diffColors } = useAppearancePreferences();
2325
const navigation = useNavigation();
2426
const insets = useSafeAreaInsets();
2527
const { selectedThread } = useThreadSelection();
@@ -130,8 +132,12 @@ export function GitCommitSheet(_props: GitCommitSheetProps) {
130132
<Text className="text-foreground flex-1 text-sm font-medium" numberOfLines={1}>
131133
{file.path}
132134
</Text>
133-
<Text className="text-xs font-t3-bold text-emerald-500">+{file.insertions}</Text>
134-
<Text className="text-xs font-t3-bold text-rose-500">-{file.deletions}</Text>
135+
<Text className="text-xs font-t3-bold" style={{ color: diffColors.addText }}>
136+
+{file.insertions}
137+
</Text>
138+
<Text className="text-xs font-t3-bold" style={{ color: diffColors.deleteText }}>
139+
-{file.deletions}
140+
</Text>
135141
</View>
136142
))}
137143
{selectedFiles.length > selectedFilePreview.length ? (
@@ -181,10 +187,16 @@ export function GitCommitSheet(_props: GitCommitSheetProps) {
181187
) : null}
182188
</View>
183189
<View className="items-end gap-1">
184-
<Text className="text-xs font-t3-bold text-emerald-500">
190+
<Text
191+
className="text-xs font-t3-bold"
192+
style={{ color: diffColors.addText }}
193+
>
185194
+{file.insertions}
186195
</Text>
187-
<Text className="text-xs font-t3-bold text-rose-500">
196+
<Text
197+
className="text-xs font-t3-bold"
198+
style={{ color: diffColors.deleteText }}
199+
>
188200
-{file.deletions}
189201
</Text>
190202
</View>

0 commit comments

Comments
 (0)