Skip to content

Commit 4b305c5

Browse files
committed
Fix Gif support which LazyImage dropped
1 parent fa2872a commit 4b305c5

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

Sources/StreamChatSwiftUI/ChatChannel/MessageList/GiphyAttachmentView.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ struct LazyGiphyView: View {
103103
var body: some View {
104104
LazyImage(imageURL: source) { state in
105105
if let imageContainer = state.imageContainer {
106-
Image(uiImage: imageContainer.image)
106+
if imageContainer.type == .gif {
107+
AnimatedGifView(imageContainer: imageContainer)
108+
.frame(width: width)
109+
} else {
110+
state.image
111+
}
107112
} else if state.error != nil {
108113
Color(.secondarySystemBackground)
109114
} else {
@@ -119,3 +124,18 @@ struct LazyGiphyView: View {
119124
.aspectRatio(contentMode: .fit)
120125
}
121126
}
127+
128+
private struct AnimatedGifView: UIViewRepresentable {
129+
let imageContainer: ImageContainer
130+
131+
func makeUIView(context: Context) -> UIImageView {
132+
let imageView = UIImageView()
133+
imageView.contentMode = .scaleAspectFit
134+
if let gifData = imageContainer.data, let image = try? UIImage(gifData: gifData) {
135+
imageView.setGifImage(image)
136+
}
137+
return imageView
138+
}
139+
140+
func updateUIView(_ uiView: UIImageView, context: Context) {}
141+
}

0 commit comments

Comments
 (0)