Skip to content

Commit 812472f

Browse files
Added config for composer text input paddings
1 parent 6849ca2 commit 812472f

File tree

5 files changed

+70
-2
lines changed

5 files changed

+70
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1010
### ✅ Added
1111
- Add message preview with attachments in channel list
1212
- Add support for pre-built XCFramework
13+
- Config for composer text input paddings
1314

1415
### 🐞 Fixed
1516
- Made some `ChannelList` and `MessageListView` parameters optional

Sources/StreamChatSwiftUI/ChatChannel/Composer/ComposerConfig.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public struct ComposerConfig {
1313
public var inputViewCornerRadius: CGFloat
1414
public var inputFont: UIFont
1515
public var gallerySupportedTypes: GallerySupportedTypes
16+
public var inputPaddingsConfig: PaddingsConfig
1617
public var adjustMessageOnSend: (String) -> (String)
1718
public var adjustMessageOnRead: (String) -> (String)
1819
public var attachmentPayloadConverter: (ChatMessage) -> [AnyAttachmentPayload]
@@ -23,6 +24,7 @@ public struct ComposerConfig {
2324
inputViewCornerRadius: CGFloat = 20,
2425
inputFont: UIFont = UIFont.preferredFont(forTextStyle: .body),
2526
gallerySupportedTypes: GallerySupportedTypes = .imagesAndVideo,
27+
inputPaddingsConfig: PaddingsConfig = .composerInput,
2628
adjustMessageOnSend: @escaping (String) -> (String) = { $0 },
2729
adjustMessageOnRead: @escaping (String) -> (String) = { $0 },
2830
attachmentPayloadConverter: @escaping (ChatMessage) -> [AnyAttachmentPayload]
@@ -36,6 +38,7 @@ public struct ComposerConfig {
3638
self.adjustMessageOnRead = adjustMessageOnRead
3739
self.attachmentPayloadConverter = attachmentPayloadConverter
3840
self.gallerySupportedTypes = gallerySupportedTypes
41+
self.inputPaddingsConfig = inputPaddingsConfig
3942
}
4043

4144
public static var defaultAttachmentPayloadConverter: (ChatMessage) -> [AnyAttachmentPayload] = { message in
@@ -48,3 +51,34 @@ public enum GallerySupportedTypes {
4851
case images
4952
case videos
5053
}
54+
55+
public struct PaddingsConfig {
56+
public let top: CGFloat
57+
public let bottom: CGFloat
58+
public let leading: CGFloat
59+
public let trailing: CGFloat
60+
61+
public var horizontal: CGFloat {
62+
leading + trailing
63+
}
64+
65+
public var vertical: CGFloat {
66+
top + bottom
67+
}
68+
69+
public init(top: CGFloat, bottom: CGFloat, leading: CGFloat, trailing: CGFloat) {
70+
self.top = top
71+
self.bottom = bottom
72+
self.leading = leading
73+
self.trailing = trailing
74+
}
75+
}
76+
77+
extension PaddingsConfig {
78+
public static let composerInput = PaddingsConfig(
79+
top: 4,
80+
bottom: 4,
81+
leading: 8,
82+
trailing: 0
83+
)
84+
}

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerView.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ public struct ComposerInputView<Factory: ViewFactory>: View {
197197
@Injected(\.colors) private var colors
198198
@Injected(\.fonts) private var fonts
199199
@Injected(\.images) private var images
200+
@Injected(\.utils) private var utils
200201

201202
var factory: Factory
202203
@Binding var text: String
@@ -255,6 +256,10 @@ public struct ComposerInputView<Factory: ViewFactory>: View {
255256

256257
return textHeight
257258
}
259+
260+
var inputPaddingsConfig: PaddingsConfig {
261+
utils.composerConfig.inputPaddingsConfig
262+
}
258263

259264
public var body: some View {
260265
VStack {
@@ -340,8 +345,9 @@ public struct ComposerInputView<Factory: ViewFactory>: View {
340345
}
341346
.frame(height: textFieldHeight)
342347
}
343-
.padding(.vertical, shouldAddVerticalPadding ? 8 : 0)
344-
.padding(.leading, 8)
348+
.padding(.vertical, shouldAddVerticalPadding ? inputPaddingsConfig.vertical : 0)
349+
.padding(.leading, inputPaddingsConfig.leading)
350+
.padding(.trailing, inputPaddingsConfig.trailing)
345351
.background(composerInputBackground)
346352
.overlay(
347353
RoundedRectangle(cornerRadius: TextSizeConstants.cornerRadius)

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@
311311
8492975227B156D100A8EEB0 /* SlowModeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8492975127B156D000A8EEB0 /* SlowModeView.swift */; };
312312
8492975427B1725B00A8EEB0 /* MessageComposerView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8492975327B1725B00A8EEB0 /* MessageComposerView_Tests.swift */; };
313313
849894952AD96CCC004ACB41 /* ChatChannelListItemView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849894942AD96CCC004ACB41 /* ChatChannelListItemView_Tests.swift */; };
314+
849988B02AE6BE4800CC95C9 /* PaddingsConfig_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849988AF2AE6BE4800CC95C9 /* PaddingsConfig_Tests.swift */; };
314315
849CDD942768E0E1003C7A51 /* MessageActionsResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849CDD932768E0E1003C7A51 /* MessageActionsResolver.swift */; };
315316
849FD5112811B05C00952934 /* ChatInfoParticipantsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849FD5102811B05C00952934 /* ChatInfoParticipantsView.swift */; };
316317
84A1CACD2816BC420046595A /* ChatChannelInfoHelperViews.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A1CACC2816BC420046595A /* ChatChannelInfoHelperViews.swift */; };
@@ -814,6 +815,7 @@
814815
8492975127B156D000A8EEB0 /* SlowModeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SlowModeView.swift; sourceTree = "<group>"; };
815816
8492975327B1725B00A8EEB0 /* MessageComposerView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageComposerView_Tests.swift; sourceTree = "<group>"; };
816817
849894942AD96CCC004ACB41 /* ChatChannelListItemView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatChannelListItemView_Tests.swift; sourceTree = "<group>"; };
818+
849988AF2AE6BE4800CC95C9 /* PaddingsConfig_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaddingsConfig_Tests.swift; sourceTree = "<group>"; };
817819
849CDD932768E0E1003C7A51 /* MessageActionsResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageActionsResolver.swift; sourceTree = "<group>"; };
818820
849FD5102811B05C00952934 /* ChatInfoParticipantsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatInfoParticipantsView.swift; sourceTree = "<group>"; };
819821
84A1CACC2816BC420046595A /* ChatChannelInfoHelperViews.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatChannelInfoHelperViews.swift; sourceTree = "<group>"; };
@@ -1905,6 +1907,7 @@
19051907
84C94D61275A5BB7007FE2B9 /* ChatChannelNamer_Tests.swift */,
19061908
91B79FD8284E7E9C005B6E4F /* ChatUserNamer_Tests.swift */,
19071909
84E1D8272976CCAF00060491 /* SortReactions_Tests.swift */,
1910+
849988AF2AE6BE4800CC95C9 /* PaddingsConfig_Tests.swift */,
19081911
);
19091912
path = Utils;
19101913
sourceTree = "<group>";
@@ -2582,6 +2585,7 @@
25822585
84C94D4D2758FD5C007FE2B9 /* MessageComposerViewModel_Tests.swift in Sources */,
25832586
84C94D62275A5BB7007FE2B9 /* ChatChannelNamer_Tests.swift in Sources */,
25842587
840A3F3828193AB20084E9CC /* ChatChannelInfoView_Tests.swift in Sources */,
2588+
849988B02AE6BE4800CC95C9 /* PaddingsConfig_Tests.swift in Sources */,
25852589
84C94D492758BE1C007FE2B9 /* ChatChannelViewModel_Tests.swift in Sources */,
25862590
842F036D288E93BF00496D49 /* ChatMessage_AdjustedText_Tests.swift in Sources */,
25872591
84507C98281AC40F0081DDC2 /* AddUsersViewModel_Tests.swift in Sources */,
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// Copyright © 2023 Stream.io Inc. All rights reserved.
3+
//
4+
5+
import StreamChat
6+
@testable import StreamChatSwiftUI
7+
import XCTest
8+
9+
final class PaddingsConfig_Tests: XCTestCase {
10+
11+
func test_paddingsConfig() {
12+
// Given
13+
let paddingsConfig = PaddingsConfig(top: 4, bottom: 4, leading: 8, trailing: 8)
14+
15+
// Then
16+
XCTAssert(paddingsConfig.horizontal == 16)
17+
XCTAssert(paddingsConfig.vertical == 8)
18+
XCTAssert(paddingsConfig.bottom == 4)
19+
XCTAssert(paddingsConfig.top == 4)
20+
XCTAssert(paddingsConfig.leading == 8)
21+
XCTAssert(paddingsConfig.trailing == 8)
22+
}
23+
}

0 commit comments

Comments
 (0)