From 1902d0be1cf022f047892687f532f8556e306a7f Mon Sep 17 00:00:00 2001 From: Brian Moakley Date: Tue, 27 Oct 2020 10:26:05 -0400 Subject: [PATCH 1/3] Disable sort controls when fetching data --- .../Colours/Text/Contents.json | 6 +-- .../Contents.json | 38 +++++++++++++++++++ Emitron/Emitron/UI/Library/LibraryView.swift | 28 +++++++++++--- 3 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 Emitron/Emitron/Assets.xcassets/Colours/Text/textButtonTextDisabled.colorset/Contents.json diff --git a/Emitron/Emitron/Assets.xcassets/Colours/Text/Contents.json b/Emitron/Emitron/Assets.xcassets/Colours/Text/Contents.json index da4a164c..73c00596 100644 --- a/Emitron/Emitron/Assets.xcassets/Colours/Text/Contents.json +++ b/Emitron/Emitron/Assets.xcassets/Colours/Text/Contents.json @@ -1,6 +1,6 @@ { "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 } -} \ No newline at end of file +} diff --git a/Emitron/Emitron/Assets.xcassets/Colours/Text/textButtonTextDisabled.colorset/Contents.json b/Emitron/Emitron/Assets.xcassets/Colours/Text/textButtonTextDisabled.colorset/Contents.json new file mode 100644 index 00000000..d2808066 --- /dev/null +++ b/Emitron/Emitron/Assets.xcassets/Colours/Text/textButtonTextDisabled.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "display-p3", + "components" : { + "alpha" : "1.000", + "blue" : "1.000", + "green" : "1.000", + "red" : "1.000" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "1.000", + "green" : "1.000", + "red" : "1.000" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Emitron/Emitron/UI/Library/LibraryView.swift b/Emitron/Emitron/UI/Library/LibraryView.swift index 5b796de7..e60e6c60 100644 --- a/Emitron/Emitron/UI/Library/LibraryView.swift +++ b/Emitron/Emitron/UI/Library/LibraryView.swift @@ -27,6 +27,7 @@ // THE SOFTWARE. import SwiftUI +import Combine private extension CGFloat { static let filterButtonSide: CGFloat = 27 @@ -39,6 +40,7 @@ struct LibraryView: View { @ObservedObject var filters: Filters @ObservedObject var libraryRepository: LibraryRepository @State var filtersPresented: Bool = false + @State var isSorting: Bool = true var body: some View { contentView @@ -49,8 +51,16 @@ struct LibraryView: View { FiltersView(libraryRepository: libraryRepository, filters: filters) .background(Color.backgroundColor.edgesIgnoringSafeArea(.all)) } + .onReceive(Just(contentView)) {_ in + switch libraryRepository.state { + case .loading, .loadingAdditional: + isSorting = true + default: + isSorting = false + } + } } - + private var contentControlsSection: some View { VStack { searchAndFilterControls @@ -104,12 +114,17 @@ struct LibraryView: View { HStack { Image("sort") .foregroundColor(.textButtonText) - - Text(filters.sortFilter.name) - .font(.uiLabelBold) - .foregroundColor(.textButtonText) + if isSorting { + Text(filters.sortFilter.name) + .font(.uiLabel) + .foregroundColor(Color.gray) + } else { + Text(filters.sortFilter.name) + .font(.uiLabelBold) + .foregroundColor(.textButtonText) + } } - } + }.disabled(isSorting) } } @@ -147,6 +162,7 @@ struct LibraryView: View { } private func changeSort() { + isSorting = true filters.changeSortFilter() libraryRepository.filters = filters } From 4121296f3d453acbd6c38f83bb0756c701e2e995 Mon Sep 17 00:00:00 2001 From: Brian Moakley Date: Wed, 28 Oct 2020 17:24:15 -0400 Subject: [PATCH 2/3] Remove isSorting property --- Emitron/Emitron/UI/Library/LibraryView.swift | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/Emitron/Emitron/UI/Library/LibraryView.swift b/Emitron/Emitron/UI/Library/LibraryView.swift index e60e6c60..c8e03fe4 100644 --- a/Emitron/Emitron/UI/Library/LibraryView.swift +++ b/Emitron/Emitron/UI/Library/LibraryView.swift @@ -40,7 +40,6 @@ struct LibraryView: View { @ObservedObject var filters: Filters @ObservedObject var libraryRepository: LibraryRepository @State var filtersPresented: Bool = false - @State var isSorting: Bool = true var body: some View { contentView @@ -51,14 +50,6 @@ struct LibraryView: View { FiltersView(libraryRepository: libraryRepository, filters: filters) .background(Color.backgroundColor.edgesIgnoringSafeArea(.all)) } - .onReceive(Just(contentView)) {_ in - switch libraryRepository.state { - case .loading, .loadingAdditional: - isSorting = true - default: - isSorting = false - } - } } private var contentControlsSection: some View { @@ -114,7 +105,7 @@ struct LibraryView: View { HStack { Image("sort") .foregroundColor(.textButtonText) - if isSorting { + if [.loading, .loadingAdditional].contains(libraryRepository.state) { Text(filters.sortFilter.name) .font(.uiLabel) .foregroundColor(Color.gray) @@ -124,7 +115,7 @@ struct LibraryView: View { .foregroundColor(.textButtonText) } } - }.disabled(isSorting) + }.disabled(libraryRepository.state == .loading || libraryRepository.state == .loadingAdditional) } } @@ -162,7 +153,6 @@ struct LibraryView: View { } private func changeSort() { - isSorting = true filters.changeSortFilter() libraryRepository.filters = filters } From fd24dc140e3f8b1e7803ac9a573fb43ab8a41c7d Mon Sep 17 00:00:00 2001 From: Brian Moakley Date: Thu, 29 Oct 2020 13:07:47 -0400 Subject: [PATCH 3/3] Make disabled modifier use consistent code and remove Combine import --- Emitron/Emitron/UI/Library/LibraryView.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Emitron/Emitron/UI/Library/LibraryView.swift b/Emitron/Emitron/UI/Library/LibraryView.swift index c8e03fe4..fdada262 100644 --- a/Emitron/Emitron/UI/Library/LibraryView.swift +++ b/Emitron/Emitron/UI/Library/LibraryView.swift @@ -27,7 +27,6 @@ // THE SOFTWARE. import SwiftUI -import Combine private extension CGFloat { static let filterButtonSide: CGFloat = 27 @@ -115,7 +114,7 @@ struct LibraryView: View { .foregroundColor(.textButtonText) } } - }.disabled(libraryRepository.state == .loading || libraryRepository.state == .loadingAdditional) + }.disabled([.loading, .loadingAdditional].contains(libraryRepository.state)) } }