1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-14 06:10:32 +05:30

Fix quality profile form

This commit is contained in:
Arkadiusz Fal 2022-08-15 00:15:18 +02:00
parent 263f0e63a6
commit 4a5cdf2d03
2 changed files with 62 additions and 38 deletions

View File

@ -1,7 +1,7 @@
import SwiftUI import SwiftUI
struct QualityProfileForm: View { struct QualityProfileForm: View {
var qualityProfileID: QualityProfile.ID! @Binding var qualityProfileID: QualityProfile.ID?
@Environment(\.colorScheme) private var colorScheme @Environment(\.colorScheme) private var colorScheme
@Environment(\.presentationMode) private var presentationMode @Environment(\.presentationMode) private var presentationMode
@ -23,31 +23,18 @@ struct QualityProfileForm: View {
} }
var body: some View { var body: some View {
ScrollView { VStack {
VStack { Group {
Group { header
header form
#if os(iOS) footer
NavigationView {
EmptyView()
form
.navigationBarHidden(true)
.navigationBarTitle(Text("Back"))
.edgesIgnoringSafeArea([.top, .bottom])
}
.navigationViewStyle(.stack)
#else
form
#endif
footer
}
.frame(maxWidth: 1000)
} }
#if os(tvOS) .frame(maxWidth: 1000)
.padding(20)
#endif
} }
#if os(tvOS)
.padding(20)
#endif
.onAppear(perform: initializeForm) .onAppear(perform: initializeForm)
.onChange(of: backend, perform: backendChanged) .onChange(of: backend, perform: backendChanged)
.onChange(of: formats) { _ in validate() } .onChange(of: formats) { _ in validate() }
@ -80,15 +67,20 @@ struct QualityProfileForm: View {
} }
var form: some View { var form: some View {
#if !os(tvOS) #if os(tvOS)
ScrollView {
VStack {
formFields
}
.padding(.horizontal, 20)
}
#else
Form { Form {
formFields formFields
#if os(macOS) #if os(macOS)
.padding(.horizontal) .padding(.horizontal)
#endif #endif
} }
#else
formFields
#endif #endif
} }
@ -121,8 +113,6 @@ struct QualityProfileForm: View {
@ViewBuilder var nameHeader: some View { @ViewBuilder var nameHeader: some View {
#if os(macOS) #if os(macOS)
Text("Name") Text("Name")
#else
EmptyView()
#endif #endif
} }
@ -132,13 +122,30 @@ struct QualityProfileForm: View {
.fixedSize(horizontal: false, vertical: true) .fixedSize(horizontal: false, vertical: true)
} }
var qualityPicker: some View { @ViewBuilder var qualityPicker: some View {
Picker("Resolution", selection: $resolution) { let picker = Picker("Resolution", selection: $resolution) {
ForEach(availableResolutions, id: \.self) { resolution in ForEach(availableResolutions, id: \.self) { resolution in
Text(resolution.description).tag(resolution) Text(resolution.description).tag(resolution)
} }
} }
.modifier(SettingsPickerModifier()) .modifier(SettingsPickerModifier())
#if os(iOS)
return HStack {
Text("Resolution")
Spacer()
Menu {
picker
} label: {
Text(resolution.description)
.frame(minWidth: 120, alignment: .trailing)
}
.transaction { t in t.animation = .none }
}
#else
return picker
#endif
} }
#if os(tvOS) #if os(tvOS)
@ -160,13 +167,29 @@ struct QualityProfileForm: View {
ResolutionSetting.allCases.filter { !isResolutionDisabled($0) } ResolutionSetting.allCases.filter { !isResolutionDisabled($0) }
} }
var backendPicker: some View { @ViewBuilder var backendPicker: some View {
Picker("Backend", selection: $backend) { let picker = Picker("Backend", selection: $backend) {
ForEach(PlayerBackendType.allCases, id: \.self) { backend in ForEach(PlayerBackendType.allCases, id: \.self) { backend in
Text(backend.label).tag(backend) Text(backend.label).tag(backend)
} }
} }
.modifier(SettingsPickerModifier()) .modifier(SettingsPickerModifier())
#if os(iOS)
return HStack {
Text("Backend")
Spacer()
Menu {
picker
} label: {
Text(backend.label)
.frame(minWidth: 120, alignment: .trailing)
}
.transaction { t in t.animation = .none }
}
#else
return picker
#endif
} }
@ViewBuilder var formatsPicker: some View { @ViewBuilder var formatsPicker: some View {
@ -307,6 +330,7 @@ struct QualityProfileForm: View {
struct QualityProfileForm_Previews: PreviewProvider { struct QualityProfileForm_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
QualityProfileForm(qualityProfileID: QualityProfile.defaultProfile.id) QualityProfileForm(qualityProfileID: .constant(QualityProfile.defaultProfile.id))
.environment(\.navigationStyle, .tab)
} }
} }

View File

@ -3,7 +3,7 @@ import SwiftUI
struct QualitySettings: View { struct QualitySettings: View {
@State private var presentingProfileForm = false @State private var presentingProfileForm = false
@State private var editedProfile: QualityProfile? @State private var editedProfileID: QualityProfile.ID?
@Default(.qualityProfiles) private var qualityProfiles @Default(.qualityProfiles) private var qualityProfiles
@ -25,7 +25,7 @@ struct QualitySettings: View {
#endif #endif
} }
.sheet(isPresented: $presentingProfileForm) { .sheet(isPresented: $presentingProfileForm) {
QualityProfileForm(qualityProfileID: editedProfile?.id) QualityProfileForm(qualityProfileID: $editedProfileID)
} }
#if os(tvOS) #if os(tvOS)
.frame(maxWidth: 1000) .frame(maxWidth: 1000)
@ -68,7 +68,7 @@ struct QualitySettings: View {
profilesList profilesList
Button { Button {
editedProfile = nil editedProfileID = nil
presentingProfileForm = true presentingProfileForm = true
} label: { } label: {
Label("Add profile...", systemImage: "plus") Label("Add profile...", systemImage: "plus")
@ -130,7 +130,7 @@ struct QualitySettings: View {
#endif #endif
} }
Button { Button {
editedProfile = qualityProfile editedProfileID = qualityProfile.id
presentingProfileForm = true presentingProfileForm = true
} label: { } label: {
Label("Edit...", systemImage: "pencil") Label("Edit...", systemImage: "pencil")