8000 Change the solution a bit to avoid breaking changes · GetStream/stream-chat-swiftui@6e08e36 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6e08e36

Browse files
committed
Change the solution a bit to avoid breaking changes
1 parent 72a66b9 commit 6e08e36

File tree

6 files changed

+11
-14
lines changed

6 files changed

+11
-14
lines changed

Sources/StreamChatSwiftUI/ChatChannel/Composer/ComposerTextInputView.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import UIKit
77

88
/// SwiftUI wrapper for a text field with multiple rows.
99
struct ComposerTextInputView: UIViewRepresentable {
10-
10+
@EnvironmentObject var composerViewModel: MessageComposerViewModel
1111
@Injected(\.utils) private var utils
1212

1313
@Binding var text: String
@@ -18,7 +18,6 @@ struct ComposerTextInputView: UIViewRepresentable {
1818
var editable: Bool
1919
var maxMessageLength: Int?
2020
var currentHeight: CGFloat
21-
var onImagePasted: ((UIImage) -> Void)?
2221

2322
func makeUIView(context: Context) -> InputTextView {
2423
let inputTextView: InputTextView
@@ -34,7 +33,9 @@ struct ComposerTextInputView: UIViewRepresentable {
3433
inputTextView.placeholderLabel.text = placeholder
3534
inputTextView.contentInsetAdjustmentBehavior = .never
3635
inputTextView.setContentCompressionResistancePriority(.streamLow, for: .horizontal)
37-
inputTextView.onImagePasted = onImagePasted
36+
inputTextView.onImagePasted = {
37+
composerViewModel.imagePasted($0)
38+
}
3839

3940
if utils.messageListConfig.becomesFirstResponderOnOpen {
4041
inputTextView.becomeFirstResponder()

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,9 @@ public struct ComposerInputView<Factory: ViewFactory>: View, KeyboardReadable {
372372
placeholder: isInCooldown ? L10n.Composer.Placeholder.slowMode : L10n.Composer.Placeholder.message,
373373
editable: !isInCooldown,
374374
maxMessageLength: maxMessageLength,
375-
currentHeight: textFieldHeight,
376-
onImagePasted: viewModel.imagePasted(_:)
375+
currentHeight: textFieldHeight
377376
)
377+
.environmentObject(viewModel)
378378
.accessibilityIdentifier("ComposerTextInputView")
379379
.accessibilityElement(children: .contain)
380380
.frame(height: textFieldHeight)

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ open class MessageComposerViewModel: ObservableObject {
511511
}
512512

513513
public func imagePasted(_ image: UIImage) {
514-
guard let imageURL = try? image.temporaryLocalFileUrl() else {
514+
guard let imageURL = try? image.saveAsJpgToTemporaryUrl() else {
515515
log.error("Failed to write image to local temporary file")
516516
return
517517
}

Sources/StreamChatSwiftUI/DefaultViewFactory.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,7 @@ extension ViewFactory {
632632
placeholder: String,
633633
editable: Bool,
634634
maxMessageLength: Int?,
635-
currentHeight: CGFloat,
636-
onImagePasted: ((UIImage) -> Void)?
635+
currentHeight: CGFloat
637636
) -> some View {
638637
ComposerTextInputView(
639638
text: text,
@@ -642,8 +641,7 @@ extension ViewFactory {
642641
placeholder: placeholder,
643642
editable: editable,
644643
maxMessageLength: maxMessageLength,
645-
currentHeight: currentHeight,
646-
onImagePasted: onImagePasted
644+
currentHeight: currentHeight
647645
)
648646
}
649647

Sources/StreamChatSwiftUI/ViewFactory.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,7 @@ public protocol ViewFactory: AnyObject {
651651
placeholder: String,
652652
editable: Bool,
653653
maxMessageLength: Int?,
654-
currentHeight: CGFloat,
655-
onImagePasted: ((UIImage) -> Void)?
654+
currentHeight: CGFloat
656655
) -> ComposerTextInputViewType
657656

658657
associatedtype TrailingComposerViewType: View

StreamChatSwiftUITests/Tests/Utils/ViewFactory_Tests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,8 +832,7 @@ class ViewFactory_Tests: StreamChatTestCase {
832832
placeholder: "Send a message",
833833
editable: true,
834834
maxMessageLength: nil,
835-
currentHeight: 40,
836-
onImagePasted: nil
835+
currentHeight: 40
837836
)
838837

839838
// Then

0 commit comments

Comments
 (0)
0