Add disable for multiselect row

This commit is contained in:
Arkadiusz Fal 2022-08-14 19:02:36 +02:00
parent 601523ab1b
commit c23b42f76c

View File

@ -2,7 +2,8 @@ import SwiftUI
struct MultiselectRow: View { struct MultiselectRow: View {
let title: String let title: String
let selected: Bool var selected: Bool
var disabled = false
var action: (Bool) -> Void var action: (Bool) -> Void
@State private var toggleChecked = false @State private var toggleChecked = false
@ -16,6 +17,7 @@ struct MultiselectRow: View {
Spacer() Spacer()
} }
.onAppear { .onAppear {
guard !disabled else { return }
toggleChecked = selected toggleChecked = selected
} }
.onChange(of: toggleChecked) { new in .onChange(of: toggleChecked) { new in
@ -34,8 +36,9 @@ struct MultiselectRow: View {
} }
.contentShape(Rectangle()) .contentShape(Rectangle())
} }
.disabled(disabled)
#if !os(tvOS) #if !os(tvOS)
.buttonStyle(.plain) .buttonStyle(.plain)
#endif #endif
} }
} }