mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 21:43:41 +00:00
Improve history view performance
This commit is contained in:
parent
eed9330c0c
commit
1e23809359
@ -8,6 +8,12 @@ struct HistoryView: View {
|
|||||||
|
|
||||||
@ObservedObject private var player = PlayerModel.shared
|
@ObservedObject private var player = PlayerModel.shared
|
||||||
|
|
||||||
|
@State private var visibleWatches = [Watch]()
|
||||||
|
|
||||||
|
init(limit: Int = 10) {
|
||||||
|
self.limit = limit
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
LazyVStack {
|
LazyVStack {
|
||||||
if visibleWatches.isEmpty {
|
if visibleWatches.isEmpty {
|
||||||
@ -30,14 +36,13 @@ struct HistoryView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.animation(nil, value: visibleWatches)
|
.animation(nil, value: visibleWatches)
|
||||||
.onAppear {
|
.onAppear(perform: reloadVisibleWatches)
|
||||||
visibleWatches
|
.onChange(of: player.currentVideo) { _ in reloadVisibleWatches() }
|
||||||
.forEach(player.loadHistoryVideoDetails)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var visibleWatches: [Watch] {
|
func reloadVisibleWatches() {
|
||||||
Array(watches.filter { $0.videoID != player.currentVideo?.videoID }.prefix(limit))
|
visibleWatches = Array(watches.filter { $0.videoID != player.currentVideo?.videoID }.prefix(limit))
|
||||||
|
visibleWatches.forEach(player.loadHistoryVideoDetails)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user