Replace URLImage with AsyncImage

This commit is contained in:
Arkadiusz Fal
2021-07-27 23:26:52 +02:00
parent 33e102207f
commit 52ffe19324
7 changed files with 54 additions and 95 deletions

View File

@@ -1,6 +1,3 @@
import URLImage
import URLImageStore
import SwiftUI
struct VideoCellView: View {
@@ -12,13 +9,14 @@ struct VideoCellView: View {
Button(action: { navigationState.playVideo(video) }) {
VStack(alignment: .leading) {
ZStack {
if let thumbnail = video.thumbnailURL(quality: .high) {
// to replace with AsyncImage when it is fixed with lazy views
URLImage(thumbnail) { image in
if let url = video.thumbnailURL(quality: .high) {
AsyncImage(url: url) { image in
image
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 550, height: 310)
} placeholder: {
ProgressView()
}
.mask(RoundedRectangle(cornerRadius: 12))
} else {

View File

@@ -1,7 +1,6 @@
import Defaults
import Siesta
import SwiftUI
import URLImage
struct VideoDetailsView: View {
@Environment(\.dismiss) private var dismiss
@@ -36,13 +35,14 @@ struct VideoDetailsView: View {
VStack(alignment: .center) {
ZStack(alignment: .bottom) {
Group {
if let thumbnail = video.thumbnailURL(quality: .maxres) {
// to replace with AsyncImage when it is fixed with lazy views
URLImage(thumbnail) { image in
if let url = video.thumbnailURL(quality: .maxres) {
AsyncImage(url: url) { image in
image
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 1600, height: 800)
} placeholder: {
ProgressView()
}
}
}

View File

@@ -1,6 +1,4 @@
import SwiftUI
import URLImage
import URLImageStore
struct VideoListRowView: View {
@EnvironmentObject<NavigationState> private var navigationState
@@ -166,20 +164,13 @@ struct VideoListRowView: View {
) -> some View {
Group {
if let url = video.thumbnailURL(quality: quality) {
URLImage(url) {
EmptyView()
} inProgress: { _ in
ProgressView()
.progressViewStyle(CircularProgressViewStyle())
} failure: { _, retry in
VStack {
Button("Retry", action: retry)
}
} content: { image in
AsyncImage(url: url) { image in
image
.resizable()
.aspectRatio(contentMode: .fill)
.frame(minWidth: minWidth, maxWidth: maxWidth, minHeight: minHeight, maxHeight: maxHeight)
} placeholder: {
ProgressView()
}
.mask(RoundedRectangle(cornerRadius: 12))
} else {
@@ -201,3 +192,24 @@ struct VideoListRowView: View {
#endif
}
}
struct VideoListRowPreview: PreviewProvider {
static var previews: some View {
List {
VideoListRowView(video: Video.fixture)
VideoListRowView(video: Video.fixtureUpcomingWithoutPublishedOrViews)
VideoListRowView(video: Video.fixtureLiveWithoutPublishedOrViews)
}
.frame(maxWidth: 400)
#if os(iOS)
List {
VideoListRowView(video: Video.fixture)
VideoListRowView(video: Video.fixtureUpcomingWithoutPublishedOrViews)
VideoListRowView(video: Video.fixtureLiveWithoutPublishedOrViews)
}
.environment(\.verticalSizeClass, .compact)
.frame(maxWidth: 800)
#endif
}
}