Skip to content

Commit

Permalink
add second preview
Browse files Browse the repository at this point in the history
  • Loading branch information
caldrian committed Feb 21, 2025
1 parent f1b8d69 commit 79a9494
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
23 changes: 16 additions & 7 deletions WireUI/Sources/WireConversationUI/Views/MessageCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class MessageCell: UITableViewCell { // TODO: this probably has to
}
}

public var messageLayout = MessageLayout.oneOnOneConversation {
public var messageLayout = MessageLayout.oneOnOneConversationStyle {
didSet {
if oldValue != messageLayout {
updateContent()
Expand Down Expand Up @@ -77,7 +77,7 @@ public final class MessageCell: UITableViewCell { // TODO: this probably has to
var dataSourceX: AnyObject?

@MainActor
public func MessageCellPreview() -> UIViewController {
public func MessageCellPreview(_ messageLayout: MessageLayout) -> UIViewController {

let tableViewController = UITableViewController()
tableViewController.tableView.register(MessageCell.self, forCellReuseIdentifier: "MessageCell")
Expand All @@ -86,7 +86,7 @@ public func MessageCellPreview() -> UIViewController {
) { tableView, indexPath, itemID in
let cell = tableView.dequeueReusableCell(withIdentifier: "MessageCell", for: indexPath)
if let cell = cell as? MessageCell {
cell.messageLayout = .groupConversation
cell.messageLayout = messageLayout
cell.message = Message(
id: .init(itemID),
attributedText: AttributedString("Hello,\nWorld!")
Expand All @@ -112,16 +112,25 @@ public func MessageCellPreview() -> UIViewController {
}

@available(iOS 17, *)
#Preview {
MessageCellPreview()
#Preview("oneOnOne") {
MessageCellPreview(.oneOnOneConversationStyle)
}

@available(iOS 17, *)
#Preview("group") {
MessageCellPreview(.groupConversationStyle)
}

public struct MessageCellPreviewRepresentable: UIViewControllerRepresentable {

public init() {}
private let messageLayout: MessageLayout

public init(messageLayout: MessageLayout) {
self.messageLayout = messageLayout
}

public func makeUIViewController(context: Context) -> UIViewController {
MessageCellPreview()
MessageCellPreview(messageLayout)
}

public func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ struct MessageContentView<

var body: some View {
switch layout {
case .oneOnOneConversation:
case .oneOnOneConversationStyle:
oneOnOneConversationContent()
case .groupConversation:
case .groupConversationStyle:
groupConversationContent()
}
}
Expand Down
4 changes: 2 additions & 2 deletions WireUI/Sources/WireConversationUI/Views/MessageLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
//

public enum MessageLayout {
case oneOnOneConversation
case groupConversation
case oneOnOneConversationStyle
case groupConversationStyle
}

0 comments on commit 79a9494

Please sign in to comment.