Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Last active January 23, 2021 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azamsharp/482392fc3fde617684f2fb89edb37657 to your computer and use it in GitHub Desktop.
Save azamsharp/482392fc3fde617684f2fb89edb37657 to your computer and use it in GitHub Desktop.
struct CustomerListView: View {
let customers: [String]
let onSelected: ((String) -> Void)?
init(customers: [String], onSelected: ((String) -> Void)? = nil) {
self.customers = customers
self.onSelected = onSelected
}
var body: some View {
List(customers, id: \.self) { name in
HStack {
Text(name)
Spacer()
if onSelected != nil {
Image(systemName: "chevron.right")
}
}.contentShape(Rectangle())
.onTapGesture(perform: {
if let onSelected = onSelected {
onSelected(name)
}
})
}.listStyle(PlainListStyle())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment