From dff18e9d368ee54889281508cd74e4aa02942c94 Mon Sep 17 00:00:00 2001 From: Angelo Stavrow Date: Sun, 28 Nov 2021 08:01:54 -0500 Subject: [PATCH] Refresh post list view when app becomes active --- Shared/PostList/PostListView.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Shared/PostList/PostListView.swift b/Shared/PostList/PostListView.swift index 86215bb..03b865e 100644 --- a/Shared/PostList/PostListView.swift +++ b/Shared/PostList/PostListView.swift @@ -6,6 +6,7 @@ struct PostListView: View { @Environment(\.managedObjectContext) var managedObjectContext @State private var postCount: Int = 0 + @State private var filteredListViewId: Int = 0 var selectedCollection: WFACollection? var showAllPosts: Bool @@ -27,6 +28,7 @@ struct PostListView: View { showAllPosts: showAllPosts, postCount: $postCount ) + .id(self.filteredListViewId) .navigationTitle( showAllPosts ? "All Posts" : selectedCollection?.title ?? ( model.account.server == "https://write.as" ? "Anonymous" : "Drafts" @@ -123,6 +125,13 @@ struct PostListView: View { .frame(height: frameHeight) .background(Color(UIColor.systemGray5)) .overlay(Divider(), alignment: .top) + .onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification)) { _ in + // We use this to invalidate and refresh the view, so that new posts created outside of the app (e.g., + // in the action extension) show up. + withAnimation { + self.filteredListViewId += 1 + } + } } .ignoresSafeArea() .onAppear {