Last active
January 23, 2021 18:42
-
-
Save azamsharp/482392fc3fde617684f2fb89edb37657 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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