Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created February 17, 2023 06:47
Show Gist options
  • Select an option

  • Save sturdysturge/1840a803bac3351ea371292551746b22 to your computer and use it in GitHub Desktop.

Select an option

Save sturdysturge/1840a803bac3351ea371292551746b22 to your computer and use it in GitHub Desktop.
import SwiftUI
@available(iOS 16.0, *)
struct ContentView: View {
@ObservedObject var viewModel = ViewModel()
var body: some View {
NavigationStack {
List(viewModel.items) { item in
NavigationLink(value: item.fullID?.videoID) {
VStack {
AsyncImage(url: item.defaultThumbnailURL) { image in
image
.resizable()
.scaledToFit()
} placeholder: { ProgressView() }
Text(item.snippet?.title ?? "???")
}
}
}
.navigationDestination(for: String.self) { videoID in
YTPlayer(videoID: videoID)
.aspectRatio(1.3, contentMode: .fit)
.frame(maxHeight:.infinity, alignment: .top)
}
}
.submitLabel(.search)
.searchable(text: $viewModel.search)
.onSubmit(of: .search, viewModel.performSearch)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment