Cache tag + gradient on home timeline

This commit is contained in:
Thomas Ricouard 2024-07-10 16:13:41 +02:00
parent 5969e8a166
commit 3c5c9adc03
4 changed files with 51 additions and 14 deletions

View file

@ -137,13 +137,6 @@ public struct StatusDetailView: View {
}
}
}
#if !os(visionOS)
.listRowBackground(viewModel.highlightRowColor)
#endif
.listRowInsets(.init(top: 12,
leading: .layoutPadding,
bottom: 12,
trailing: .layoutPadding))
}
}

View file

@ -15,6 +15,8 @@ public struct StatusRowView: View {
@Environment(\.accessibilityVoiceOverEnabled) private var accessibilityVoiceOverEnabled
@Environment(\.isStatusFocused) private var isFocused
@Environment(\.indentationLevel) private var indentationLevel
@Environment(\.isHomeTimeline) private var isHomeTimeline
@Environment(RouterPath.self) private var routerPath: RouterPath
@Environment(QuickLook.self) private var quickLook
@ -151,7 +153,7 @@ public struct StatusRowView: View {
.foregroundStyle(.background).hoverEffect())
.listRowHoverEffectDisabled()
#else
.listRowBackground(viewModel.highlightRowColor)
.listRowBackground(viewModel.makeBackgroundColor(isHomeTimeline: isHomeTimeline))
#endif
.listRowInsets(.init(top: 0,
leading: .layoutPadding,

View file

@ -18,6 +18,8 @@ import SwiftUI
let client: Client
let routerPath: RouterPath
let userFollowedTag: HTMLString.Link?
private let theme = Theme.shared
private let userMentionned: Bool
@ -103,8 +105,35 @@ import SwiftUI
status.reblog?.inReplyToId != nil || status.reblog?.inReplyToAccountId != nil ||
status.inReplyToId != nil || status.inReplyToAccountId != nil
}
@ViewBuilder
func makeBackgroundColor(isHomeTimeline: Bool) -> some View {
if isHomeTimeline {
homeBackgroundColor
} else {
backgroundColor
}
}
@ViewBuilder
var homeBackgroundColor: some View {
if status.visibility == .direct {
theme.tintColor.opacity(0.15)
} else if userMentionned {
theme.secondaryBackgroundColor
} else {
if userFollowedTag != nil {
makeDecorativeGradient(startColor: .teal, endColor: theme.primaryBackgroundColor)
} else if status.reblog != nil {
makeDecorativeGradient(startColor: theme.tintColor, endColor: theme.primaryBackgroundColor)
} else {
theme.primaryBackgroundColor
}
}
}
var highlightRowColor: Color {
@ViewBuilder
var backgroundColor: some View {
if status.visibility == .direct {
theme.tintColor.opacity(0.15)
} else if userMentionned {
@ -113,6 +142,18 @@ import SwiftUI
theme.primaryBackgroundColor
}
}
func makeDecorativeGradient(startColor: Color, endColor: Color) -> some View {
LinearGradient(stops: [
.init(color: startColor.opacity(0.3), location: 0.03),
.init(color: startColor.opacity(0.2), location: 0.06),
.init(color: startColor.opacity(0.1), location: 0.09),
.init(color: startColor.opacity(0.05), location: 0.15),
.init(color: endColor, location: 0.25),
],
startPoint: .topLeading,
endPoint: .bottomTrailing)
}
public init(status: Status,
client: Client,
@ -146,6 +187,10 @@ import SwiftUI
} else {
userMentionned = false
}
userFollowedTag = finalStatus.content.links.first(where: { link in
link.type == .hashtag && CurrentAccount.shared.tags.contains(where: { $0.name.lowercased() == link.title.lowercased() })
})
isFiltered = filter != nil

View file

@ -5,17 +5,14 @@ import SwiftUI
struct StatusRowTagView: View {
@Environment(CurrentAccount.self) private var currentAccount
@Environment(RouterPath.self) private var routerPath
@Environment(Theme.self) private var theme
@Environment(\.isHomeTimeline) private var isHomeTimeline
let viewModel: StatusRowViewModel
var body: some View {
if isHomeTimeline,
let tag = viewModel.finalStatus.content.links.first(where: { link in
link.type == .hashtag && currentAccount.tags.contains(where: { $0.name.lowercased() == link.title.lowercased() })
})
{
if isHomeTimeline, let tag = viewModel.userFollowedTag {
Text("#\(tag.title)")
.font(.scaledFootnote)
.foregroundStyle(.secondary)