Fix Home view showing zero counts after returning from background

onAppear only fires once when the view first appears, not on foreground
return. Add scenePhase observer to reload data when the app becomes active.
This commit is contained in:
Arkadiusz Fal
2026-02-23 13:22:31 +01:00
parent 78f0268342
commit caa19a742b

View File

@@ -9,6 +9,7 @@ import SwiftUI
struct HomeView: View {
@Environment(\.appEnvironment) private var appEnvironment
@Environment(\.scenePhase) private var scenePhase
@Namespace private var sheetTransition
@State private var playlists: [LocalPlaylist] = []
@State private var bookmarksCount: Int = 0
@@ -117,6 +118,11 @@ struct HomeView: View {
.onAppear {
loadData()
}
.onChange(of: scenePhase) { _, newPhase in
if newPhase == .active {
loadData()
}
}
.task {
await feedCache.loadFromDiskIfNeeded()
await appEnvironment?.homeInstanceCache.loadFromDiskIfNeeded()