Files
yattee/tvOS/ControlsOverlayButton.swift
Arkadiusz Fal 0913c6d73c Fix tvOS controls overlay button text legibility
Improved text contrast on overlay buttons by:
- Applying foreground color directly to button labels to ensure proper override
- Using semi-transparent gray background for unfocused buttons instead of Color.secondary
- Removing accent color overrides from caption text to respect button styling

This ensures readable text in both focused (black on white) and unfocused
(white on gray) states.
2025-11-22 23:40:23 +01:00

56 lines
1.7 KiB
Swift

import SwiftUI
struct ControlsOverlayButton<LabelView: View>: View {
var focusedField: FocusState<ControlsOverlay.Field?>.Binding
var field: ControlsOverlay.Field
let label: LabelView
var onSelect: (() -> Void)?
init(
focusedField: FocusState<ControlsOverlay.Field?>.Binding,
field: ControlsOverlay.Field,
onSelect: (() -> Void)? = nil,
@ViewBuilder label: @escaping () -> LabelView
) {
self.focusedField = focusedField
self.field = field
self.onSelect = onSelect
self.label = label()
}
var body: some View {
let isFocused = focusedField.wrappedValue == field
if let onSelect {
Button(action: onSelect) {
label
.foregroundColor(isFocused ? .black : .white)
.padding()
.frame(width: 400)
}
.buttonStyle(TVButtonStyle(isFocused: isFocused))
.focused(focusedField, equals: field)
} else {
label
.foregroundColor(isFocused ? .black : .white)
.padding()
.frame(width: 400)
.focusable()
.focused(focusedField, equals: field)
.background(isFocused ? Color.white : Color.gray.opacity(0.5))
.clipShape(RoundedRectangle(cornerRadius: 4))
}
}
}
struct TVButtonStyle: ButtonStyle {
let isFocused: Bool
func makeBody(configuration: Configuration) -> some View {
configuration.label
.background(isFocused ? Color.white : Color.gray.opacity(0.5))
.clipShape(RoundedRectangle(cornerRadius: 4))
.scaleEffect(configuration.isPressed ? 0.95 : 1.0)
}
}