yattee/Apple TV/TrendingCountrySelectionView.swift

28 lines
782 B
Swift
Raw Normal View History

2021-06-17 10:02:39 +00:00
import SwiftUI
struct TrendingCountrySelectionView: View {
@State private var query: String = ""
2021-06-28 10:43:07 +00:00
@ObservedObject private var store = Store<[Country]>()
2021-06-17 10:02:39 +00:00
@Binding var selectedCountry: Country
2021-06-26 23:29:55 +00:00
@Environment(\.dismiss) private var dismiss
2021-06-17 10:02:39 +00:00
2021-06-26 23:29:55 +00:00
var body: some View {
ScrollView(.vertical) {
2021-06-28 10:43:07 +00:00
ForEach(store.collection) { country in
2021-06-26 23:29:55 +00:00
Button(country.name) {
selectedCountry = country
2021-06-28 10:43:07 +00:00
dismiss()
2021-06-17 10:02:39 +00:00
}
}
2021-06-26 23:29:55 +00:00
.frame(width: 800)
2021-06-17 10:02:39 +00:00
}
2021-06-28 10:43:07 +00:00
.searchable(text: $query, prompt: Text("Country name or two letter code"))
.onChange(of: query) { newQuery in
store.replace(Country.search(newQuery))
}
2021-06-26 23:29:55 +00:00
.background(.thinMaterial)
2021-06-17 10:02:39 +00:00
}
}