diff --git a/Shared/Post/PostList.swift b/Shared/Post/PostList.swift index 2682b9f..ab4102c 100644 --- a/Shared/Post/PostList.swift +++ b/Shared/Post/PostList.swift @@ -1,104 +1,107 @@ import SwiftUI struct PostList: View { @EnvironmentObject var postStore: PostStore @State var selectedCollection: PostCollection @State var isPresentingSettings = false var body: some View { #if os(iOS) - List { - ForEach(showPosts(for: selectedCollection)) { post in - NavigationLink( - destination: PostEditor(post: post) - ) { - PostCell( - post: post - ) + GeometryReader { geometry in + List { + ForEach(showPosts(for: selectedCollection)) { post in + NavigationLink( + destination: PostEditor(post: post) + ) { + PostCell( + post: post + ) + } } } - } - .navigationTitle(selectedCollection.title) - .toolbar { - ToolbarItem(placement: .primaryAction) { - Button(action: { - let post = Post() - postStore.add(post) - }, label: { - Image(systemName: "square.and.pencil") - }) - } - ToolbarItem(placement: .bottomBar) { - Button(action: { - isPresentingSettings = true - }, label: { - Image(systemName: "gear") - }).sheet( - isPresented: $isPresentingSettings, - onDismiss: { - isPresentingSettings = false - }, - content: { - SettingsView(isPresented: $isPresentingSettings) + .navigationTitle(selectedCollection.title) + .toolbar { + ToolbarItem(placement: .primaryAction) { + Button(action: { + let post = Post() + postStore.add(post) + }, label: { + Image(systemName: "square.and.pencil") + }) + } + ToolbarItem(placement: .bottomBar) { + HStack { + Button(action: { + isPresentingSettings = true + }, label: { + Image(systemName: "gear") + }).sheet( + isPresented: $isPresentingSettings, + onDismiss: { + isPresentingSettings = false + }, + content: { + SettingsView(isPresented: $isPresentingSettings) + } + ) + Spacer() + Text(pluralizedPostCount(for: showPosts(for: selectedCollection))) + .foregroundColor(.secondary) } - ) - } - ToolbarItem(placement: .bottomBar) { - Spacer() - } - ToolbarItem(placement: .bottomBar) { - Text(pluralizedPostCount(for: showPosts(for: selectedCollection))) + .padding() + .frame(width: geometry.size.width) + } } } #else //if os(macOS) List { ForEach(showPosts(for: selectedCollection)) { post in NavigationLink( destination: PostEditor(post: post) ) { PostCell( post: post ) } } } .navigationTitle(selectedCollection.title) .navigationSubtitle(pluralizedPostCount(for: showPosts(for: selectedCollection))) .toolbar { Button(action: { let post = Post() postStore.add(post) }, label: { Image(systemName: "square.and.pencil") }) } #endif } private func pluralizedPostCount(for posts: [Post]) -> String { if posts.count == 1 { return "1 post" } else { return "\(posts.count) posts" } } private func showPosts(for collection: PostCollection) -> [Post] { if collection == allPostsCollection { return postStore.posts } else { return postStore.posts.filter { $0.collection.title == collection.title } } } } struct PostList_Previews: PreviewProvider { static var previews: some View { Group { PostList(selectedCollection: allPostsCollection) .environmentObject(testPostStore) } } } diff --git a/WriteFreely-MultiPlatform.xcodeproj/xcuserdata/angelo.xcuserdatad/xcschemes/xcschememanagement.plist b/WriteFreely-MultiPlatform.xcodeproj/xcuserdata/angelo.xcuserdatad/xcschemes/xcschememanagement.plist index 2723ebe..6cd8075 100644 --- a/WriteFreely-MultiPlatform.xcodeproj/xcuserdata/angelo.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/WriteFreely-MultiPlatform.xcodeproj/xcuserdata/angelo.xcuserdatad/xcschemes/xcschememanagement.plist @@ -1,19 +1,19 @@ SchemeUserState WriteFreely-MultiPlatform (iOS).xcscheme_^#shared#^_ orderHint - 0 + 1 WriteFreely-MultiPlatform (macOS).xcscheme_^#shared#^_ orderHint - 1 + 0