From c0755fe55bab263fd31615a1522633d9b0042800 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Sat, 4 Jul 2020 21:07:18 +0800 Subject: [PATCH 1/3] Add Web Feed Layout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #2194 • Views are aligned using `LazyVGrid` and some `.padding()` --- Multiplatform/Shared/Add/AddWebFeedView.swift | 56 ++++++++++++++----- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/Multiplatform/Shared/Add/AddWebFeedView.swift b/Multiplatform/Shared/Add/AddWebFeedView.swift index 5741e6e1b..f0d745d45 100644 --- a/Multiplatform/Shared/Add/AddWebFeedView.swift +++ b/Multiplatform/Shared/Add/AddWebFeedView.swift @@ -49,23 +49,34 @@ struct AddWebFeedView: View { Form { HStack { Spacer() - Image(systemName: "globe").foregroundColor(.accentColor).font(.title) + Image("FaviconTemplateImage") + .resizable() + .renderingMode(.template) + .frame(width: 30, height: 30) + .foregroundColor(.accentColor).font(.title) Text("Add a Web Feed") .font(.title) Spacer() } - urlTextField - .textFieldStyle(RoundedBorderTextFieldStyle()) - .help("The URL of the feed you want to add.") - providedNameTextField - .textFieldStyle(RoundedBorderTextFieldStyle()) - .help("The name of the feed. (Optional.)") - folderPicker - .help("Pick the folder you want to add the feed to.") + + LazyVGrid(columns: [GridItem(.fixed(75), spacing: 10, alignment: .trailing),GridItem(.fixed(400), spacing: 0, alignment: .leading) ], alignment: .leading, spacing: 10, pinnedViews: [], content:{ + + Text("URL:").bold() + urlTextField + .textFieldStyle(RoundedBorderTextFieldStyle()) + .help("The URL of the feed you want to add.") + Text("Name:").bold() + providedNameTextField + .textFieldStyle(RoundedBorderTextFieldStyle()) + .help("The name of the feed. (Optional.)") + Text("Folder:").bold() + folderPicker + .help("Pick the folder you want to add the feed to.") + }) buttonStack } - .padding() - .frame(minWidth: 450) + .frame(maxWidth: 485) + .padding(12) } #endif @@ -98,8 +109,8 @@ struct AddWebFeedView: View { var urlTextField: some View { HStack { - Text("Feed:") #if os(iOS) + Text("Feed:") TextField("URL", text: $viewModel.providedURL) .disableAutocorrection(true) .autocapitalization(UITextAutocapitalizationType.none) @@ -112,12 +123,15 @@ struct AddWebFeedView: View { var providedNameTextField: some View { HStack(alignment: .lastTextBaseline) { + #if os(iOS) Text("Name:") + #endif TextField("Optional", text: $viewModel.providedName) } } - var folderPicker: some View { + @ViewBuilder var folderPicker: some View { + #if os(iOS) Picker("Folder:", selection: $viewModel.selectedFolderIndex, content: { ForEach(0.. Date: Sat, 4 Jul 2020 21:34:15 +0800 Subject: [PATCH 2/3] Sidebar toolbar no longer an overlay Also moved view model to separate file and removed the view prefix. --- .../Sidebar/CompactSidebarContainerView.swift | 7 +- .../Sidebar/RegularSidebarContainerView.swift | 6 +- .../Shared/Sidebar/SidebarToolbar.swift | 124 ++++++++---------- .../Shared/Sidebar/SidebarToolbarModel.swift | 26 ++++ NetNewsWire.xcodeproj/project.pbxproj | 28 ++-- 5 files changed, 98 insertions(+), 93 deletions(-) create mode 100644 Multiplatform/Shared/Sidebar/SidebarToolbarModel.swift diff --git a/Multiplatform/Shared/Sidebar/CompactSidebarContainerView.swift b/Multiplatform/Shared/Sidebar/CompactSidebarContainerView.swift index a14b01503..686f01ebd 100644 --- a/Multiplatform/Shared/Sidebar/CompactSidebarContainerView.swift +++ b/Multiplatform/Shared/Sidebar/CompactSidebarContainerView.swift @@ -16,6 +16,7 @@ struct CompactSidebarContainerView: View { var body: some View { SidebarView() + .modifier(SidebarToolbar()) .environmentObject(sidebarModel) .navigationBarTitle(Text("Feeds")) .listStyle(PlainListStyle()) @@ -23,11 +24,7 @@ struct CompactSidebarContainerView: View { sceneModel.sidebarModel = sidebarModel sidebarModel.delegate = sceneModel sidebarModel.rebuildSidebarItems() - }.overlay(Group { - #if os(iOS) - SidebarToolbar() - #endif - },alignment: .bottom) + } } } diff --git a/Multiplatform/Shared/Sidebar/RegularSidebarContainerView.swift b/Multiplatform/Shared/Sidebar/RegularSidebarContainerView.swift index f2440a746..bd2e05a42 100644 --- a/Multiplatform/Shared/Sidebar/RegularSidebarContainerView.swift +++ b/Multiplatform/Shared/Sidebar/RegularSidebarContainerView.swift @@ -17,6 +17,7 @@ struct RegularSidebarContainerView: View { @ViewBuilder var body: some View { SidebarView() + .modifier(SidebarToolbar()) .environmentObject(sidebarModel) .navigationTitle(Text("Feeds")) .listStyle(SidebarListStyle()) @@ -25,11 +26,6 @@ struct RegularSidebarContainerView: View { sidebarModel.delegate = sceneModel sidebarModel.rebuildSidebarItems() } - .overlay(Group { - #if os(iOS) - SidebarToolbar() - #endif - },alignment: .bottom) } diff --git a/Multiplatform/Shared/Sidebar/SidebarToolbar.swift b/Multiplatform/Shared/Sidebar/SidebarToolbar.swift index 90d4a7e39..969809e22 100644 --- a/Multiplatform/Shared/Sidebar/SidebarToolbar.swift +++ b/Multiplatform/Shared/Sidebar/SidebarToolbar.swift @@ -8,85 +8,65 @@ import SwiftUI -fileprivate enum ToolbarSheets { - case none, web, twitter, reddit, folder, settings -} -fileprivate class SidebarToolbarViewModel: 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 - -} - -struct SidebarToolbar: View { +struct SidebarToolbar: ViewModifier { @EnvironmentObject private var appSettings: AppDefaults - @StateObject private var viewModel = SidebarToolbarViewModel() + @StateObject private var viewModel = SidebarToolbarModel() - var body: some View { - VStack { - Divider() - HStack(alignment: .center) { - Button(action: { - viewModel.sheetToShow = .settings - }, label: { - AppAssets.settingsImage - .font(.title3) - .foregroundColor(.accentColor) - }).help("Settings") + func body(content: Content) -> some View { + content + .toolbar { + ToolbarItem(placement: .automatic) { + Button(action: { + viewModel.sheetToShow = .settings + }, label: { + AppAssets.settingsImage + .font(.title3) + .foregroundColor(.accentColor) + Spacer() + }).help("Settings") + } - Spacer() - - Text("Last updated") - .font(.caption) - .foregroundColor(.secondary) - - Spacer() - - Button(action: { - viewModel.showActionSheet = true - }, label: { - AppAssets.addMenuImage - .font(.title3) - .foregroundColor(.accentColor) + ToolbarItem(placement: .automatic, content: { + Spacer() + Text("Last updated") + .font(.caption) + .foregroundColor(.secondary) + Spacer() }) - .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")) - ]) + + ToolbarItem(placement: .automatic, content: { + Button(action: { + viewModel.showActionSheet = true + }, label: { + Spacer() + AppAssets.addMenuImage + .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() - } -} + diff --git a/Multiplatform/Shared/Sidebar/SidebarToolbarModel.swift b/Multiplatform/Shared/Sidebar/SidebarToolbarModel.swift new file mode 100644 index 000000000..000066277 --- /dev/null +++ b/Multiplatform/Shared/Sidebar/SidebarToolbarModel.swift @@ -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 + +} diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index bdb2dc841..ea58b06bd 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -29,6 +29,8 @@ 179DB3CE822BFCC2D774D9F4 /* AccountsNewsBlurWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 179DBBA2B22A659F81EED6F9 /* AccountsNewsBlurWindowController.swift */; }; 17D232A824AFF10A0005F075 /* 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 */; }; 3B826DCB2385C84800FC1ADB /* AccountsFeedWrangler.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3B826DB02385C84800FC1ADB /* AccountsFeedWrangler.xib */; }; 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 = ""; }; 17B223DB24AC24D2001E4592 /* TimelineLayoutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineLayoutView.swift; sourceTree = ""; }; 17D232A724AFF10A0005F075 /* AddWebFeedModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddWebFeedModel.swift; sourceTree = ""; }; + 17D5F17024B0BC6700375168 /* SidebarToolbarModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarToolbarModel.swift; sourceTree = ""; }; 3B3A328B238B820900314204 /* FeedWranglerAccountViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedWranglerAccountViewController.swift; sourceTree = ""; }; 3B826DB02385C84800FC1ADB /* AccountsFeedWrangler.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AccountsFeedWrangler.xib; sourceTree = ""; }; 3B826DCA2385C84800FC1ADB /* AccountsFeedWranglerWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountsFeedWranglerWindowController.swift; sourceTree = ""; }; @@ -2963,6 +2966,7 @@ 51919FAE24AA8EFA00541E64 /* SidebarItemView.swift */, 51E499FC24A9137600B667CB /* SidebarModel.swift */, 172199F024AB716900A31D04 /* SidebarToolbar.swift */, + 17D5F17024B0BC6700375168 /* SidebarToolbarModel.swift */, 51919FA524AA64B000541E64 /* SidebarView.swift */, 51919FAB24AA8CCA00541E64 /* UnreadCountView.swift */, ); @@ -3972,46 +3976,46 @@ TargetAttributes = { 51314636235A7BBE00387FDC = { CreatedOnToolsVersion = 11.2; - DevelopmentTeam = SHJK2V3AJG; + DevelopmentTeam = FQLBNX3GP7; LastSwiftMigration = 1120; ProvisioningStyle = Automatic; }; 513C5CE5232571C2003D4054 = { CreatedOnToolsVersion = 11.0; - DevelopmentTeam = SHJK2V3AJG; + DevelopmentTeam = FQLBNX3GP7; ProvisioningStyle = Automatic; }; 518B2ED12351B3DD00400001 = { CreatedOnToolsVersion = 11.2; - DevelopmentTeam = SHJK2V3AJG; + DevelopmentTeam = FQLBNX3GP7; ProvisioningStyle = Automatic; TestTargetID = 840D617B2029031C009BC708; }; 51C0513C24A77DF800194D5E = { CreatedOnToolsVersion = 12.0; - DevelopmentTeam = SHJK2V3AJG; + DevelopmentTeam = FQLBNX3GP7; ProvisioningStyle = Automatic; }; 51C0514324A77DF800194D5E = { CreatedOnToolsVersion = 12.0; - DevelopmentTeam = SHJK2V3AJG; + DevelopmentTeam = FQLBNX3GP7; ProvisioningStyle = Automatic; }; 6581C73220CED60000F4AD34 = { - DevelopmentTeam = SHJK2V3AJG; + DevelopmentTeam = FQLBNX3GP7; ProvisioningStyle = Automatic; }; 65ED3FA2235DEF6C0081F399 = { - DevelopmentTeam = SHJK2V3AJG; + DevelopmentTeam = FQLBNX3GP7; ProvisioningStyle = Automatic; }; 65ED4090235DEF770081F399 = { - DevelopmentTeam = SHJK2V3AJG; + DevelopmentTeam = FQLBNX3GP7; ProvisioningStyle = Automatic; }; 840D617B2029031C009BC708 = { CreatedOnToolsVersion = 9.3; - DevelopmentTeam = SHJK2V3AJG; + DevelopmentTeam = FQLBNX3GP7; ProvisioningStyle = Automatic; SystemCapabilities = { com.apple.BackgroundModes = { @@ -4021,7 +4025,7 @@ }; 849C645F1ED37A5D003D8FC0 = { CreatedOnToolsVersion = 8.2.1; - DevelopmentTeam = SHJK2V3AJG; + DevelopmentTeam = FQLBNX3GP7; ProvisioningStyle = Automatic; SystemCapabilities = { com.apple.HardenedRuntime = { @@ -4031,7 +4035,7 @@ }; 849C64701ED37A5D003D8FC0 = { CreatedOnToolsVersion = 8.2.1; - DevelopmentTeam = SHJK2V3AJG; + DevelopmentTeam = FQLBNX3GP7; ProvisioningStyle = Automatic; TestTargetID = 849C645F1ED37A5D003D8FC0; }; @@ -4797,6 +4801,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 17D5F17124B0BC6700375168 /* SidebarToolbarModel.swift in Sources */, 51E4995924A873F900B667CB /* ErrorHandler.swift in Sources */, 51392D1B24AC19A000BE0D35 /* SidebarExpandedContainers.swift in Sources */, 51E4992F24A8676400B667CB /* ArticleArray.swift in Sources */, @@ -4915,6 +4920,7 @@ 51E4990824A808C300B667CB /* RSHTMLMetadata+Extension.swift in Sources */, 51919FF824AB8B7700541E64 /* TimelineView.swift in Sources */, 51E4992B24A8676300B667CB /* ArticleArray.swift in Sources */, + 17D5F17224B0BC6700375168 /* SidebarToolbarModel.swift in Sources */, 514E6C0724AD2B5F00AC6F6E /* Image-Extensions.swift in Sources */, 51E4994D24A8734C00B667CB /* ExtensionPointIdentifer.swift in Sources */, 51E4992224A8095600B667CB /* URL-Extensions.swift in Sources */, From 294591d154d2904a2242613d2bd7af0b39fd702f Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Sat, 4 Jul 2020 22:01:01 +0800 Subject: [PATCH 3/3] Fixes compile crash with sidebar toolbar --- Multiplatform/Shared/Add/AddWebFeedView.swift | 3 +-- .../Shared/Sidebar/RegularSidebarContainerView.swift | 1 - Multiplatform/Shared/Sidebar/SidebarToolbar.swift | 11 ++++++++++- NetNewsWire.xcodeproj/project.pbxproj | 2 ++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Multiplatform/Shared/Add/AddWebFeedView.swift b/Multiplatform/Shared/Add/AddWebFeedView.swift index f0d745d45..2ab535457 100644 --- a/Multiplatform/Shared/Add/AddWebFeedView.swift +++ b/Multiplatform/Shared/Add/AddWebFeedView.swift @@ -49,11 +49,10 @@ struct AddWebFeedView: View { Form { HStack { Spacer() - Image("FaviconTemplateImage") + Image(rsImage: AppAssets.faviconTemplateImage) .resizable() .renderingMode(.template) .frame(width: 30, height: 30) - .foregroundColor(.accentColor).font(.title) Text("Add a Web Feed") .font(.title) Spacer() diff --git a/Multiplatform/Shared/Sidebar/RegularSidebarContainerView.swift b/Multiplatform/Shared/Sidebar/RegularSidebarContainerView.swift index bd2e05a42..c5311d586 100644 --- a/Multiplatform/Shared/Sidebar/RegularSidebarContainerView.swift +++ b/Multiplatform/Shared/Sidebar/RegularSidebarContainerView.swift @@ -26,7 +26,6 @@ struct RegularSidebarContainerView: View { sidebarModel.delegate = sceneModel sidebarModel.rebuildSidebarItems() } - } } diff --git a/Multiplatform/Shared/Sidebar/SidebarToolbar.swift b/Multiplatform/Shared/Sidebar/SidebarToolbar.swift index 969809e22..77d6a5799 100644 --- a/Multiplatform/Shared/Sidebar/SidebarToolbar.swift +++ b/Multiplatform/Shared/Sidebar/SidebarToolbar.swift @@ -14,7 +14,8 @@ struct SidebarToolbar: ViewModifier { @EnvironmentObject private var appSettings: AppDefaults @StateObject private var viewModel = SidebarToolbarModel() - func body(content: Content) -> some View { + @ViewBuilder func body(content: Content) -> some View { + #if os(iOS) content .toolbar { ToolbarItem(placement: .automatic) { @@ -66,6 +67,14 @@ struct SidebarToolbar: ViewModifier { SettingsView().modifier(PreferredColorSchemeModifier(preferredColorScheme: appSettings.userInterfaceColorPalette)) } } + #else + content + .toolbar { + ToolbarItem { + Spacer() + } + } + #endif } } diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index ea58b06bd..dd7e01732 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -31,6 +31,7 @@ 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 */; }; + 17D5F19524B0C1DD00375168 /* SidebarToolbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 172199F024AB716900A31D04 /* SidebarToolbar.swift */; }; 3B3A32A5238B820900314204 /* FeedWranglerAccountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B3A328B238B820900314204 /* FeedWranglerAccountViewController.swift */; }; 3B826DCB2385C84800FC1ADB /* AccountsFeedWrangler.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3B826DB02385C84800FC1ADB /* AccountsFeedWrangler.xib */; }; 3B826DCC2385C84800FC1ADB /* AccountsFeedWranglerWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B826DCA2385C84800FC1ADB /* AccountsFeedWranglerWindowController.swift */; }; @@ -4965,6 +4966,7 @@ 51E4995024A8734C00B667CB /* ExtensionPoint.swift in Sources */, 51E4990E24A808CC00B667CB /* HTMLMetadataDownloader.swift in Sources */, 51E498FB24A808BA00B667CB /* FaviconGenerator.swift in Sources */, + 17D5F19524B0C1DD00375168 /* SidebarToolbar.swift in Sources */, 51E4996724A8760B00B667CB /* ArticleStylesManager.swift in Sources */, 1729529B24AA1FD200D65E66 /* MacSearchField.swift in Sources */, 51408B7F24A9EC6F0073CF4E /* SidebarItem.swift in Sources */,