Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apps/ios/Sources/Litter/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,12 @@ extension View {
}
}
}

extension Array {
func chunked(into size: Int) -> [[Element]] {
guard size > 0 else { return [self] }
return stride(from: 0, to: count, by: size).map {
Array(self[$0..<Swift.min($0 + size, count)])
}
}
}
59 changes: 32 additions & 27 deletions apps/ios/Sources/Litter/Views/MessageBubbleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,30 +122,10 @@ struct UserBubble: View, Equatable {
HStack(alignment: .top, spacing: 0) {
Spacer(minLength: compact ? 30 : 60)
VStack(alignment: .trailing, spacing: compact ? 4 : 8) {
ForEach(images) { img in
if let request = UserBubble.imageRequest(for: img) {
LazyImage(request: request) { state in
if let image = state.image {
if let ui = state.imageContainer?.image {
image
.resizable()
.scaledToFit()
.frame(maxWidth: 200, maxHeight: 200)
.clipShape(RoundedRectangle(cornerRadius: 10))
.draggable(Image(uiImage: ui)) {
Image(uiImage: ui)
.resizable()
.scaledToFit()
.frame(width: 120)
}
} else {
image
.resizable()
.scaledToFit()
.frame(maxWidth: 200, maxHeight: 200)
.clipShape(RoundedRectangle(cornerRadius: 10))
}
}
ForEach(Array(images.chunked(into: 3).enumerated()), id: \.offset) { _, row in
HStack(spacing: 6) {
ForEach(row) { img in
bubbleImage(img)
}
}
}
Expand All @@ -170,18 +150,43 @@ struct UserBubble: View, Equatable {
.accessibilityLabel(expandedLongText ? "Show less user message" : "Show more user message")
}
}
.padding(.horizontal, compact ? 12 : 18)
.padding(.vertical, compact ? 8 : 14)
.modifier(GlassRectModifier(cornerRadius: compact ? 14 : 18, tint: LitterTheme.accent.opacity(0.3)))
}
}
.padding(.horizontal, compact ? 12 : 18)
.padding(.vertical, compact ? 8 : 14)
.modifier(GlassRectModifier(cornerRadius: compact ? 14 : 18, tint: LitterTheme.accent.opacity(0.3)))
}
.padding(.bottom, 14)
.onChange(of: text) { _, _ in
expandedLongText = false
}
}

@ViewBuilder
private func bubbleImage(_ img: ChatImage) -> some View {
if let request = UserBubble.imageRequest(for: img) {
LazyImage(request: request) { state in
if let image = state.image {
let thumb = image
.resizable()
.scaledToFill()
.frame(width: 100, height: 100)
.clipShape(RoundedRectangle(cornerRadius: 12))
if let ui = state.imageContainer?.image {
thumb.draggable(Image(uiImage: ui)) {
Image(uiImage: ui)
.resizable()
.scaledToFit()
.frame(width: 120)
}
} else {
thumb
}
}
}
}
}

private var visibleText: String {
guard shouldLimitText, !expandedLongText else {
return text
Expand Down