Skip to content

Commit 5517c99

Browse files
committed
fix(mobile): soften dark segmented selections
1 parent 5c70db3 commit 5517c99

4 files changed

Lines changed: 16 additions & 6 deletions

File tree

‎apps/mobile/src/components/ui/SegmentedControl.ios.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ const NativeSegmentedControl = requireNativeView<
2424
export function SegmentedControl<Value extends string | number>(
2525
props: SegmentedControlProps<Value>,
2626
) {
27-
const { colors, colorScheme } = useControlTheme();
27+
const { colors, colorScheme, themeId } = useControlTheme();
2828
// UIKit adds a gray fill over the sunken card track.
2929
if (props.variant === "card") return <FlatSegmentedControl {...props} />;
3030
const { trackColor, selectedColor, selectedTextColor, mutedColor } = segmentedControlColors(
3131
colors,
3232
colorScheme,
3333
props.variant,
3434
"ios",
35+
themeId,
3536
);
3637
return (
3738
<View className={props.className}>

‎apps/mobile/src/components/ui/SegmentedControl.shared.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type { SegmentedControlProps } from "./SegmentedControl.types";
1212
export function SegmentedControl<Value extends string | number>(
1313
props: SegmentedControlProps<Value>,
1414
) {
15-
const { colorScheme, colors } = useControlTheme();
15+
const { colorScheme, colors, themeId } = useControlTheme();
1616
const [layout, setLayout] = useState({ width: 0, height: 0 });
1717
const { width } = layout;
1818
const reduceMotion = useReducedMotion();
@@ -28,6 +28,7 @@ export function SegmentedControl<Value extends string | number>(
2828
colorScheme,
2929
props.variant,
3030
Platform.OS,
31+
themeId,
3132
);
3233
const minHeight = props.size === "compact" ? 32 : Platform.OS === "android" ? 40 : 36;
3334

‎apps/mobile/src/components/ui/segmentedControlColors.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
themeColorWithAlpha,
55
themeColorWithContrast,
66
type MobileThemeAppearance,
7+
type MobileThemeId,
78
type MobileThemeVariables,
89
} from "../../lib/mobileTheme";
910
import type { SegmentedControlProps } from "./SegmentedControl.types";
@@ -13,6 +14,7 @@ export function segmentedControlColors(
1314
appearance: MobileThemeAppearance,
1415
variant: SegmentedControlProps<string>["variant"],
1516
platform: string,
17+
themeId: MobileThemeId,
1618
) {
1719
const dark = appearance === "dark";
1820
const card = variant === "card";
@@ -24,14 +26,19 @@ export function segmentedControlColors(
2426
colors["--color-grouped-card"],
2527
)
2628
: flattenThemeColor(
27-
themeColorWithAlpha(colors["--color-prominent-action"], dark ? 0.18 : 0.07),
29+
themeColorWithAlpha(colors["--color-prominent-action"], dark ? 0.1 : 0.07),
2830
colors["--color-screen"],
2931
);
3032
let selectedColor = colors["--color-secondary"];
3133
if (card && !dark) selectedColor = colors["--color-screen"];
32-
if (!card && dark) selectedColor = colors["--color-prominent-action"];
34+
if (dark && (!card || themeId === "t3-code")) {
35+
selectedColor = flattenThemeColor(
36+
themeColorWithAlpha(colors["--color-prominent-action"], 0.32),
37+
colors["--color-screen"],
38+
);
39+
}
3340
let selectedTextColor =
34-
colors[!card && dark ? "--color-prominent-action-foreground" : "--color-secondary-foreground"];
41+
colors[!card && dark ? "--color-foreground" : "--color-secondary-foreground"];
3542
if (!card && !dark && platform === "android") {
3643
const selection = colors["--color-thread-selected"];
3744
if (

‎apps/mobile/src/components/ui/useControlTheme.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { useAppearancePreferences } from "../../features/settings/appearance/AppearancePreferencesProvider";
22

33
export function useControlTheme() {
4-
const { themeAppearance, themeVariables, systemColorsActive, appearance } =
4+
const { themeId, themeAppearance, themeVariables, systemColorsActive, appearance } =
55
useAppearancePreferences();
66
return {
7+
themeId,
78
colorScheme: themeAppearance,
89
colors: themeVariables,
910
systemColorsActive,

0 commit comments

Comments
 (0)