Use Nuke where relevant

This commit is contained in:
Thomas Ricouard 2022-12-25 07:43:02 +01:00
parent 4be33b4f67
commit e569bb1d74
11 changed files with 75 additions and 60 deletions

View file

@ -18,6 +18,15 @@
"revision" : "32a99b537d1c6f3529a08257c28a5feb70c0c5af"
}
},
{
"identity" : "nuke",
"kind" : "remoteSourceControl",
"location" : "https://github.com/kean/Nuke",
"state" : {
"revision" : "1e7395a8931ad19659fd1e10137a862b9c1e2a38",
"version" : "11.5.0"
}
},
{
"identity" : "swiftui-shimmer",
"kind" : "remoteSourceControl",

View file

@ -2,6 +2,9 @@ import SwiftUI
import Models
import DesignSystem
import Env
import Shimmer
import Nuke
import NukeUI
struct AccountDetailHeaderView: View {
@EnvironmentObject private var theme: Theme
@ -29,20 +32,21 @@ struct AccountDetailHeaderView: View {
private var headerImageView: some View {
GeometryReader { proxy in
ZStack(alignment: .bottomTrailing) {
AsyncImage(
url: account.header,
content: { image in
image.resizable()
.aspectRatio(contentMode: .fill)
LazyImage(url: account.header) { state in
if let image = state.image {
image
.resizingMode(.aspectFill)
} else if state.isLoading {
Color.gray
.frame(height: bannerHeight)
.frame(width: proxy.frame(in: .local).width)
.clipped()
},
placeholder: {
.shimmering()
} else {
Color.gray
.frame(height: bannerHeight)
}
)
}
.frame(height: bannerHeight)
if relationship?.followedBy == true {
Text("Follows You")
.font(.footnote)

View file

@ -16,14 +16,16 @@ let package = Package(
dependencies: [
.package(name: "Models", path: "../Models"),
.package(name: "Env", path: "../Env"),
.package(url: "https://github.com/markiv/SwiftUI-Shimmer", exact: "1.1.0")],
.package(url: "https://github.com/markiv/SwiftUI-Shimmer", exact: "1.1.0"),
.package(url: "https://github.com/kean/Nuke", from: "11.5.0")],
targets: [
.target(
name: "DesignSystem",
dependencies: [
.product(name: "Models", package: "Models"),
.product(name: "Env", package: "Env"),
.product(name: "Shimmer", package: "SwiftUI-Shimmer")
.product(name: "Shimmer", package: "SwiftUI-Shimmer"),
.product(name: "NukeUI", package: "Nuke")
]),
]
)

View file

@ -1,5 +1,7 @@
import SwiftUI
import Shimmer
import NukeUI
import Nuke
public struct AvatarView: View {
public enum Size {
@ -41,22 +43,20 @@ public struct AvatarView: View {
.fill(.gray)
.frame(maxWidth: size.size.width, maxHeight: size.size.height)
} else {
AsyncImage(url: url) { phase in
switch phase {
case .empty:
LazyImage(url: url) { state in
if let image = state.image {
image
.resizingMode(.aspectFit)
} else if state.isLoading {
placeholderView
.shimmering()
case let .success(image):
image.resizable()
.aspectRatio(contentMode: .fit)
.cornerRadius(size.cornerRadius)
.frame(maxWidth: size.size.width, maxHeight: size.size.height)
case .failure:
placeholderView
@unknown default:
} else {
placeholderView
}
}
.processors([ImageProcessors.Resize(size: size.size),
ImageProcessors.RoundedCorners(radius: size.cornerRadius)])
.frame(width: size.size.width, height: size.size.height)
}
}

View file

@ -19,7 +19,7 @@ let package = Package(
.package(name: "Models", path: "../Models"),
.package(name: "Env", path: "../Env"),
.package(name: "Status", path: "../Status"),
.package(url: "https://github.com/markiv/SwiftUI-Shimmer", exact: "1.1.0")
.package(name: "DesignSystem", path: "../DesignSystem"),
],
targets: [
.target(
@ -30,7 +30,7 @@ let package = Package(
.product(name: "Models", package: "Models"),
.product(name: "Env", package: "Env"),
.product(name: "Status", package: "Status"),
.product(name: "Shimmer", package: "SwiftUI-Shimmer")
.product(name: "DesignSystem", package: "DesignSystem")
])
]
)

View file

@ -1,23 +1,27 @@
import Foundation
import SwiftUI
import Nuke
import NukeUI
@MainActor
extension Account {
public var displayNameWithEmojis: some View {
let splittedDisplayName = displayName.split(separator: ":")
return HStack(spacing: 0) {
ForEach(splittedDisplayName, id: \.self) { part in
if let emoji = emojis.first(where: { $0.shortcode == part }) {
AsyncImage(
url: emoji.url,
content: { image in
image.resizable()
.aspectRatio(contentMode: .fit)
.frame(maxWidth: 20, maxHeight: 20)
},
placeholder: {
LazyImage(url: emoji.url) { state in
if let image = state.image {
image
.resizingMode(.aspectFit)
} else if state.isLoading {
ProgressView()
} else {
ProgressView()
}
)
}
.processors([ImageProcessors.Resize(size: .init(width: 20, height: 20))])
.frame(width: 20, height: 20)
} else {
Text(part)
}

View file

@ -18,7 +18,7 @@ let package = Package(
.package(name: "Models", path: "../Models"),
.package(name: "Env", path: "../Env"),
.package(name: "Status", path: "../Status"),
.package(url: "https://github.com/markiv/SwiftUI-Shimmer", exact: "1.1.0")
.package(name: "DesignSystem", path: "../DesignSystem"),
],
targets: [
.target(
@ -28,7 +28,7 @@ let package = Package(
.product(name: "Models", package: "Models"),
.product(name: "Env", package: "Env"),
.product(name: "Status", package: "Status"),
.product(name: "Shimmer", package: "SwiftUI-Shimmer")
.product(name: "DesignSystem", package: "DesignSystem")
]),
]
)

View file

@ -18,7 +18,6 @@ let package = Package(
.package(name: "Network", path: "../Network"),
.package(name: "Env", path: "../Env"),
.package(name: "DesignSystem", path: "../DesignSystem"),
.package(url: "https://github.com/markiv/SwiftUI-Shimmer", exact: "1.1.0"),
.package(url: "https://github.com/Dimillian/TextView", branch: "main")
],
targets: [
@ -29,7 +28,6 @@ let package = Package(
.product(name: "Network", package: "Network"),
.product(name: "Env", package: "Env"),
.product(name: "DesignSystem", package: "DesignSystem"),
.product(name: "Shimmer", package: "SwiftUI-Shimmer"),
.product(name: "TextView", package: "TextView")
]),
]

View file

@ -1,6 +1,8 @@
import SwiftUI
import Models
import Shimmer
import Nuke
import NukeUI
public struct StatusCardView: View {
@Environment(\.openURL) private var openURL
@ -14,21 +16,18 @@ public struct StatusCardView: View {
if let title = card.title {
VStack(alignment: .leading) {
if let imageURL = card.image {
AsyncImage(
url: imageURL,
content: { image in
image.resizable()
.aspectRatio(contentMode: .fill)
.frame(maxHeight: 200)
.clipped()
},
placeholder: {
LazyImage(url: imageURL) { state in
if let image = state.image {
image
.resizingMode(.aspectFill)
} else if state.isLoading {
Rectangle()
.fill(Color.gray)
.frame(height: 200)
.shimmering()
}
)
}
.frame(height: 200)
}
Spacer()
HStack {

View file

@ -2,6 +2,8 @@ import SwiftUI
import Models
import Env
import Shimmer
import Nuke
import NukeUI
public struct StatusMediaPreviewView: View {
@EnvironmentObject private var quickLook: QuickLook
@ -89,24 +91,21 @@ public struct StatusMediaPreviewView: View {
GeometryReader { proxy in
switch type {
case .image:
AsyncImage(
url: attachement.url,
content: { image in
LazyImage(url: attachement.url) { state in
if let image = state.image {
image
.resizable()
.aspectRatio(contentMode: attachements.count == 1 ? .fit : .fill)
.frame(height: imageMaxHeight)
.frame(width: proxy.frame(in: .local).width)
.resizingMode(.aspectFill)
.cornerRadius(4)
},
placeholder: {
} else if state.isLoading {
RoundedRectangle(cornerRadius: 4)
.fill(Color.gray)
.frame(maxHeight: imageMaxHeight)
.frame(width: proxy.frame(in: .local).width)
.shimmering()
}
)
}
.frame(width: proxy.frame(in: .local).width)
.frame(height: imageMaxHeight)
case .gifv:
VideoPlayerView(viewModel: .init(url: attachement.url))
.frame(width: proxy.frame(in: .local).width)

View file

@ -18,7 +18,7 @@ let package = Package(
.package(name: "Models", path: "../Models"),
.package(name: "Env", path: "../Env"),
.package(name: "Status", path: "../Status"),
.package(url: "https://github.com/markiv/SwiftUI-Shimmer", exact: "1.1.0")
.package(name: "DesignSystem", path: "../DesignSystem"),
],
targets: [
.target(
@ -28,7 +28,7 @@ let package = Package(
.product(name: "Models", package: "Models"),
.product(name: "Env", package: "Env"),
.product(name: "Status", package: "Status"),
.product(name: "Shimmer", package: "SwiftUI-Shimmer")
.product(name: "DesignSystem", package: "DesignSystem")
]),
.testTarget(
name: "TimelineTests",