Skip to content

Commit aeed58f

Browse files
Improvements to the composer view
1 parent 6779033 commit aeed58f

File tree

4 files changed

+45
-25
lines changed

4 files changed

+45
-25
lines changed

Sources/StreamChatSwiftUI/ChatChannel/Composer/AddedImageAttachmentsView.swift

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,45 @@ public struct AddedImageAttachmentsView: View {
2323
}
2424

2525
public var body: some View {
26-
ScrollView(.horizontal) {
27-
HStack {
28-
ForEach(images) { attachment in
29-
Image(uiImage: attachment.image)
30-
.resizable()
31-
.aspectRatio(contentMode: .fill)
32-
.frame(width: imageSize, height: imageSize)
33-
.clipped()
34-
.cornerRadius(12)
35-
.overlay(
36-
ZStack {
37-
DiscardAttachmentButton(
38-
attachmentIdentifier: attachment.id,
39-
onDiscard: onDiscardAttachment
40-
)
41-
42-
if attachment.type == .video {
43-
VideoIndicatorView()
26+
ScrollViewReader { reader in
27+
ScrollView(.horizontal) {
28+
HStack {
29+
ForEach(images) { attachment in
30+
Image(uiImage: attachment.image)
31+
.resizable()
32+
.aspectRatio(contentMode: .fill)
33+
.frame(width: imageSize, height: imageSize)
34+
.clipped()
35+
.cornerRadius(12)
36+
.id(attachment.id)
37+
.overlay(
38+
ZStack {
39+
DiscardAttachmentButton(
40+
attachmentIdentifier: attachment.id,
41+
onDiscard: onDiscardAttachment
42+
)
4443

45-
if let duration = attachment.extraData["duration"] as? String {
46-
VideoDurationIndicatorView(duration: duration)
44+
if attachment.type == .video {
45+
VideoIndicatorView()
46+
47+
if let duration = attachment.extraData["duration"] as? String {
48+
VideoDurationIndicatorView(duration: duration)
49+
}
4750
}
4851
}
49-
}
50-
)
52+
)
53+
}
54+
}
55+
}
56+
.frame(height: imageSize)
57+
.onChange(of: images) { [images] newValue in
58+
if newValue.count > images.count {
59+
let last = newValue.last
60+
withAnimation {
61+
reader.scrollTo(last?.id, anchor: .trailing)
62+
}
5163
}
5264
}
5365
}
54-
.frame(height: imageSize)
5566
}
5667
}

Sources/StreamChatSwiftUI/ChatChannel/Composer/AttachmentPickerView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public struct AttachmentPickerView<Factory: ViewFactory>: View {
4444
onAssetTap: onAssetTap,
4545
isAssetSelected: isAssetSelected
4646
)
47+
.edgesIgnoringSafeArea(.bottom)
4748
} else {
4849
viewFactory.makeAssetsAccessPermissionView()
4950
}

Sources/StreamChatSwiftUI/ChatChannel/Composer/ComposerHelperViews.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,15 @@ struct CameraPickerDisplayView: View {
9797

9898
var body: some View {
9999
Spacer()
100-
.sheet(isPresented: $cameraPickerShown, onDismiss: {
100+
.fullScreenCover(isPresented: $cameraPickerShown, onDismiss: {
101101
selectedPickerState = .photos
102102
}) {
103103
ImagePickerView(sourceType: .camera) { addedImage in
104104
cameraImageAdded(addedImage)
105105
}
106+
.background(
107+
Color.black.edgesIgnoringSafeArea(.all)
108+
)
106109
}
107110
}
108111
}

Sources/StreamChatSwiftUI/ChatChannel/Composer/ComposerModels.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ public enum AttachmentPickerState {
1414
}
1515

1616
/// Struct representing an asset added to the composer.
17-
public struct AddedAsset: Identifiable {
17+
public struct AddedAsset: Identifiable, Equatable {
18+
19+
public static func == (lhs: AddedAsset, rhs: AddedAsset) -> Bool {
20+
lhs.id == rhs.id
21+
}
22+
1823
public let image: UIImage
1924
public let id: String
2025
public let url: URL

0 commit comments

Comments
 (0)