Skip to content

Commit f1b8d69

Browse files
committed
fix group conversation layout
1 parent 7fcb9e9 commit f1b8d69

File tree

2 files changed

+63
-13
lines changed

2 files changed

+63
-13
lines changed

WireUI/Sources/WireConversationUI/Views/MessageCell.swift

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import SwiftUI
2020
import WireFoundation
2121

22-
public final class MessageCell: UITableViewCell {
22+
public final class MessageCell: UITableViewCell { // TODO: this probably has to be moved out of WireConversationUI (no generics supported)
2323

2424
public var message = Message() {
2525
didSet {
@@ -51,18 +51,23 @@ public final class MessageCell: UITableViewCell {
5151

5252
private func updateContent() {
5353
contentConfiguration = UIHostingConfiguration {
54-
MessageContentView(message: message, layout: messageLayout)
55-
.swipeActions(edge: .leading) {
56-
Button {
57-
print("swipe")
58-
} label: {
59-
Label("Favorite", systemImage: "arrowshape.turn.up.backward.fill")
60-
}
54+
MessageContentView(
55+
message: message,
56+
layout: messageLayout,
57+
accountImageViewContent: { Circle().fill(.red) }
58+
)
59+
.swipeActions(edge: .leading) {
60+
Button {
61+
print("swipe")
62+
} label: {
63+
Label("Favorite", systemImage: "arrowshape.turn.up.backward.fill")
6164
}
62-
.environment(\.wireAccentColor, wireAccentColor)
63-
.environment(\.wireAccentColorMapping, wireAccentColorMapping)
65+
}
66+
.environment(\.wireAccentColor, wireAccentColor)
67+
.environment(\.wireAccentColorMapping, wireAccentColorMapping)
6468
}
6569
}
70+
6671
}
6772

6873

@@ -81,14 +86,16 @@ public func MessageCellPreview() -> UIViewController {
8186
) { tableView, indexPath, itemID in
8287
let cell = tableView.dequeueReusableCell(withIdentifier: "MessageCell", for: indexPath)
8388
if let cell = cell as? MessageCell {
89+
cell.messageLayout = .groupConversation
8490
cell.message = Message(
8591
id: .init(itemID),
86-
attributedText: AttributedString("Hello, World!")
92+
attributedText: AttributedString("Hello,\nWorld!")
8793
)
8894
}
8995
return cell
9096
}
9197
tableViewController.tableView.dataSource = dataSource
98+
tableViewController.tableView.separatorStyle = .none
9299

93100
var snapshot = dataSource.snapshot()
94101
snapshot.appendSections([.single])

WireUI/Sources/WireConversationUI/Views/MessageContentView.swift

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,55 @@
1818

1919
import SwiftUI
2020

21-
struct MessageContentView: View {
21+
struct MessageContentView<
22+
AccountImageView: View
23+
>: View {
24+
25+
let accountImageViewDiameter: CGFloat = 32
2226

2327
var message: Message
2428
var layout: MessageLayout
29+
var accountImageViewContent: () -> AccountImageView
2530

2631
var body: some View {
27-
Text(message.attributedText)
32+
switch layout {
33+
case .oneOnOneConversation:
34+
oneOnOneConversationContent()
35+
case .groupConversation:
36+
groupConversationContent()
37+
}
2838
}
39+
40+
@ViewBuilder
41+
private func oneOnOneConversationContent() -> some View {
42+
HStack(alignment: .top) {
43+
44+
accountImageViewContent()
45+
.frame(width: accountImageViewDiameter, height: accountImageViewDiameter)
46+
47+
VStack {
48+
Text(message.attributedText)
49+
}
50+
51+
}
52+
}
53+
54+
@ViewBuilder
55+
private func groupConversationContent() -> some View {
56+
Grid(alignment: .topLeading) {
57+
GridRow(alignment: .center) {
58+
accountImageViewContent()
59+
.frame(width: accountImageViewDiameter, height: accountImageViewDiameter)
60+
Text(verbatim: "sender-name")
61+
.frame(minHeight: accountImageViewDiameter)
62+
}
63+
GridRow {
64+
Color.clear
65+
.gridCellUnsizedAxes([.horizontal, .vertical])
66+
Text(message.attributedText)
67+
.fixedSize(horizontal: false, vertical: true)
68+
}
69+
}
70+
}
71+
2972
}

0 commit comments

Comments
 (0)