Skip to content

Commit

Permalink
Add fallback to gif support
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Müller <[email protected]>
  • Loading branch information
SystemKeeper committed Sep 20, 2024
1 parent a4f3b7a commit 07dfa8b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions NextcloudTalk/ReferenceGiphyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
//

import Foundation
import SwiftyGif

@objcMembers class ReferenceGiphyView: UIView {
@objcMembers class ReferenceGiphyView: UIView, SwiftyGifDelegate {

@IBOutlet var contentView: UIView!
@IBOutlet weak var referenceThumbnailView: UIImageView!
Expand Down Expand Up @@ -65,7 +66,8 @@ import Foundation
}

if let proxiedUrlString = reference["proxied_url"] as? String, let proxiedUrl = URL(string: proxiedUrlString) {
referenceThumbnailView.setGifFromURL(proxiedUrl)
referenceThumbnailView.delegate = self
referenceThumbnailView.setGifFromURL(proxiedUrl, showLoader: false)
} else {
setPlaceholderThumbnail()
}
Expand All @@ -74,4 +76,13 @@ import Foundation
func setPlaceholderThumbnail() {
referenceThumbnailView.image = UIImage(systemName: "safari")?.withTintColor(UIColor.secondarySystemFill, renderingMode: .alwaysOriginal)
}

func gifURLDidFail(sender: UIImageView, url: URL, error: (any Error)?) {
// In case we were unable to load or process the gif, fall back to the normal thumbnail
if let request = NCAPIController.sharedInstance().createReferenceThumbnailRequest(forUrl: url.absoluteString) {
referenceThumbnailView.setImageWith(request, placeholderImage: nil, success: nil) { _, _, _ in
self.setPlaceholderThumbnail()
}
}
}
}

0 comments on commit 07dfa8b

Please sign in to comment.