From ee69714b90ffcff718021118664b36dd94f6f50f Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Fri, 17 Jul 2020 20:47:49 +0800 Subject: [PATCH 1/3] Adds timeline preview to viewing pane --- .../Viewing/LayoutPreferencesView.swift | 90 +++++++++++++++---- 1 file changed, 72 insertions(+), 18 deletions(-) diff --git a/Multiplatform/macOS/Preferences/Preference Panes/Viewing/LayoutPreferencesView.swift b/Multiplatform/macOS/Preferences/Preference Panes/Viewing/LayoutPreferencesView.swift index ef08cf3b1..0d7e0cc95 100644 --- a/Multiplatform/macOS/Preferences/Preference Panes/Viewing/LayoutPreferencesView.swift +++ b/Multiplatform/macOS/Preferences/Preference Panes/Viewing/LayoutPreferencesView.swift @@ -12,30 +12,84 @@ struct LayoutPreferencesView: View { @EnvironmentObject var defaults: AppDefaults private let colorPalettes = UserInterfaceColorPalette.allCases + private let sampleTitle = "Lorem dolor sed viverra ipsum. Gravida rutrum quisque non tellus. Rutrum tellus pellentesque eu tincidunt tortor. Sed blandit libero volutpat sed cras ornare. Et netus et malesuada fames ac. Ultrices eros in cursus turpis massa tincidunt dui ut ornare. Lacus sed viverra tellus in. Sollicitudin ac orci phasellus egestas. Purus in mollis nunc sed. Sollicitudin ac orci phasellus egestas tellus rutrum tellus pellentesque. Interdum consectetur libero id faucibus nisl tincidunt eget." var body: some View { - Form { - Picker("Appearance", selection: $defaults.userInterfaceColorPalette, content: { - ForEach(colorPalettes, id: \.self, content: { - Text($0.description) + + VStack { + Form { + Picker("Appearance", selection: $defaults.userInterfaceColorPalette, content: { + ForEach(colorPalettes, id: \.self, content: { + Text($0.description) + }) }) - }) + + Divider() + + Text("Timeline: ") + Picker("Number of Lines", selection: $defaults.timelineNumberOfLines, content: { + ForEach(1..<6, content: { i in + Text(String(i)) + .tag(Double(i)) + }) + }).padding(.leading, 16) + Slider(value: $defaults.timelineIconDimensions, in: 20...60, step: 10, minimumValueLabel: Text("Small"), maximumValueLabel: Text("Large"), label: { + Text("Icon size") + }).padding(.leading, 16) + + } - Divider() + timelineRowPreview + .frame(width: 300) + .padding() + .overlay( + RoundedRectangle(cornerRadius: 8, style: .continuous) + .stroke(Color.gray, lineWidth: 1) + ) + .animation(.default) + + Text("PREVIEW") + .font(.caption) + .tracking(0.3) + Spacer() - Text("Timeline: ") - Picker("Number of Lines", selection: $defaults.timelineNumberOfLines, content: { - ForEach(1..<6, content: { i in - Text(String(i)) - .tag(Double(i)) - }) - }).padding(.leading, 16) - Slider(value: $defaults.timelineIconDimensions, in: 20...60, step: 10, minimumValueLabel: Text("Small"), maximumValueLabel: Text("Large"), label: { - Text("Icon Size") - }).padding(.leading, 16) - } - .frame(width: 400, alignment: .center) + }.frame(width: 400, height: 300, alignment: .center) + + + } + + @ViewBuilder + var timelineRowPreview: some View { + HStack(alignment: .top) { + Image(systemName: "circle.fill") + .resizable() + .frame(width: 10, height: 10, alignment: .top) + .foregroundColor(.accentColor) + + Image(systemName: "paperplane.circle") + .resizable() + .frame(width: CGFloat(defaults.timelineIconDimensions), height: CGFloat(defaults.timelineIconDimensions), alignment: .top) + .foregroundColor(.accentColor) + + VStack(alignment: .leading, spacing: 4) { + Text(sampleTitle) + .font(.headline) + .lineLimit(Int(defaults.timelineNumberOfLines)) + HStack { + Text("Feed Name") + .foregroundColor(.secondary) + .font(.footnote) + Spacer() + Text("10:31") + .font(.footnote) + .foregroundColor(.secondary) + } + } + } + } + + } struct SwiftUIView_Previews: PreviewProvider { From b739f6dd61addf197b4419541fc203ec82c61f91 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Fri, 17 Jul 2020 22:18:10 +0800 Subject: [PATCH 2/3] Improves behaviour of dark/light changes on iOS --- Multiplatform/Shared/AppDefaults.swift | 4 +++- Multiplatform/Shared/MainApp.swift | 2 +- Multiplatform/Shared/Sidebar/SidebarToolbarModifier.swift | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Multiplatform/Shared/AppDefaults.swift b/Multiplatform/Shared/AppDefaults.swift index 39f53d5e1..f94d62813 100644 --- a/Multiplatform/Shared/AppDefaults.swift +++ b/Multiplatform/Shared/AppDefaults.swift @@ -134,7 +134,9 @@ final class AppDefaults: ObservableObject { } set { AppDefaults.store.set(newValue.rawValue, forKey: Key.userInterfaceColorPalette) - objectWillChange.send() + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { + self.objectWillChange.send() + }) } } diff --git a/Multiplatform/Shared/MainApp.swift b/Multiplatform/Shared/MainApp.swift index 73ebbc4a7..739259a04 100644 --- a/Multiplatform/Shared/MainApp.swift +++ b/Multiplatform/Shared/MainApp.swift @@ -93,7 +93,7 @@ struct MainApp: App { .onAppear { refreshProgress.startup() } .environmentObject(refreshProgress) .environmentObject(defaults) - .modifier(PreferredColorSchemeModifier(preferredColorScheme: defaults.userInterfaceColorPalette)) + .preferredColorScheme(AppDefaults.userInterfaceColorScheme) } .commands { CommandGroup(after: .newItem, addition: { diff --git a/Multiplatform/Shared/Sidebar/SidebarToolbarModifier.swift b/Multiplatform/Shared/Sidebar/SidebarToolbarModifier.swift index bde459e27..d33d38c85 100644 --- a/Multiplatform/Shared/Sidebar/SidebarToolbarModifier.swift +++ b/Multiplatform/Shared/Sidebar/SidebarToolbarModifier.swift @@ -94,7 +94,8 @@ struct SidebarToolbarModifier: ViewModifier { AddFolderView() } if viewModel.sheetToShow == .settings { - SettingsView().modifier(PreferredColorSchemeModifier(preferredColorScheme: defaults.userInterfaceColorPalette)) + SettingsView() + .preferredColorScheme(AppDefaults.userInterfaceColorScheme) } } #else From 19d4afc467e01c6e3c62e2e3099933cd1c1da36c Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Fri, 17 Jul 2020 22:33:38 +0800 Subject: [PATCH 3/3] On macOS, just change the colorScheme --- Multiplatform/Shared/AppDefaults.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Multiplatform/Shared/AppDefaults.swift b/Multiplatform/Shared/AppDefaults.swift index f94d62813..408154b33 100644 --- a/Multiplatform/Shared/AppDefaults.swift +++ b/Multiplatform/Shared/AppDefaults.swift @@ -134,9 +134,13 @@ final class AppDefaults: ObservableObject { } set { AppDefaults.store.set(newValue.rawValue, forKey: Key.userInterfaceColorPalette) + #if os(macOS) + self.objectWillChange.send() + #else DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { self.objectWillChange.send() }) + #endif } }