Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace GIFs with new GIF viewer #1437

Merged
merged 10 commits into from
Aug 29, 2024
Prev Previous commit
Next Next commit
upgrade SDWebImageSwiftUI; add some comments
  • Loading branch information
joshuatbrown committed Aug 27, 2024
commit 8e67ef9dc4895858c7dc69882a3f55f1c6bc779c
2 changes: 1 addition & 1 deletion Nos.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3233,7 +3233,7 @@
repositoryURL = "https://github.com/SDWebImage/SDWebImageSwiftUI";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 2.0.0;
minimumVersion = 3.0.0;
};
};
C9ADB139299299570075E7F8 /* XCRemoteSwiftPackageReference "bech32" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/SDWebImage/SDWebImageSwiftUI",
"state" : {
"revision" : "53573d6dd017e354c0e7d8f1c86b77ef1383c996",
"version" : "2.2.7"
"revision" : "5d462f7530677ae0c2b9510c26383aa25ba48751",
"version" : "3.1.1"
}
},
{
Expand Down
21 changes: 14 additions & 7 deletions Nos/Views/AvatarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@ struct AvatarView: View {
var size: CGFloat

var body: some View {
WebImage(url: imageUrl)
.resizable()
.placeholder {
WebImage(
url: imageUrl,
content: { image in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an API change on SDWebImage? It stinks that we have to duplicate a bunch of the view modifiers now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, unfortunately the old API is gone. I can look and see if we can do anything better, or maybe try to unduplicate the view modifiers.

image
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: size, height: size)
.clipShape(Circle())
},
placeholder: {
Image.emptyAvatar
.resizable()
.renderingMode(.original)
.aspectRatio(contentMode: .fill)
.frame(width: size, height: size)
.clipShape(Circle())
}
.indicator(.activity)
.aspectRatio(contentMode: .fill)
.frame(width: size, height: size)
.clipShape(Circle())
)
}
}

Expand Down
26 changes: 15 additions & 11 deletions Nos/Views/Components/Media/ImageButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,25 @@ struct ImageButton: View {
if url.pathExtension == "gif" {
ZStack {
// RIDICULOUS! When the value of $isAnimating is `false`, you can never start animating the image.
// Adding the `context` here fixes the problem.
// See [my bug report](https://github.com/SDWebImage/SDWebImageSwiftUI/issues/332) for updates.
WebImage(url: url, context: [.animatedImageClass: SDAnimatedImage.self], isAnimating: $isAnimating)
.resizable()
.scaledToFill()

Button {
isAnimating = true
} label: {
Text(.localizable.gifButton)
.font(.title)
.foregroundStyle(Color.primaryTxt)
.padding()
.background(
Circle()
.fill(Color.gifButtonBackground)
)
if !isAnimating {
Button {
isAnimating = true
} label: {
Text(.localizable.gifButton)
.font(.title)
.foregroundStyle(Color.primaryTxt)
.padding()
.background(
Circle()
.fill(Color.gifButtonBackground)
)
}
}
}
} else {
Expand Down