mirror of
https://github.com/yattee/yattee.git
synced 2025-11-24 18:28:20 +00:00
Changed context menus from press-and-hold to single-press for better UX: - Quality profile selection - Stream quality selection - Captions selection - Audio track selection Updated ControlsOverlayButton to support tap actions via new onSelect parameter. Replaced .contextMenu modifiers with .alert for instant menu access on tvOS. Removed hint text and unnecessary 80px padding as single-press is self-evident.
56 lines
1.7 KiB
Swift
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
|
|
.padding()
|
|
.frame(width: 400)
|
|
}
|
|
.buttonStyle(TVButtonStyle(isFocused: isFocused))
|
|
.focused(focusedField, equals: field)
|
|
} else {
|
|
label
|
|
.padding()
|
|
.frame(width: 400)
|
|
.focusable()
|
|
.focused(focusedField, equals: field)
|
|
.background(isFocused ? Color.white : Color.secondary)
|
|
.foregroundColor(isFocused ? Color.black : Color.white)
|
|
.clipShape(RoundedRectangle(cornerRadius: 4))
|
|
}
|
|
}
|
|
}
|
|
|
|
struct TVButtonStyle: ButtonStyle {
|
|
let isFocused: Bool
|
|
|
|
func makeBody(configuration: Configuration) -> some View {
|
|
configuration.label
|
|
.background(isFocused ? Color.white : Color.secondary)
|
|
.foregroundColor(isFocused ? Color.black : Color.white)
|
|
.clipShape(RoundedRectangle(cornerRadius: 4))
|
|
.scaleEffect(configuration.isPressed ? 0.95 : 1.0)
|
|
}
|
|
}
|