Skip to content

Commit 0355824

Browse files
Added configuration of message size via spacing
1 parent 768725b commit 0355824

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
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
- Customizing padding for message bubble modifier
88
- Customizing padding for message text view
99
- Possibility to control tab bar visibility
10+
- Configuration of message size via spacing
1011

1112
### 🐞 Fixed
1213
- Fixed a bug with canceled backswipe

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageContainerView.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,7 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
244244
}
245245

246246
private var spacerWidth: CGFloat {
247-
let proposedViewWidth = width ?? 0
248-
if isIPad {
249-
return 2 * proposedViewWidth / 3
250-
} else {
251-
return proposedViewWidth / 4
252-
}
247+
messageListConfig.messageDisplayOptions.spacerWidth(width ?? 0)
253248
}
254249

255250
private var reactionsShown: Bool {

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListConfig.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public struct MessageDisplayOptions {
8585
public let otherUserMessageTransition: AnyTransition
8686
public let shouldAnimateReactions: Bool
8787
public let messageLinkDisplayResolver: (ChatMessage) -> [NSAttributedString.Key: Any]
88+
public let spacerWidth: (CGFloat) -> CGFloat
8889

8990
public init(
9091
showAvatars: Bool = true,
@@ -98,7 +99,8 @@ public struct MessageDisplayOptions {
9899
otherUserMessageTransition: AnyTransition = .identity,
99100
shouldAnimateReactions: Bool = true,
100101
messageLinkDisplayResolver: @escaping (ChatMessage) -> [NSAttributedString.Key: Any] = MessageDisplayOptions
101-
.defaultLinkDisplay
102+
.defaultLinkDisplay,
103+
spacerWidth: @escaping (CGFloat) -> CGFloat = MessageDisplayOptions.defaultSpacerWidth
102104
) {
103105
self.showAvatars = showAvatars
104106
self.showAuthorName = showAuthorName
@@ -111,6 +113,7 @@ public struct MessageDisplayOptions {
111113
self.messageLinkDisplayResolver = messageLinkDisplayResolver
112114
self.lastInGroupHeaderSize = lastInGroupHeaderSize
113115
self.shouldAnimateReactions = shouldAnimateReactions
116+
self.spacerWidth = spacerWidth
114117
}
115118

116119
public static var defaultLinkDisplay: (ChatMessage) -> [NSAttributedString.Key: Any] {
@@ -120,6 +123,16 @@ public struct MessageDisplayOptions {
120123
]
121124
}
122125
}
126+
127+
public static var defaultSpacerWidth: (CGFloat) -> (CGFloat) {
128+
{ availableWidth in
129+
if isIPad {
130+
return 2 * availableWidth / 3
131+
} else {
132+
return availableWidth / 4
133+
}
134+
}
135+
}
123136
}
124137

125138
/// Type of message list. Currently only `messaging` is supported.

0 commit comments

Comments
 (0)