Refresh views on entering foreground

This commit is contained in:
Arkadiusz Fal 2022-08-28 20:00:43 +02:00
parent 0f7d826a3e
commit 44600831a6
5 changed files with 27 additions and 0 deletions

View File

@ -49,6 +49,7 @@ struct FavoritesView: View {
}
.tieToLifetime(of: accounts)
}
.redrawOn(change: favoritesChanged)
#if os(tvOS)
@ -64,6 +65,11 @@ struct FavoritesView: View {
#if os(iOS)
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
#endif
#if !os(macOS)
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
favoritesChanged.toggle()
}
#endif
}
}
}

View File

@ -158,6 +158,12 @@ struct PlaylistsView: View {
#if os(iOS)
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
#endif
#if !os(macOS)
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
model.load()
resource?.loadIfNeeded()
}
#endif
}
#if os(tvOS)

View File

@ -140,6 +140,11 @@ struct TrendingView: View {
}
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
#endif
#if !os(macOS)
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
resource.loadIfNeeded()
}
#endif
}
#if os(tvOS)

View File

@ -47,5 +47,10 @@ struct PopularView: View {
}
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
#endif
#if !os(macOS)
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
resource?.loadIfNeeded()
}
#endif
}
}

View File

@ -50,6 +50,11 @@ struct SubscriptionsView: View {
#if os(iOS)
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
#endif
#if !os(macOS)
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
loadResources()
}
#endif
}
private func loadResources(force: Bool = false, onCompletion: @escaping () -> Void = {}) {