From cfd34e2021cfb0d659f79c169d24ae29608d5bcf Mon Sep 17 00:00:00 2001 From: Angelo Stavrow Date: Mon, 4 Jan 2021 10:04:27 -0500 Subject: [PATCH] Replace bottom toolbar with overlaid view --- Shared/PostList/PostListView.swift | 92 +++++++------------ .../project.pbxproj | 12 +++ iOS/PostList/PostListBottomBarView.swift | 46 ++++++++++ 3 files changed, 91 insertions(+), 59 deletions(-) create mode 100644 iOS/PostList/PostListBottomBarView.swift diff --git a/Shared/PostList/PostListView.swift b/Shared/PostList/PostListView.swift index e20651a..a174af2 100644 --- a/Shared/PostList/PostListView.swift +++ b/Shared/PostList/PostListView.swift @@ -11,73 +11,47 @@ struct PostListView: View { var body: some View { #if os(iOS) - GeometryReader { geometry in + ZStack(alignment: .bottom) { PostListFilteredView(collection: selectedCollection, showAllPosts: showAllPosts, postCount: $postCount) - .navigationTitle( - showAllPosts ? "All Posts" : selectedCollection?.title ?? ( - model.account.server == "https://write.as" ? "Anonymous" : "Drafts" + .navigationTitle( + showAllPosts ? "All Posts" : selectedCollection?.title ?? ( + model.account.server == "https://write.as" ? "Anonymous" : "Drafts" + ) ) - ) - .toolbar { - ToolbarItem(placement: .primaryAction) { - Button(action: { - let managedPost = WFAPost(context: self.managedObjectContext) - managedPost.createdDate = Date() - managedPost.title = "" - managedPost.body = "" - managedPost.status = PostStatus.local.rawValue - managedPost.collectionAlias = nil - switch model.preferences.font { - case 1: - managedPost.appearance = "sans" - case 2: - managedPost.appearance = "wrap" - default: - managedPost.appearance = "serif" - } - if let languageCode = Locale.current.languageCode { - managedPost.language = languageCode - managedPost.rtl = Locale.characterDirection(forLanguage: languageCode) == .rightToLeft - } - withAnimation { - self.selectedCollection = nil - self.showAllPosts = false - self.model.selectedPost = managedPost - } - }, label: { - Image(systemName: "square.and.pencil") - }) - } - ToolbarItem(placement: .bottomBar) { - HStack { + .toolbar { + ToolbarItem(placement: .primaryAction) { Button(action: { - model.isPresentingSettingsView = true + let managedPost = WFAPost(context: self.managedObjectContext) + managedPost.createdDate = Date() + managedPost.title = "" + managedPost.body = "" + managedPost.status = PostStatus.local.rawValue + managedPost.collectionAlias = nil + switch model.preferences.font { + case 1: + managedPost.appearance = "sans" + case 2: + managedPost.appearance = "wrap" + default: + managedPost.appearance = "serif" + } + if let languageCode = Locale.current.languageCode { + managedPost.language = languageCode + managedPost.rtl = Locale.characterDirection(forLanguage: languageCode) == .rightToLeft + } + withAnimation { + self.selectedCollection = nil + self.showAllPosts = false + self.model.selectedPost = managedPost + } }, label: { - Image(systemName: "gear") + Image(systemName: "square.and.pencil") }) - Spacer() - Text(postCount == 1 ? "\(postCount) post" : "\(postCount) posts") - .foregroundColor(.secondary) - Spacer() - if model.isProcessingRequest { - ProgressView() - } else { - Button(action: { - DispatchQueue.main.async { - model.fetchUserCollections() - model.fetchUserPosts() - } - }, label: { - Image(systemName: "arrow.clockwise") - }) - .disabled(!model.account.isLoggedIn) - } } - .padding() - .frame(width: geometry.size.width) } - } + PostListBottomBarView(postCount: $postCount) } + .ignoresSafeArea() #else //if os(macOS) PostListFilteredView( collection: selectedCollection, diff --git a/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj b/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj index d5493aa..032a893 100644 --- a/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj +++ b/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj @@ -79,6 +79,7 @@ 17D4F39F2514F0E500517CE6 /* OpenSans-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 17D4F39D2514F0E500517CE6 /* OpenSans-Regular.ttf */; }; 17D4F3A52514F1E900517CE6 /* Hack-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 17D4F3A42514F1E900517CE6 /* Hack-Regular.ttf */; }; 17D4F3A62514F1E900517CE6 /* Hack-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 17D4F3A42514F1E900517CE6 /* Hack-Regular.ttf */; }; + 17DB9C7D25A3582F0030ECC0 /* PostListBottomBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17DB9C7C25A3582F0030ECC0 /* PostListBottomBarView.swift */; }; 17DF329D24C87D3500BCE2E3 /* Tests_iOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17DF329C24C87D3500BCE2E3 /* Tests_iOS.swift */; }; 17DF32A824C87D3500BCE2E3 /* Tests_macOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17DF32A724C87D3500BCE2E3 /* Tests_macOS.swift */; }; 17DF32AA24C87D3500BCE2E3 /* WriteFreely_MultiPlatformApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17DF328124C87D3300BCE2E3 /* WriteFreely_MultiPlatformApp.swift */; }; @@ -164,6 +165,7 @@ 17D4F36B2514EE2F00517CE6 /* LoraGX.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = LoraGX.ttf; sourceTree = ""; }; 17D4F39D2514F0E500517CE6 /* OpenSans-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "OpenSans-Regular.ttf"; sourceTree = ""; }; 17D4F3A42514F1E900517CE6 /* Hack-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Hack-Regular.ttf"; sourceTree = ""; }; + 17DB9C7C25A3582F0030ECC0 /* PostListBottomBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostListBottomBarView.swift; sourceTree = ""; }; 17DF328124C87D3300BCE2E3 /* WriteFreely_MultiPlatformApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WriteFreely_MultiPlatformApp.swift; sourceTree = ""; }; 17DF328224C87D3300BCE2E3 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 17DF328324C87D3500BCE2E3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -343,6 +345,14 @@ path = Resources; sourceTree = ""; }; + 17DB9C7B25A358000030ECC0 /* PostList */ = { + isa = PBXGroup; + children = ( + 17DB9C7C25A3582F0030ECC0 /* PostListBottomBarView.swift */, + ); + path = PostList; + sourceTree = ""; + }; 17DF327B24C87D3300BCE2E3 = { isa = PBXGroup; children = ( @@ -399,6 +409,7 @@ 17B3E964250FAA9000EE9748 /* LaunchScreen.storyboard */, 17681E3F251940F200D394AE /* Extensions */, 17A67CAB251A5D7E002F163D /* PostEditor */, + 17DB9C7B25A358000030ECC0 /* PostList */, 17120DA624E19CE2002B9F6C /* Settings */, ); path = iOS; @@ -711,6 +722,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 17DB9C7D25A3582F0030ECC0 /* PostListBottomBarView.swift in Sources */, 17DF32AC24C87D3500BCE2E3 /* ContentView.swift in Sources */, 173E19D1254318F600440F0F /* RemoteChangePromptView.swift in Sources */, 17C42E622507D8E600072984 /* PostStatus.swift in Sources */, diff --git a/iOS/PostList/PostListBottomBarView.swift b/iOS/PostList/PostListBottomBarView.swift new file mode 100644 index 0000000..181b190 --- /dev/null +++ b/iOS/PostList/PostListBottomBarView.swift @@ -0,0 +1,46 @@ +import SwiftUI + +struct PostListBottomBarView: View { + @EnvironmentObject var model: WriteFreelyModel + @Binding var postCount: Int + + var body: some View { + VStack { + HStack(spacing: 0) { + Button(action: { + model.isPresentingSettingsView = true + }, label: { + Image(systemName: "gear") + }) + Spacer() + Text(postCount == 1 ? "\(postCount) post" : "\(postCount) posts") + .foregroundColor(.secondary) + Spacer() + if model.isProcessingRequest { + ProgressView() + } else { + Button(action: { + DispatchQueue.main.async { + model.fetchUserCollections() + model.fetchUserPosts() + } + }, label: { + Image(systemName: "arrow.clockwise") + }) + .disabled(!model.account.isLoggedIn) + } + } + .padding() + Spacer() + } + .frame(height: 100) + .background(Color(UIColor.systemGray5)) + .overlay(Divider(), alignment: .top) + } +} + +struct PostListBottomBarView_Previews: PreviewProvider { + static var previews: some View { + PostListBottomBarView(postCount: .constant(0)).environmentObject(WriteFreelyModel()) + } +}