This repository has been archived by the owner on Sep 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
feat: 🎸 gif supported by SDWebImage #32
Merged
MarcoEidinger
merged 3 commits into
SAP:devBreaking
from
ShadowTourist:change-urlimage-to-sdwebimage
Sep 3, 2021
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -87,7 +87,7 @@ curl -X POST "<BaseUrl>/connect/v1/channels" \ | |||||
|
||||||
- [SAPCommon](https://help.sap.com/doc/978e4f6c968c4cc5a30f9d324aa4b1d7/Latest/en-US/Documents/Frameworks/SAPCommon/index.html) for Logging | ||||||
- [SAPFoundation](https://help.sap.com/doc/978e4f6c968c4cc5a30f9d324aa4b1d7/Latest/en-US/Documents/Frameworks/SAPFoundation/index.html) for Network Connectivity and Authentication | ||||||
- [URLImage](https://github.com/dmytro-anokhin/url-image) for asynchronous image loading in SwiftUI | ||||||
- [SDWebImage](https://github.com/SDWebImage/SDWebImage) for asynchronous image loading in SwiftUI | ||||||
- [Down](https://github.com/johnxnguyen/Down) for Markdown / CommonMark rendering in Swift | ||||||
|
||||||
## Installation | ||||||
|
@@ -146,6 +146,9 @@ AssistantView() | |||||
.onDisappear { | ||||||
viewModel.cancelSubscriptions() | ||||||
dataPublisher.resetConversation() | ||||||
//Clear SDImage Cache | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
SDImageCache.shared.clearMemory() | ||||||
SDImageCache.shared.clearDisk(onCompletion: nil) | ||||||
}) | ||||||
``` | ||||||
|
||||||
|
@@ -196,7 +199,6 @@ You can also provide an alternative color palette or provide a custom theme. | |||||
### Image related | ||||||
|
||||||
- Not being able to save, copy, or share an image as part of a bot response. Currently, there is no gesture handler attached to an image view which could allow opening a contextual menu offering such features (similar to iMessage or WhatsApp). | ||||||
- Animated images (GIF), as part of a bot response, will be viewed as a static image (dependency to https://github.com/dmytro-anokhin/url-image/issues/43) | ||||||
|
||||||
## How to obtain support | ||||||
|
||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import Combine | ||
import SDWebImage | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is needed here. If so please remove |
||
import SwiftUI | ||
|
||
/// SwiftUI main view. Use this when you want a full screen out-of-the box view that contains: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
Sources/SAPCAI/UI/Common/UIKit/ImageViewRepresentable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import SDWebImage | ||
import SwiftUI | ||
|
||
struct ImageViewRepresentable: UIViewRepresentable { | ||
var url: URL? | ||
var imageManager: ImageManager | ||
let wrapper = UIImageViewWrapper() | ||
|
||
func makeUIView(context: Self.Context) -> UIImageViewWrapper { | ||
self.wrapper | ||
} | ||
|
||
func updateUIView(_ uiView: UIImageViewWrapper, context: UIViewRepresentableContext<ImageViewRepresentable>) { | ||
uiView.imageView.contentMode = self.imageManager.contentMode | ||
if case ImageManager.ImageState.error = self.imageManager.state, uiView.imageView.image == nil { | ||
self.loadImage() | ||
} | ||
} | ||
|
||
func loadImage() { | ||
self.wrapper.imageView.sd_setImage(with: self.url, | ||
placeholderImage: nil) { image, error, _, _ in | ||
if let error = error { | ||
imageManager.state = .error(error) | ||
} else if let image = image { | ||
imageManager.state = .completed(image: image) | ||
} else { | ||
imageManager.state = .error(NSError(domain: "cai.com", code: 1, userInfo: nil)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
class UIImageViewWrapper: UIView { | ||
lazy var imageView: UIImageView = { | ||
let imageView = UIImageView() | ||
imageView.setContentCompressionResistancePriority(.defaultLow, for: .horizontal) | ||
imageView.setContentCompressionResistancePriority(.defaultLow, for: .vertical) | ||
imageView.setContentHuggingPriority(.defaultLow, for: .vertical) | ||
imageView.setContentHuggingPriority(.defaultLow, for: .horizontal) | ||
return imageView | ||
}() | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
addSubview(self.imageView) | ||
self.imageView.bindFrameToSuperviewBounds() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
super.init(coder: coder) | ||
addSubview(self.imageView) | ||
self.imageView.bindFrameToSuperviewBounds() | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.