Skip to content

Commit f50d1a4

Browse files
authored
Add support for overriding onImageTap in LinkAttachmentView (#986)
* Add support for overriding onImageTap in LinkAttachmentView * Update CHANGELOG.md
1 parent 5fc1b8d commit f50d1a4

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
77
- Opens the `commandsHandler` and makes the mention methods public [#979](https://github.com/GetStream/stream-chat-swiftui/pull/979)
88
- Opens `MarkdownFormatter` so that it can be customised [#978](https://github.com/GetStream/stream-chat-swiftui/pull/978)
99
- Add participant actions in channel info view [#982](https://github.com/GetStream/stream-chat-swiftui/pull/982)
10+
- Add support for overriding `onImageTap` in `LinkAttachmentView` [#986](https://github.com/GetStream/stream-chat-swiftui/pull/986)
1011

1112
### 🐞 Fixed
1213
- Fix openChannel not working when searching or another chat shown [#975](https://github.com/GetStream/stream-chat-swiftui/pull/975)

Sources/StreamChatSwiftUI/ChatChannel/MessageList/LinkAttachmentView.swift

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public struct LinkAttachmentContainer<Factory: ViewFactory>: View {
1414
var message: ChatMessage
1515
var width: CGFloat
1616
var isFirst: Bool
17+
var onImageTap: ((ChatMessageLinkAttachment) -> Void)?
1718
@Binding var scrolledId: String?
1819

1920
private let padding: CGFloat = 8
@@ -23,12 +24,14 @@ public struct LinkAttachmentContainer<Factory: ViewFactory>: View {
2324
message: ChatMessage,
2425
width: CGFloat,
2526
isFirst: Bool,
26-
scrolledId: Binding<String?>
27+
scrolledId: Binding<String?>,
28+
onImageTap: ((ChatMessageLinkAttachment) -> Void)? = nil
2729
) {
2830
self.factory = factory
2931
self.message = message
3032
self.width = width
3133
self.isFirst = isFirst
34+
self.onImageTap = onImageTap
3235
_scrolledId = scrolledId
3336
}
3437

@@ -69,7 +72,8 @@ public struct LinkAttachmentContainer<Factory: ViewFactory>: View {
6972
LinkAttachmentView(
7073
linkAttachment: message.linkAttachments[0],
7174
width: width,
72-
isFirst: isFirst
75+
isFirst: isFirst,
76+
onImageTap: onImageTap
7377
)
7478
}
7579
}
@@ -97,11 +101,18 @@ public struct LinkAttachmentView: View {
97101
var linkAttachment: ChatMessageLinkAttachment
98102
var width: CGFloat
99103
var isFirst: Bool
100-
101-
public init(linkAttachment: ChatMessageLinkAttachment, width: CGFloat, isFirst: Bool) {
104+
var onImageTap: ((ChatMessageLinkAttachment) -> Void)?
105+
106+
public init(
107+
linkAttachment: ChatMessageLinkAttachment,
108+
width: CGFloat,
109+
isFirst: Bool,
110+
onImageTap: ((ChatMessageLinkAttachment) -> Void)? = nil
111+
) {
102112
self.linkAttachment = linkAttachment
103113
self.width = width
104114
self.isFirst = isFirst
115+
self.onImageTap = onImageTap
105116
}
106117

107118
public var body: some View {
@@ -149,6 +160,10 @@ public struct LinkAttachmentView: View {
149160
}
150161
.padding(.horizontal, padding)
151162
.onTapGesture {
163+
if let onImageTap {
164+
onImageTap(linkAttachment)
165+
return
166+
}
152167
if let url = linkAttachment.originalURL.secureURL, UIApplication.shared.canOpenURL(url) {
153168
UIApplication.shared.open(url, options: [:])
154169
}

0 commit comments

Comments
 (0)