From 8064e65e68491390d06316543cba6540914a6391 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Tue, 7 Jul 2020 16:05:26 -0500 Subject: [PATCH] Move Mac toolbar to SceneNavigationView so that it operates properly. Issue #2217 --- Multiplatform/Shared/MainApp.swift | 79 +------------------ .../Shared/SceneNavigationView.swift | 70 +++++++++++++++- 2 files changed, 70 insertions(+), 79 deletions(-) diff --git a/Multiplatform/Shared/MainApp.swift b/Multiplatform/Shared/MainApp.swift index 6cd5dcd50..d58a25751 100644 --- a/Multiplatform/Shared/MainApp.swift +++ b/Multiplatform/Shared/MainApp.swift @@ -18,86 +18,16 @@ struct MainApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) private var delegate #endif - @StateObject private var sceneModel = SceneModel() @StateObject private var defaults = AppDefaults.shared - @State private var showSheet = false - + @SceneBuilder var body: some Scene { #if os(macOS) WindowGroup { SceneNavigationView() .frame(minWidth: 600, idealWidth: 1000, maxWidth: .infinity, minHeight: 600, idealHeight: 700, maxHeight: .infinity) - .environmentObject(sceneModel) .environmentObject(defaults) - .onAppear { - sceneModel.startup() - } - .sheet(isPresented: $showSheet, onDismiss: { showSheet = false }) { - AddWebFeedView() - } - .toolbar { - - ToolbarItem() { - Menu { - Button("Add Web Feed", action: { showSheet = true }) - Button("Add Reddit Feed", action: { }) - Button("Add Twitter Feed", action: { }) - Button("Add Folder", action: { }) - } label : { - AppAssets.addMenuImage - } - } - - ToolbarItem { - Button(action: {}, label: { - AppAssets.refreshImage - }).help("Refresh").padding(.trailing, 40) - } - - ToolbarItem { - Button(action: {}, label: { - AppAssets.markAllAsReadImagePDF - .resizable() - .scaledToFit() - .frame(width: 20, height: 20, alignment: .center) - }).help("Mark All as Read") - } - - ToolbarItem { - MacSearchField() - .frame(width: 200) - } - - ToolbarItem { - Button(action: {}, label: { - AppAssets.nextUnreadArticleImage - }).help("Go to Next Unread").padding(.trailing, 40) - } - - ToolbarItem { - Button(action: {}, label: { - AppAssets.starOpenImage - }).help("Mark as Starred") - } - ToolbarItem { - Button(action: {}, label: { - AppAssets.readClosedImage - }).help("Mark as Unread") - } - ToolbarItem { - Button(action: {}, label: { - AppAssets.openInBrowserImage - }).help("Open in Browser") - } - ToolbarItem { - Button(action: {}, label: { - AppAssets.shareImage - }).help("Share") - } - - - } } + .windowToolbarStyle(UnifiedWindowToolbarStyle()) .commands { CommandGroup(after: .newItem, addition: { Button("New Feed", action: {}) @@ -138,7 +68,6 @@ struct MainApp: App { .keyboardShortcut(.rightArrow, modifiers: [.command]) }) } - .windowToolbarStyle(UnifiedWindowToolbarStyle()) // Mac Preferences Settings { @@ -155,12 +84,8 @@ struct MainApp: App { #if os(iOS) WindowGroup { SceneNavigationView() - .environmentObject(sceneModel) .environmentObject(defaults) .modifier(PreferredColorSchemeModifier(preferredColorScheme: defaults.userInterfaceColorPalette)) - .onAppear { - sceneModel.startup() - } } .commands { CommandGroup(after: .newItem, addition: { diff --git a/Multiplatform/Shared/SceneNavigationView.swift b/Multiplatform/Shared/SceneNavigationView.swift index 19998261b..f0e7ba587 100644 --- a/Multiplatform/Shared/SceneNavigationView.swift +++ b/Multiplatform/Shared/SceneNavigationView.swift @@ -9,7 +9,10 @@ import SwiftUI struct SceneNavigationView: View { - + + @StateObject private var sceneModel = SceneModel() + @State private var showSheet = false + #if os(iOS) @Environment(\.horizontalSizeClass) private var horizontalSizeClass #endif @@ -42,7 +45,70 @@ struct SceneNavigationView: View { .frame(maxWidth: .infinity, maxHeight: .infinity) #endif } - + .environmentObject(sceneModel) + .onAppear { + sceneModel.startup() + } + .sheet(isPresented: $showSheet, onDismiss: { showSheet = false }) { + AddWebFeedView() + } + .toolbar { + + #if os(macOS) + ToolbarItem() { + Menu { + Button("Add Web Feed", action: { showSheet = true }) + Button("Add Reddit Feed", action: { }) + Button("Add Twitter Feed", action: { }) + Button("Add Folder", action: { }) + } label : { + AppAssets.addMenuImage + } + } + ToolbarItem { + Button(action: {}, label: { + AppAssets.refreshImage + }).help("Refresh").padding(.trailing, 40) + } + ToolbarItem { + Button(action: {}, label: { + AppAssets.markAllAsReadImagePDF + .resizable() + .scaledToFit() + .frame(width: 20, height: 20, alignment: .center) + }).help("Mark All as Read") + } + ToolbarItem { + MacSearchField() + .frame(width: 200) + } + ToolbarItem { + Button(action: {}, label: { + AppAssets.nextUnreadArticleImage + }).help("Go to Next Unread").padding(.trailing, 40) + } + ToolbarItem { + Button(action: {}, label: { + AppAssets.starOpenImage + }).help("Mark as Starred") + } + ToolbarItem { + Button(action: {}, label: { + AppAssets.readClosedImage + }).help("Mark as Unread") + } + ToolbarItem { + Button(action: {}, label: { + AppAssets.openInBrowserImage + }).help("Open in Browser") + } + ToolbarItem { + Button(action: {}, label: { + AppAssets.shareImage + }).help("Share") + } + #endif + } } }