Skip to content

Commit 346643b

Browse files
Added composer config for changing frames
1 parent 93298dd commit 346643b

File tree

6 files changed

+61
-6
lines changed

6 files changed

+61
-6
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Copyright © 2022 Stream.io Inc. All rights reserved.
3+
//
4+
5+
import SwiftUI
6+
7+
/// Config for customizing the composer.
8+
public struct ComposerConfig {
9+
10+
public var inputViewMinHeight: CGFloat
11+
public var inputFont: UIFont
12+
13+
public init(
14+
inputViewMinHeight: CGFloat = 38,
15+
inputFont: UIFont = UIFont.preferredFont(forTextStyle: .body)
16+
) {
17+
self.inputViewMinHeight = inputViewMinHeight
18+
self.inputFont = inputFont
19+
}
20+
}

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerView.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public struct ComposerInputView<Factory: ViewFactory>: View {
292292
}
293293
.padding(.vertical, shouldAddVerticalPadding ? 8 : 0)
294294
.padding(.leading, 8)
295-
.background(Color(colors.background))
295+
.background(composerInputBackground)
296296
.overlay(
297297
RoundedRectangle(cornerRadius: 20)
298298
.stroke(Color(colors.innerBorder))
@@ -302,6 +302,11 @@ public struct ComposerInputView<Factory: ViewFactory>: View {
302302
)
303303
}
304304

305+
private var composerInputBackground: Color {
306+
var colors = colors
307+
return Color(colors.composerInputBackground)
308+
}
309+
305310
private var shouldAddVerticalPadding: Bool {
306311
!addedFileURLs.isEmpty || !addedAssets.isEmpty
307312
}

Sources/StreamChatSwiftUI/ColorPalette.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public struct ColorPalette {
7777
public lazy var reactionCurrentUserColor: UIColor? = UIColor(tintColor)
7878
public lazy var reactionOtherUserColor: UIColor? = textLowEmphasis
7979
public lazy var selectedReactionBackgroundColor: UIColor? = nil
80+
81+
// MARK: - Composer
82+
83+
public lazy var composerPlaceholderColor: UIColor = subtitleText
84+
public lazy var composerInputBackground: UIColor = background
8085
}
8186

8287
// Those colors are default defined stream constants, which are fallback values if you don't implement your color theme.

Sources/StreamChatSwiftUI/Utils.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class Utils {
1919
public var messageActionsResolver: MessageActionsResolving
2020
public var commandsConfig: CommandsConfig
2121
public var messageListConfig: MessageListConfig
22+
public var composerConfig: ComposerConfig
2223

2324
var messageCachingUtils = MessageCachingUtils()
2425

@@ -34,6 +35,7 @@ public class Utils {
3435
messageActionResolver: MessageActionsResolving = MessageActionsResolver(),
3536
commandsConfig: CommandsConfig = DefaultCommandsConfig(),
3637
messageListConfig: MessageListConfig = MessageListConfig(),
38+
composerConfig: ComposerConfig = ComposerConfig(),
3739
channelNamer: @escaping ChatChannelNamer = DefaultChatChannelNamer()
3840
) {
3941
self.dateFormatter = dateFormatter
@@ -48,5 +50,6 @@ public class Utils {
4850
messageActionsResolver = messageActionResolver
4951
self.commandsConfig = commandsConfig
5052
self.messageListConfig = messageListConfig
53+
self.composerConfig = composerConfig
5154
}
5255
}

Sources/StreamChatSwiftUI/Utils/Common/InputTextView.swift

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,22 @@
55
import UIKit
66

77
struct TextSizeConstants {
8-
static let minimumHeight = 38.0
9-
static let maximumHeight = 76.0
10-
static let minThreshold = 38.0
8+
static let composerConfig = InjectedValues[\.utils].composerConfig
9+
static let defaultInputViewHeight: CGFloat = 38.0
10+
static var minimumHeight: CGFloat {
11+
composerConfig.inputViewMinHeight
12+
}
13+
14+
static let maximumHeight: CGFloat = 76
15+
static var minThreshold: CGFloat {
16+
composerConfig.inputViewMinHeight
17+
}
1118
}
1219

1320
class InputTextView: UITextView {
1421
@Injected(\.colors) private var colors
15-
22+
@Injected(\.utils) private var utils
23+
1624
/// Label used as placeholder for textView when it's empty.
1725
open private(set) lazy var placeholderLabel: UILabel = UILabel()
1826
.withoutAutoresizingMaskConstraints
@@ -62,7 +70,7 @@ class InputTextView: UITextView {
6270
open func setUpAppearance() {
6371
backgroundColor = .clear
6472
textContainer.lineFragmentPadding = 8
65-
font = UIFont.preferredFont(forTextStyle: .body)
73+
font = utils.composerConfig.inputFont
6674
textColor = colors.text
6775
textAlignment = .natural
6876

@@ -130,6 +138,16 @@ class InputTextView: UITextView {
130138
}
131139
}
132140

141+
override func layoutSubviews() {
142+
super.layoutSubviews()
143+
144+
if TextSizeConstants.defaultInputViewHeight != minimumHeight {
145+
let rect = layoutManager.usedRect(for: textContainer)
146+
let topInset = (bounds.size.height - rect.height) / 2.0
147+
textContainerInset.top = max(0, topInset)
148+
}
149+
}
150+
133151
override open func paste(_ sender: Any?) {
134152
super.paste(sender)
135153
handleTextChange()

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
84335018274BAD4B007A1B81 /* NewChatViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84335017274BAD4B007A1B81 /* NewChatViewModel.swift */; };
3838
8434E58127707F19001E1B83 /* GridPhotosView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8434E58027707F19001E1B83 /* GridPhotosView.swift */; };
3939
8434E583277088D9001E1B83 /* TitleWithCloseButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8434E582277088D9001E1B83 /* TitleWithCloseButton.swift */; };
40+
844CC60E2811378D0006548D /* ComposerConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844CC60D2811378D0006548D /* ComposerConfig.swift */; };
4041
8465FBBE2746873A00AF091E /* StreamChatSwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8465FBB52746873A00AF091E /* StreamChatSwiftUI.framework */; };
4142
8465FCB727468B0600AF091E /* NukeUI in Frameworks */ = {isa = PBXBuildFile; productRef = 8465FCB627468B0600AF091E /* NukeUI */; };
4243
8465FCBF27468B6900AF091E /* DemoAppSwiftUIApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8465FCBE27468B6900AF091E /* DemoAppSwiftUIApp.swift */; };
@@ -369,6 +370,7 @@
369370
84335017274BAD4B007A1B81 /* NewChatViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewChatViewModel.swift; sourceTree = "<group>"; };
370371
8434E58027707F19001E1B83 /* GridPhotosView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridPhotosView.swift; sourceTree = "<group>"; };
371372
8434E582277088D9001E1B83 /* TitleWithCloseButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleWithCloseButton.swift; sourceTree = "<group>"; };
373+
844CC60D2811378D0006548D /* ComposerConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposerConfig.swift; sourceTree = "<group>"; };
372374
8465FBB52746873A00AF091E /* StreamChatSwiftUI.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = StreamChatSwiftUI.framework; sourceTree = BUILT_PRODUCTS_DIR; };
373375
8465FBBD2746873A00AF091E /* StreamChatSwiftUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = StreamChatSwiftUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
374376
8465FCBC27468B6900AF091E /* DemoAppSwiftUI.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DemoAppSwiftUI.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -909,6 +911,7 @@
909911
8465FD1A2746A95600AF091E /* ComposerHelperViews.swift */,
910912
841B64C327744DB60016FF3B /* ComposerModels.swift */,
911913
8465FD182746A95600AF091E /* PhotoAssetsUtils.swift */,
914+
844CC60D2811378D0006548D /* ComposerConfig.swift */,
912915
);
913916
path = Composer;
914917
sourceTree = "<group>";
@@ -1565,6 +1568,7 @@
15651568
8465FD6F2746A95700AF091E /* StreamChat.swift in Sources */,
15661569
8465FD8F2746A95700AF091E /* AttachmentUploadingStateView.swift in Sources */,
15671570
8465FD732746A95700AF091E /* ActionItemView.swift in Sources */,
1571+
844CC60E2811378D0006548D /* ComposerConfig.swift in Sources */,
15681572
846608E5278C865200D3D7B3 /* TypingIndicatorPlacement.swift in Sources */,
15691573
8465FDA72746A95700AF091E /* KeyboardHandling.swift in Sources */,
15701574
8465FDD72746A95800AF091E /* Appearance.swift in Sources */,

0 commit comments

Comments
 (0)