Replace bottom toolbar with overlaid view

This commit is contained in:
Angelo Stavrow 2021-01-04 10:04:27 -05:00
parent 1d1d4927b3
commit cfd34e2021
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
3 changed files with 91 additions and 59 deletions

View File

@ -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,

View File

@ -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 = "<group>"; };
17D4F39D2514F0E500517CE6 /* OpenSans-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "OpenSans-Regular.ttf"; sourceTree = "<group>"; };
17D4F3A42514F1E900517CE6 /* Hack-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Hack-Regular.ttf"; sourceTree = "<group>"; };
17DB9C7C25A3582F0030ECC0 /* PostListBottomBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostListBottomBarView.swift; sourceTree = "<group>"; };
17DF328124C87D3300BCE2E3 /* WriteFreely_MultiPlatformApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WriteFreely_MultiPlatformApp.swift; sourceTree = "<group>"; };
17DF328224C87D3300BCE2E3 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
17DF328324C87D3500BCE2E3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@ -343,6 +345,14 @@
path = Resources;
sourceTree = "<group>";
};
17DB9C7B25A358000030ECC0 /* PostList */ = {
isa = PBXGroup;
children = (
17DB9C7C25A3582F0030ECC0 /* PostListBottomBarView.swift */,
);
path = PostList;
sourceTree = "<group>";
};
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 */,

View File

@ -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())
}
}