From c88ef750f00c6a69475bd62345a893ff44aacb24 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Tue, 31 Jan 2023 12:17:03 +0100 Subject: [PATCH] Fix multiple timeline refresh on launch close #555 --- Packages/Timeline/Sources/Timeline/TimelineView.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Packages/Timeline/Sources/Timeline/TimelineView.swift b/Packages/Timeline/Sources/Timeline/TimelineView.swift index babe46d8..dbc33caa 100644 --- a/Packages/Timeline/Sources/Timeline/TimelineView.swift +++ b/Packages/Timeline/Sources/Timeline/TimelineView.swift @@ -21,6 +21,7 @@ public struct TimelineView: View { @StateObject private var viewModel = TimelineViewModel() @State private var scrollProxy: ScrollViewProxy? + @State private var wasBackgrounded: Bool = false @Binding var timeline: TimelineFilter @Binding var scrollToTopSignal: Int @@ -99,9 +100,15 @@ public struct TimelineView: View { .onChange(of: scenePhase, perform: { scenePhase in switch scenePhase { case .active: - Task { - await viewModel.fetchStatuses(userIntent: false) + if wasBackgrounded { + wasBackgrounded = false + Task { + await viewModel.fetchStatuses(userIntent: false) + } } + case .background: + wasBackgrounded = true + default: break }