Fixes #279 - Fix plain timeline style layout, fix various TimelineViews' previews (#284)

This commit is contained in:
Stefan Ceriu 2022-11-02 14:06:10 +02:00 committed by GitHub
parent fabb0bc95f
commit 965569aae2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 62 additions and 17 deletions

View File

@ -44,6 +44,7 @@ struct TimelineItemPlainStylerView<Content: View>: View {
.foregroundColor(.element.primaryContent)
.fontWeight(.semibold)
.lineLimit(1)
Spacer()
Text(timelineItem.timestamp)
.foregroundColor(Color.element.tertiaryContent)
.font(.element.caption2)

View File

@ -39,6 +39,10 @@ struct EmoteRoomTimelineView_Previews: PreviewProvider {
static var previews: some View {
body.preferredColorScheme(.light)
body.preferredColorScheme(.dark)
body.preferredColorScheme(.light)
.timelineStyle(.plain)
body.preferredColorScheme(.dark)
.timelineStyle(.plain)
}
@ViewBuilder
@ -52,6 +56,7 @@ struct EmoteRoomTimelineView_Previews: PreviewProvider {
timestamp: "Later",
senderId: "Anne"))
}
.environment(\.timelineWidth, 400)
}
private static func itemWith(text: String, timestamp: String, senderId: String) -> EmoteRoomTimelineItem {

View File

@ -18,12 +18,24 @@ import Foundation
import SwiftUI
struct FormattedBodyText: View {
@Environment(\.timelineStyle) private var timelineStyle
let attributedComponents: [AttributedStringBuilderComponent]
var body: some View {
VStack(alignment: .leading, spacing: 8.0) {
ForEach(attributedComponents, id: \.self) { component in
if component.isBlockquote {
if timelineStyle == .plain {
HStack(spacing: 4.0) {
Rectangle()
.foregroundColor(Color.red)
.frame(width: 4.0)
Text(component.attributedString)
.foregroundColor(.element.primaryContent)
}
.fixedSize(horizontal: false, vertical: true)
} else {
Text(component.attributedString.mergingAttributes(blockquoteAttributes))
.fixedSize(horizontal: false, vertical: true)
.foregroundColor(.element.primaryContent)
@ -31,6 +43,7 @@ struct FormattedBodyText: View {
.clipped()
.background(Color.element.systemGray4)
.cornerRadius(13)
}
} else {
Text(component.attributedString)
.fixedSize(horizontal: false, vertical: true)
@ -58,6 +71,10 @@ struct FormattedBodyText_Previews: PreviewProvider {
static var previews: some View {
body.preferredColorScheme(.light)
body.preferredColorScheme(.dark)
body.preferredColorScheme(.light)
.timelineStyle(.plain)
body.preferredColorScheme(.dark)
.timelineStyle(.plain)
}
@ViewBuilder

View File

@ -54,6 +54,10 @@ struct ImageRoomTimelineView_Previews: PreviewProvider {
static var previews: some View {
body.preferredColorScheme(.light)
body.preferredColorScheme(.dark)
body.preferredColorScheme(.light)
.timelineStyle(.plain)
body.preferredColorScheme(.dark)
.timelineStyle(.plain)
}
@ViewBuilder
@ -88,5 +92,6 @@ struct ImageRoomTimelineView_Previews: PreviewProvider {
aspectRatio: 0.7,
blurhash: "L%KUc%kqS$RP?Ks,WEf8OlrqaekW"))
}
.environment(\.timelineWidth, 400)
}
}

View File

@ -39,6 +39,10 @@ struct NoticeRoomTimelineView_Previews: PreviewProvider {
static var previews: some View {
body.preferredColorScheme(.light)
body.preferredColorScheme(.dark)
body.preferredColorScheme(.light)
.timelineStyle(.plain)
body.preferredColorScheme(.dark)
.timelineStyle(.plain)
}
@ViewBuilder
@ -52,7 +56,7 @@ struct NoticeRoomTimelineView_Previews: PreviewProvider {
timestamp: "Later",
senderId: "Anne"))
}
.padding()
.environment(\.timelineWidth, 400)
}
private static func itemWith(text: String, timestamp: String, senderId: String) -> NoticeRoomTimelineItem {

View File

@ -44,7 +44,7 @@ struct RedactedRoomTimelineView_Previews: PreviewProvider {
timestamp: "Later",
senderId: "Anne"))
}
.padding()
.environment(\.timelineWidth, 400)
}
private static func itemWith(text: String, timestamp: String, senderId: String) -> RedactedRoomTimelineItem {

View File

@ -36,6 +36,10 @@ struct TextRoomTimelineView_Previews: PreviewProvider {
static var previews: some View {
body.preferredColorScheme(.light)
body.preferredColorScheme(.dark)
body.preferredColorScheme(.light)
.timelineStyle(.plain)
body.preferredColorScheme(.dark)
.timelineStyle(.plain)
}
@ViewBuilder
@ -55,15 +59,13 @@ struct TextRoomTimelineView_Previews: PreviewProvider {
timestamp: "Now",
isOutgoing: false,
senderId: "Bob"))
.timelineStyle(.plain)
TextRoomTimelineView(timelineItem: itemWith(text: "Some other text",
timestamp: "Later",
isOutgoing: true,
senderId: "Anne"))
.timelineStyle(.plain)
}
.padding(.horizontal, 8)
.environment(\.timelineWidth, 400)
}
private static func itemWith(text: String, timestamp: String, isOutgoing: Bool, senderId: String) -> TextRoomTimelineItem {

View File

@ -39,7 +39,7 @@ struct TimelineItemList: View {
.opacity(context.viewState.isBackPaginating ? 1.0 : 0.0)
.animation(.elementDefault, value: context.viewState.isBackPaginating)
LazyVStack(spacing: 0.0) {
LazyVStack(alignment: .leading, spacing: 0.0) {
ForEach(isRunningPreviews ? context.viewState.items : timelineItems) { item in
item
.contextMenu {

View File

@ -62,16 +62,14 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol {
inGroupState: .single,
isOutgoing: false,
senderId: "",
senderDisplayName: "Helena",
properties: RoomTimelineItemProperties()),
senderDisplayName: "Helena"),
TextRoomTimelineItem(id: UUID().uuidString,
text: "And John's speech was amazing!",
timestamp: "5 PM",
inGroupState: .beginning,
isOutgoing: true,
senderId: "",
senderDisplayName: "Bob",
properties: RoomTimelineItemProperties()),
senderDisplayName: "Bob"),
TextRoomTimelineItem(id: UUID().uuidString,
text: "New home office set up!",
timestamp: "5 PM",
@ -82,7 +80,19 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol {
properties: RoomTimelineItemProperties(reactions: [
AggregatedReaction(key: "🙏", count: 1, isHighlighted: false),
AggregatedReaction(key: "😁", count: 3, isHighlighted: false)
]))
])),
TextRoomTimelineItem(id: UUID().uuidString,
text: "",
attributedComponents: [
AttributedStringBuilderComponent(attributedString: "Hol' up", isBlockquote: false),
AttributedStringBuilderComponent(attributedString: "New home office set up!", isBlockquote: true),
AttributedStringBuilderComponent(attributedString: "That's amazing! Congrats 🥳", isBlockquote: false)
],
timestamp: "5 PM",
inGroupState: .single,
isOutgoing: false,
senderId: "",
senderDisplayName: "Helena")
]
func paginateBackwards(_ count: UInt) async -> Result<Void, RoomTimelineControllerError> {

1
changelog.d/279.bugfix Normal file
View File

@ -0,0 +1 @@
Fixed blockquote and item layout when using the plain timeline