mirror of
https://github.com/yattee/yattee.git
synced 2026-05-12 18:35:05 +00:00
Introduce PlatformMenuPicker that wraps short-option pickers in LabeledContent + .pickerStyle(.menu) on tvOS so they render as a compact dropdown instead of pushing a full-screen option list. On iOS/macOS it falls through to a plain Picker, leaving rendering unchanged. Applied across Playback, Subtitles, Sidebar, Privacy, and Advanced settings. Long language lists in PlaybackSettingsView are left as push-style.
43 lines
1.2 KiB
Swift
43 lines
1.2 KiB
Swift
//
|
|
// PlatformMenuPicker.swift
|
|
// Yattee
|
|
//
|
|
// A Picker wrapper that renders as a compact menu inside LabeledContent on tvOS,
|
|
// and as a standard inline Picker on iOS/macOS. Use this for short option lists
|
|
// in settings forms so tvOS shows a dropdown menu rather than pushing a sub-view.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct PlatformMenuPicker<Selection: Hashable, Label: View, Content: View>: View {
|
|
@Binding var selection: Selection
|
|
@ViewBuilder var content: () -> Content
|
|
@ViewBuilder var label: () -> Label
|
|
|
|
var body: some View {
|
|
#if os(tvOS)
|
|
LabeledContent {
|
|
Picker(selection: $selection, content: content) { EmptyView() }
|
|
.pickerStyle(.menu)
|
|
.labelsHidden()
|
|
} label: {
|
|
label()
|
|
}
|
|
#else
|
|
Picker(selection: $selection, content: content, label: label)
|
|
#endif
|
|
}
|
|
}
|
|
|
|
extension PlatformMenuPicker where Label == Text {
|
|
init(
|
|
_ titleKey: String,
|
|
selection: Binding<Selection>,
|
|
@ViewBuilder content: @escaping () -> Content
|
|
) {
|
|
self._selection = selection
|
|
self.content = content
|
|
self.label = { Text(titleKey) }
|
|
}
|
|
}
|