Skip to content

Commit

Permalink
Refactor BubbleTimestampLayoutType
Browse files Browse the repository at this point in the history
  • Loading branch information
alfogrillo committed Jul 26, 2023
1 parent 30a42a2 commit 0e35a70
Showing 1 changed file with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
messageBubbleWithReactions
}
.padding(timelineItem.isOutgoing ? .leading : .trailing, 48) // Additional padding to differentiate alignment.

HStack(spacing: 0) {
if !timelineItem.isOutgoing {
Spacer()
Expand Down Expand Up @@ -156,23 +156,11 @@ struct TimelineItemBubbledStylerView<Content: View>: View {

@ViewBuilder
var contentWithTimestamp: some View {
switch timelineItem.bubbleTimestampLayout {
case .horizontal:
HStack(alignment: .bottom, spacing: 4) {
contentWithReply
interactiveLocalizedSendInfo
}
case .vertical:
VStack(alignment: .leading, spacing: 4) {
contentWithReply
interactiveLocalizedSendInfo
}
case .overlay:
ZStack(alignment: .bottomTrailing) {
timelineItem.bubbleTimestampLayoutType
.layout {
contentWithReply
interactiveLocalizedSendInfo
}
}
}

@ViewBuilder
Expand All @@ -189,7 +177,7 @@ struct TimelineItemBubbledStylerView<Content: View>: View {

@ViewBuilder
var backgroundedLocalizedSendInfo: some View {
switch timelineItem.bubbleTimestampLayout {
switch timelineItem.bubbleTimestampLayoutType {
case .overlay(capsuleStyle: true):
localizedSendInfo
.padding(.horizontal, 4)
Expand Down Expand Up @@ -292,10 +280,25 @@ private extension View {
}
}

enum BubbleTimestampLayout {
enum BubbleTimestampLayoutType {
case horizontal
case vertical
case overlay(capsuleStyle: Bool)

var layout: AnyLayout {
let layout: any Layout

switch self {
case .horizontal:
layout = HStackLayout(alignment: .bottom, spacing: 4)
case .vertical:
layout = VStackLayout(alignment: .leading, spacing: 4)
case .overlay:
layout = ZStackLayout(alignment: .bottomTrailing)
}

return AnyLayout(layout)
}
}

private extension EventBasedTimelineItemProtocol {
Expand Down Expand Up @@ -329,8 +332,8 @@ private extension EventBasedTimelineItemProtocol {
}
}

var bubbleTimestampLayout: BubbleTimestampLayout {
let defaultTimestampLayout: BubbleTimestampLayout = .horizontal
var bubbleTimestampLayoutType: BubbleTimestampLayoutType {
let defaultTimestampLayout: BubbleTimestampLayoutType = .horizontal

switch self {
case is TextBasedRoomTimelineItem:
Expand Down

0 comments on commit 0e35a70

Please sign in to comment.