是否可以让 HStack 将带有图像和标题的 json 文件加载到视图中,当点击时将链接的视频加载到默认播放器中,而不使用列表?我已经用 List 完成了这项工作,但是我似乎找不到创建可用水平视图的方法。
当前列表代码:
struct VideoList: View {
@ObservedObject private(set) var viewModel: ViewModel
@State private var isRefreshing = false
var body: some View {
NavigationView {
List(viewModel.videos.sorted { $0.id > $1.id}, id: \.id) { video in
NavigationLink(
destination: VideoDetails(viewModel: VideoDetails.ViewModel(video: video))) {
VideoRow(video: video)
}
}
.onPullToRefresh(isRefreshing: $isRefreshing, perform: {
self.viewModel.fetchVideos()
})
.onReceive(viewModel.$videos, perform: { _ in
self.isRefreshing = false
})
.navigationBarTitle(viewModel.navigationBarTitle)
}
.onAppear(perform: viewModel.fetchVideos)
}
}
JSON文件:
{
"videos": [
{
"id": 87,
"name": "Title 2",
"thumbnail": "https://videodelivery.net/,
"video_link": "https://videodelivery.net/"
},
{
"id": 86,
"name": "Title one",
"thumbnail": "https://videodelivery.net/",
"video_link": "https://videodelivery.net/"
}
]
"videos section 2": [
{
"id": 52,
"name": "Title 2",
"thumbnail": "https://videodelivery.net/,
"video_link": "https://videodelivery.net/"
},
{
"id": 16,
"name": "Title one",
"thumbnail": "https://videodelivery.net/",
"video_link": "https://videodelivery.net/"
}
]
}