mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Refresh post list view when app becomes active
This commit is contained in:
parent
8a3017d46f
commit
dff18e9d36
@ -6,6 +6,7 @@ struct PostListView: View {
|
|||||||
@Environment(\.managedObjectContext) var managedObjectContext
|
@Environment(\.managedObjectContext) var managedObjectContext
|
||||||
|
|
||||||
@State private var postCount: Int = 0
|
@State private var postCount: Int = 0
|
||||||
|
@State private var filteredListViewId: Int = 0
|
||||||
|
|
||||||
var selectedCollection: WFACollection?
|
var selectedCollection: WFACollection?
|
||||||
var showAllPosts: Bool
|
var showAllPosts: Bool
|
||||||
@ -27,6 +28,7 @@ struct PostListView: View {
|
|||||||
showAllPosts: showAllPosts,
|
showAllPosts: showAllPosts,
|
||||||
postCount: $postCount
|
postCount: $postCount
|
||||||
)
|
)
|
||||||
|
.id(self.filteredListViewId)
|
||||||
.navigationTitle(
|
.navigationTitle(
|
||||||
showAllPosts ? "All Posts" : selectedCollection?.title ?? (
|
showAllPosts ? "All Posts" : selectedCollection?.title ?? (
|
||||||
model.account.server == "https://write.as" ? "Anonymous" : "Drafts"
|
model.account.server == "https://write.as" ? "Anonymous" : "Drafts"
|
||||||
@ -123,6 +125,13 @@ struct PostListView: View {
|
|||||||
.frame(height: frameHeight)
|
.frame(height: frameHeight)
|
||||||
.background(Color(UIColor.systemGray5))
|
.background(Color(UIColor.systemGray5))
|
||||||
.overlay(Divider(), alignment: .top)
|
.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()
|
.ignoresSafeArea()
|
||||||
.onAppear {
|
.onAppear {
|
||||||
|
Loading…
Reference in New Issue
Block a user