SelectableRowView.swift (1112B)
1 // 2 // File.swift 3 // damus 4 // 5 // Created by devandsev on 2/4/23. 6 // 7 8 import SwiftUI 9 10 struct SelectableRowView <Content: View>: View { 11 12 @Binding var isSelected: Bool 13 var shouldChangeSelection: () -> Bool 14 var content: () -> Content 15 16 @available(iOS, deprecated: 16, message: "In iOS 15 List rows selection works only in editing mode; with iOS 16 selection doesn't require Edit button at all. Consider using standard selection mechanism when deployment target is iOS 16") 17 init(isSelected: Binding<Bool>, shouldChangeSelection: @escaping () -> Bool = { true }, @ViewBuilder content: @escaping () -> Content) { 18 _isSelected = isSelected 19 self.shouldChangeSelection = shouldChangeSelection 20 self.content = content 21 } 22 23 var body: some View { 24 HStack { 25 content() 26 Spacer() 27 Image(systemName: isSelected ? "checkmark.circle.fill" : "circle") 28 } 29 .contentShape(Rectangle()) 30 .onTapGesture { 31 if shouldChangeSelection() { 32 isSelected.toggle() 33 } 34 } 35 } 36 }