Skip to content

Commit f338f7e

Browse files
fix(mobile): align iOS segmented controls with action colors
1 parent 6cecd22 commit f338f7e

3 files changed

Lines changed: 22 additions & 11 deletions

File tree

‎apps/mobile/modules/t3-native-controls/ios/T3SegmentedControlView.swift‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ final class T3SegmentedControlView: ExpoView {
1515
}
1616
}
1717
var selectedIndex = -1 { didSet { updateSelection() } }
18-
var trackColor: UIColor = .secondarySystemBackground { didSet { control.backgroundColor = trackColor } }
19-
var selectedColor: UIColor = .secondarySystemFill { didSet { control.selectedSegmentTintColor = selectedColor } }
20-
var textColor: UIColor = .label { didSet { updateColors() } }
21-
var mutedColor: UIColor = .secondaryLabel { didSet { updateColors() } }
18+
var trackColor: UIColor = .secondarySystemBackground { didSet { if trackColor != oldValue { control.backgroundColor = trackColor } } }
19+
var selectedColor: UIColor = .secondarySystemFill { didSet { if selectedColor != oldValue { control.selectedSegmentTintColor = selectedColor } } }
20+
var textColor: UIColor = .label { didSet { if textColor != oldValue { updateColors() } } }
21+
var mutedColor: UIColor = .secondaryLabel { didSet { if mutedColor != oldValue { updateColors() } } }
2222
var appearance = "light" {
23-
didSet { overrideUserInterfaceStyle = appearance == "dark" ? .dark : .light }
23+
didSet {
24+
guard appearance != oldValue else { return }
25+
overrideUserInterfaceStyle = appearance == "dark" ? .dark : .light
26+
}
2427
}
2528

2629
required init(appContext: AppContext? = nil) {
@@ -31,11 +34,20 @@ final class T3SegmentedControlView: ExpoView {
3134

3235
override func layoutSubviews() {
3336
super.layoutSubviews()
34-
control.frame = bounds
37+
guard control.frame != bounds else { return }
38+
UIView.performWithoutAnimation {
39+
control.frame = bounds
40+
}
3541
}
3642

3743
private func updateSelection() {
38-
control.selectedSegmentIndex = labels.indices.contains(selectedIndex) ? selectedIndex : UISegmentedControl.noSegment
44+
let index = labels.indices.contains(selectedIndex) ? selectedIndex : UISegmentedControl.noSegment
45+
// React echoes native selections while UIKit is still settling the glass lens.
46+
guard control.selectedSegmentIndex != index else { return }
47+
UIView.performWithoutAnimation {
48+
control.selectedSegmentIndex = index
49+
control.layoutIfNeeded()
50+
}
3951
}
4052

4153
private func updateColors() {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ export function SegmentedControl<Value extends string | number>(
2929
) {
3030
const { colors, colorScheme } = useControlTheme();
3131
const trackColor = flattenThemeColor(
32-
themeColorWithAlpha(colors["--color-primary"], colorScheme === "dark" ? 0.18 : 0.07),
32+
themeColorWithAlpha(colors["--color-prominent-action"], colorScheme === "dark" ? 0.18 : 0.07),
3333
colors["--color-screen"],
3434
);
3535
const selectedColor =
36-
colorScheme === "dark" ? colors["--color-primary"] : colors["--color-secondary"];
36+
colorScheme === "dark" ? colors["--color-prominent-action"] : colors["--color-secondary"];
3737
const selectedTextColor =
3838
colorScheme === "dark"
39-
? colors["--color-primary-foreground"]
39+
? colors["--color-prominent-action-foreground"]
4040
: colors["--color-secondary-foreground"];
4141
return (
4242
<View className={props.className}>

‎apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,6 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
685685
>
686686
<PullRequestIdentity pr={identity} params={params} />
687687
<SegmentedControl
688-
className={Platform.OS === "android" ? undefined : "bg-grouped-card"}
689688
options={[
690689
{ value: "overview", label: "Overview" },
691690
...(guidesEnabled

0 commit comments

Comments
 (0)