Sidebar toolbar no longer an overlay

Also moved view model to separate file and removed the view prefix.
This commit is contained in:
Stuart Breckenridge 2020-07-04 21:34:15 +08:00
parent c0755fe55b
commit 01a84a2a40
5 changed files with 98 additions and 93 deletions

View File

@ -16,6 +16,7 @@ struct CompactSidebarContainerView: View {
var body: some View { var body: some View {
SidebarView() SidebarView()
.modifier(SidebarToolbar())
.environmentObject(sidebarModel) .environmentObject(sidebarModel)
.navigationBarTitle(Text("Feeds")) .navigationBarTitle(Text("Feeds"))
.listStyle(PlainListStyle()) .listStyle(PlainListStyle())
@ -23,11 +24,7 @@ struct CompactSidebarContainerView: View {
sceneModel.sidebarModel = sidebarModel sceneModel.sidebarModel = sidebarModel
sidebarModel.delegate = sceneModel sidebarModel.delegate = sceneModel
sidebarModel.rebuildSidebarItems() sidebarModel.rebuildSidebarItems()
}.overlay(Group { }
#if os(iOS)
SidebarToolbar()
#endif
},alignment: .bottom)
} }
} }

View File

@ -17,6 +17,7 @@ struct RegularSidebarContainerView: View {
@ViewBuilder var body: some View { @ViewBuilder var body: some View {
SidebarView() SidebarView()
.modifier(SidebarToolbar())
.environmentObject(sidebarModel) .environmentObject(sidebarModel)
.navigationTitle(Text("Feeds")) .navigationTitle(Text("Feeds"))
.listStyle(SidebarListStyle()) .listStyle(SidebarListStyle())
@ -25,11 +26,6 @@ struct RegularSidebarContainerView: View {
sidebarModel.delegate = sceneModel sidebarModel.delegate = sceneModel
sidebarModel.rebuildSidebarItems() sidebarModel.rebuildSidebarItems()
} }
.overlay(Group {
#if os(iOS)
SidebarToolbar()
#endif
},alignment: .bottom)
} }

View File

@ -8,85 +8,65 @@
import SwiftUI import SwiftUI
fileprivate enum ToolbarSheets {
case none, web, twitter, reddit, folder, settings
}
fileprivate class SidebarToolbarViewModel: ObservableObject { struct SidebarToolbar: ViewModifier {
@Published var showSheet: Bool = false
@Published var sheetToShow: ToolbarSheets = .none {
didSet {
sheetToShow != .none ? (showSheet = true) : (showSheet = false)
}
}
@Published var showActionSheet: Bool = false
@Published var showAddSheet: Bool = false
}
struct SidebarToolbar: View {
@EnvironmentObject private var appSettings: AppDefaults @EnvironmentObject private var appSettings: AppDefaults
@StateObject private var viewModel = SidebarToolbarViewModel() @StateObject private var viewModel = SidebarToolbarModel()
var body: some View { func body(content: Content) -> some View {
VStack { content
Divider() .toolbar {
HStack(alignment: .center) { ToolbarItem(placement: .automatic) {
Button(action: { Button(action: {
viewModel.sheetToShow = .settings viewModel.sheetToShow = .settings
}, label: { }, label: {
AppAssets.settingsImage AppAssets.settingsImage
.font(.title3) .font(.title3)
.foregroundColor(.accentColor) .foregroundColor(.accentColor)
}).help("Settings") Spacer()
}).help("Settings")
}
Spacer() ToolbarItem(placement: .automatic, content: {
Spacer()
Text("Last updated") Text("Last updated")
.font(.caption) .font(.caption)
.foregroundColor(.secondary) .foregroundColor(.secondary)
Spacer()
Spacer()
Button(action: {
viewModel.showActionSheet = true
}, label: {
AppAssets.addMenuImage
.font(.title3)
.foregroundColor(.accentColor)
}) })
.help("Add")
.actionSheet(isPresented: $viewModel.showActionSheet) { ToolbarItem(placement: .automatic, content: {
ActionSheet(title: Text("Add"), buttons: [ Button(action: {
.cancel(), viewModel.showActionSheet = true
.default(Text("Add Web Feed"), action: { viewModel.sheetToShow = .web }), }, label: {
.default(Text("Add Twitter Feed")), Spacer()
.default(Text("Add Reddit Feed")), AppAssets.addMenuImage
.default(Text("Add Folder")) .font(.title3)
]) .foregroundColor(.accentColor)
})
.help("Add")
.actionSheet(isPresented: $viewModel.showActionSheet) {
ActionSheet(title: Text("Add"), buttons: [
.cancel(),
.default(Text("Add Web Feed"), action: { viewModel.sheetToShow = .web }),
.default(Text("Add Twitter Feed")),
.default(Text("Add Reddit Feed")),
.default(Text("Add Folder"))
])
}
})
}
.sheet(isPresented: $viewModel.showSheet, onDismiss: { viewModel.sheetToShow = .none }) {
if viewModel.sheetToShow == .web {
AddWebFeedView()
}
if viewModel.sheetToShow == .settings {
SettingsView().modifier(PreferredColorSchemeModifier(preferredColorScheme: appSettings.userInterfaceColorPalette))
} }
} }
.padding(.horizontal, 16) }
.padding(.bottom, 12)
.padding(.top, 4)
}
.background(VisualEffectBlur(blurStyle: .systemChromeMaterial).edgesIgnoringSafeArea(.bottom))
.sheet(isPresented: $viewModel.showSheet, onDismiss: { viewModel.sheetToShow = .none }) {
if viewModel.sheetToShow == .web {
AddWebFeedView()
}
if viewModel.sheetToShow == .settings {
SettingsView().modifier(PreferredColorSchemeModifier(preferredColorScheme: appSettings.userInterfaceColorPalette))
}
}
}
} }
struct SidebarToolbar_Previews: PreviewProvider {
static var previews: some View {
SidebarToolbar()
}
}

View File

@ -0,0 +1,26 @@
//
// SidebarToolbarModel.swift
// NetNewsWire
//
// Created by Stuart Breckenridge on 4/7/20.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import Foundation
enum ToolbarSheets {
case none, web, twitter, reddit, folder, settings
}
class SidebarToolbarModel: ObservableObject {
@Published var showSheet: Bool = false
@Published var sheetToShow: ToolbarSheets = .none {
didSet {
sheetToShow != .none ? (showSheet = true) : (showSheet = false)
}
}
@Published var showActionSheet: Bool = false
@Published var showAddSheet: Bool = false
}

View File

@ -29,6 +29,8 @@
179DB3CE822BFCC2D774D9F4 /* AccountsNewsBlurWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 179DBBA2B22A659F81EED6F9 /* AccountsNewsBlurWindowController.swift */; }; 179DB3CE822BFCC2D774D9F4 /* AccountsNewsBlurWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 179DBBA2B22A659F81EED6F9 /* AccountsNewsBlurWindowController.swift */; };
17D232A824AFF10A0005F075 /* AddWebFeedModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17D232A724AFF10A0005F075 /* AddWebFeedModel.swift */; }; 17D232A824AFF10A0005F075 /* AddWebFeedModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17D232A724AFF10A0005F075 /* AddWebFeedModel.swift */; };
17D232A924AFF10A0005F075 /* AddWebFeedModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17D232A724AFF10A0005F075 /* AddWebFeedModel.swift */; }; 17D232A924AFF10A0005F075 /* AddWebFeedModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17D232A724AFF10A0005F075 /* AddWebFeedModel.swift */; };
17D5F17124B0BC6700375168 /* SidebarToolbarModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17D5F17024B0BC6700375168 /* SidebarToolbarModel.swift */; };
17D5F17224B0BC6700375168 /* SidebarToolbarModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17D5F17024B0BC6700375168 /* SidebarToolbarModel.swift */; };
3B3A32A5238B820900314204 /* FeedWranglerAccountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B3A328B238B820900314204 /* FeedWranglerAccountViewController.swift */; }; 3B3A32A5238B820900314204 /* FeedWranglerAccountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B3A328B238B820900314204 /* FeedWranglerAccountViewController.swift */; };
3B826DCB2385C84800FC1ADB /* AccountsFeedWrangler.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3B826DB02385C84800FC1ADB /* AccountsFeedWrangler.xib */; }; 3B826DCB2385C84800FC1ADB /* AccountsFeedWrangler.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3B826DB02385C84800FC1ADB /* AccountsFeedWrangler.xib */; };
3B826DCC2385C84800FC1ADB /* AccountsFeedWranglerWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B826DCA2385C84800FC1ADB /* AccountsFeedWranglerWindowController.swift */; }; 3B826DCC2385C84800FC1ADB /* AccountsFeedWranglerWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B826DCA2385C84800FC1ADB /* AccountsFeedWranglerWindowController.swift */; };
@ -1731,6 +1733,7 @@
179DBBA2B22A659F81EED6F9 /* AccountsNewsBlurWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountsNewsBlurWindowController.swift; sourceTree = "<group>"; }; 179DBBA2B22A659F81EED6F9 /* AccountsNewsBlurWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountsNewsBlurWindowController.swift; sourceTree = "<group>"; };
17B223DB24AC24D2001E4592 /* TimelineLayoutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineLayoutView.swift; sourceTree = "<group>"; }; 17B223DB24AC24D2001E4592 /* TimelineLayoutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineLayoutView.swift; sourceTree = "<group>"; };
17D232A724AFF10A0005F075 /* AddWebFeedModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddWebFeedModel.swift; sourceTree = "<group>"; }; 17D232A724AFF10A0005F075 /* AddWebFeedModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddWebFeedModel.swift; sourceTree = "<group>"; };
17D5F17024B0BC6700375168 /* SidebarToolbarModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarToolbarModel.swift; sourceTree = "<group>"; };
3B3A328B238B820900314204 /* FeedWranglerAccountViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedWranglerAccountViewController.swift; sourceTree = "<group>"; }; 3B3A328B238B820900314204 /* FeedWranglerAccountViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedWranglerAccountViewController.swift; sourceTree = "<group>"; };
3B826DB02385C84800FC1ADB /* AccountsFeedWrangler.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AccountsFeedWrangler.xib; sourceTree = "<group>"; }; 3B826DB02385C84800FC1ADB /* AccountsFeedWrangler.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AccountsFeedWrangler.xib; sourceTree = "<group>"; };
3B826DCA2385C84800FC1ADB /* AccountsFeedWranglerWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountsFeedWranglerWindowController.swift; sourceTree = "<group>"; }; 3B826DCA2385C84800FC1ADB /* AccountsFeedWranglerWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountsFeedWranglerWindowController.swift; sourceTree = "<group>"; };
@ -2963,6 +2966,7 @@
51919FAE24AA8EFA00541E64 /* SidebarItemView.swift */, 51919FAE24AA8EFA00541E64 /* SidebarItemView.swift */,
51E499FC24A9137600B667CB /* SidebarModel.swift */, 51E499FC24A9137600B667CB /* SidebarModel.swift */,
172199F024AB716900A31D04 /* SidebarToolbar.swift */, 172199F024AB716900A31D04 /* SidebarToolbar.swift */,
17D5F17024B0BC6700375168 /* SidebarToolbarModel.swift */,
51919FA524AA64B000541E64 /* SidebarView.swift */, 51919FA524AA64B000541E64 /* SidebarView.swift */,
51919FAB24AA8CCA00541E64 /* UnreadCountView.swift */, 51919FAB24AA8CCA00541E64 /* UnreadCountView.swift */,
); );
@ -3972,46 +3976,46 @@
TargetAttributes = { TargetAttributes = {
51314636235A7BBE00387FDC = { 51314636235A7BBE00387FDC = {
CreatedOnToolsVersion = 11.2; CreatedOnToolsVersion = 11.2;
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
LastSwiftMigration = 1120; LastSwiftMigration = 1120;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
}; };
513C5CE5232571C2003D4054 = { 513C5CE5232571C2003D4054 = {
CreatedOnToolsVersion = 11.0; CreatedOnToolsVersion = 11.0;
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
}; };
518B2ED12351B3DD00400001 = { 518B2ED12351B3DD00400001 = {
CreatedOnToolsVersion = 11.2; CreatedOnToolsVersion = 11.2;
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
TestTargetID = 840D617B2029031C009BC708; TestTargetID = 840D617B2029031C009BC708;
}; };
51C0513C24A77DF800194D5E = { 51C0513C24A77DF800194D5E = {
CreatedOnToolsVersion = 12.0; CreatedOnToolsVersion = 12.0;
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
}; };
51C0514324A77DF800194D5E = { 51C0514324A77DF800194D5E = {
CreatedOnToolsVersion = 12.0; CreatedOnToolsVersion = 12.0;
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
}; };
6581C73220CED60000F4AD34 = { 6581C73220CED60000F4AD34 = {
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
}; };
65ED3FA2235DEF6C0081F399 = { 65ED3FA2235DEF6C0081F399 = {
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
}; };
65ED4090235DEF770081F399 = { 65ED4090235DEF770081F399 = {
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
}; };
840D617B2029031C009BC708 = { 840D617B2029031C009BC708 = {
CreatedOnToolsVersion = 9.3; CreatedOnToolsVersion = 9.3;
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
SystemCapabilities = { SystemCapabilities = {
com.apple.BackgroundModes = { com.apple.BackgroundModes = {
@ -4021,7 +4025,7 @@
}; };
849C645F1ED37A5D003D8FC0 = { 849C645F1ED37A5D003D8FC0 = {
CreatedOnToolsVersion = 8.2.1; CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
SystemCapabilities = { SystemCapabilities = {
com.apple.HardenedRuntime = { com.apple.HardenedRuntime = {
@ -4031,7 +4035,7 @@
}; };
849C64701ED37A5D003D8FC0 = { 849C64701ED37A5D003D8FC0 = {
CreatedOnToolsVersion = 8.2.1; CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
TestTargetID = 849C645F1ED37A5D003D8FC0; TestTargetID = 849C645F1ED37A5D003D8FC0;
}; };
@ -4797,6 +4801,7 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
17D5F17124B0BC6700375168 /* SidebarToolbarModel.swift in Sources */,
51E4995924A873F900B667CB /* ErrorHandler.swift in Sources */, 51E4995924A873F900B667CB /* ErrorHandler.swift in Sources */,
51392D1B24AC19A000BE0D35 /* SidebarExpandedContainers.swift in Sources */, 51392D1B24AC19A000BE0D35 /* SidebarExpandedContainers.swift in Sources */,
51E4992F24A8676400B667CB /* ArticleArray.swift in Sources */, 51E4992F24A8676400B667CB /* ArticleArray.swift in Sources */,
@ -4915,6 +4920,7 @@
51E4990824A808C300B667CB /* RSHTMLMetadata+Extension.swift in Sources */, 51E4990824A808C300B667CB /* RSHTMLMetadata+Extension.swift in Sources */,
51919FF824AB8B7700541E64 /* TimelineView.swift in Sources */, 51919FF824AB8B7700541E64 /* TimelineView.swift in Sources */,
51E4992B24A8676300B667CB /* ArticleArray.swift in Sources */, 51E4992B24A8676300B667CB /* ArticleArray.swift in Sources */,
17D5F17224B0BC6700375168 /* SidebarToolbarModel.swift in Sources */,
514E6C0724AD2B5F00AC6F6E /* Image-Extensions.swift in Sources */, 514E6C0724AD2B5F00AC6F6E /* Image-Extensions.swift in Sources */,
51E4994D24A8734C00B667CB /* ExtensionPointIdentifer.swift in Sources */, 51E4994D24A8734C00B667CB /* ExtensionPointIdentifer.swift in Sources */,
51E4992224A8095600B667CB /* URL-Extensions.swift in Sources */, 51E4992224A8095600B667CB /* URL-Extensions.swift in Sources */,