mirror of
https://github.com/yattee/yattee.git
synced 2026-05-14 19:35:02 +00:00
Use menu-style pickers in tvOS settings
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.
This commit is contained in:
42
Yattee/Views/Settings/PlatformMenuPicker.swift
Normal file
42
Yattee/Views/Settings/PlatformMenuPicker.swift
Normal file
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// 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) }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user