Skip to content

Commit 20417ad

Browse files
Possibility to add custom snapshot generation logic
1 parent c3e3a78 commit 20417ad

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66
### ✅ Added
77
- Configuration for stack based navigation for iPads
88
- Customization of the reactions background
9+
- Possibility to add custom snapshot generation logic
910

1011
# [4.21.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.21.0)
1112
_September 02, 2022_

Sources/StreamChatSwiftUI/Utils/SnapshotCreator.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ public class DefaultSnapshotCreator: SnapshotCreator {
2121
public init() { /* Public init. */ }
2222

2323
public func makeSnapshot(for view: AnyView) -> UIImage {
24-
let currentSnapshot: UIImage?
25-
guard let view: UIView = topVC()?.view else {
24+
guard let uiView: UIView = topVC()?.view else {
2625
return images.snapshot
2726
}
27+
return makeSnapshot(from: uiView)
28+
}
29+
30+
func makeSnapshot(from view: UIView) -> UIImage {
31+
let currentSnapshot: UIImage?
2832
UIGraphicsBeginImageContext(view.frame.size)
2933
if let currentGraphicsContext = UIGraphicsGetCurrentContext() {
3034
view.layer.render(in: currentGraphicsContext)

StreamChatSwiftUITests/Tests/ChatChannel/MessageListView_Tests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ class MessageListView_Tests: StreamChatTestCase {
6060
assertSnapshot(matching: messageListView, as: .image)
6161
}
6262

63+
func test_messageListView_snapshot() {
64+
// Given
65+
let channelConfig = ChannelConfig(reactionsEnabled: true)
66+
let messageListView = makeMessageListView(channelConfig: channelConfig)
67+
.applyDefaultSize()
68+
69+
// When
70+
let snapshotCreator = DefaultSnapshotCreator()
71+
let viewController = UIHostingController(rootView: messageListView)
72+
let snapshot = snapshotCreator.makeSnapshot(from: viewController.view)
73+
let view = Image(uiImage: snapshot)
74+
75+
// Then
76+
assertSnapshot(matching: view, as: .image)
77+
}
78+
6379
func test_messageListView_snapshotFallback() {
6480
// Given
6581
let channelConfig = ChannelConfig(reactionsEnabled: true)
4.69 KB
Loading

0 commit comments

Comments
 (0)