From a007b7a98005b2ec275bbb93ba4cc32d45681b7b Mon Sep 17 00:00:00 2001 From: sunxiaojian Date: Fri, 9 Apr 2021 20:38:02 +0800 Subject: [PATCH] fix: color in Light Mode, fix search result disappear when push new page --- Mastodon/Generated/Assets.swift | 1 + .../searchResult.colorset/Contents.json | 38 +++++++++++++++++++ .../Scene/Search/SearchViewController.swift | 2 +- Mastodon/Scene/Search/SearchViewModel.swift | 28 +++++++------- 4 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 Mastodon/Resources/Assets.xcassets/Colors/Background/searchResult.colorset/Contents.json diff --git a/Mastodon/Generated/Assets.swift b/Mastodon/Generated/Assets.swift index eb69bda1..b6cdde9c 100644 --- a/Mastodon/Generated/Assets.swift +++ b/Mastodon/Generated/Assets.swift @@ -44,6 +44,7 @@ internal enum Asset { internal static let mediaTypeIndicotor = ColorAsset(name: "Colors/Background/media.type.indicotor") internal static let navigationBar = ColorAsset(name: "Colors/Background/navigationBar") internal static let onboardingBackground = ColorAsset(name: "Colors/Background/onboarding.background") + internal static let searchResult = ColorAsset(name: "Colors/Background/searchResult") internal static let secondaryGroupedSystemBackground = ColorAsset(name: "Colors/Background/secondary.grouped.system.background") internal static let secondarySystemBackground = ColorAsset(name: "Colors/Background/secondary.system.background") internal static let systemBackground = ColorAsset(name: "Colors/Background/system.background") diff --git a/Mastodon/Resources/Assets.xcassets/Colors/Background/searchResult.colorset/Contents.json b/Mastodon/Resources/Assets.xcassets/Colors/Background/searchResult.colorset/Contents.json new file mode 100644 index 00000000..3338422a --- /dev/null +++ b/Mastodon/Resources/Assets.xcassets/Colors/Background/searchResult.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0xFE", + "green" : "0xFF", + "red" : "0xFE" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0x00", + "green" : "0x00", + "red" : "0x00" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Mastodon/Scene/Search/SearchViewController.swift b/Mastodon/Scene/Search/SearchViewController.swift index b98a34b9..ee6b9190 100644 --- a/Mastodon/Scene/Search/SearchViewController.swift +++ b/Mastodon/Scene/Search/SearchViewController.swift @@ -77,7 +77,7 @@ final class SearchViewController: UIViewController, NeedsDependency { // searching let searchingTableView: UITableView = { let tableView = UITableView() - tableView.backgroundColor = Asset.Colors.Background.systemGroupedBackground.color + tableView.backgroundColor = Asset.Colors.Background.searchResult.color tableView.rowHeight = UITableView.automaticDimension tableView.separatorStyle = .singleLine tableView.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) diff --git a/Mastodon/Scene/Search/SearchViewModel.swift b/Mastodon/Scene/Search/SearchViewModel.swift index 46255fde..2bd5b14d 100644 --- a/Mastodon/Scene/Search/SearchViewModel.swift +++ b/Mastodon/Scene/Search/SearchViewModel.swift @@ -106,27 +106,27 @@ final class SearchViewModel: NSObject { isSearching } .sink { [weak self] _, text, scope in + guard text.isEmpty else { return } guard let self = self else { return } guard let searchHistories = self.fetchSearchHistory() else { return } guard let dataSource = self.searchResultDiffableDataSource else { return } var snapshot = NSDiffableDataSourceSnapshot() - if text.isEmpty { - snapshot.appendSections([.mixed]) - - searchHistories.forEach { searchHistory in - let containsAccount = scope == Mastodon.API.Search.SearchType.accounts || scope == Mastodon.API.Search.SearchType.default - let containsHashTag = scope == Mastodon.API.Search.SearchType.hashtags || scope == Mastodon.API.Search.SearchType.default - if let mastodonUser = searchHistory.account, containsAccount { - let item = SearchResultItem.accountObjectID(accountObjectID: mastodonUser.objectID) - snapshot.appendItems([item], toSection: .mixed) - } - if let tag = searchHistory.hashtag, containsHashTag { - let item = SearchResultItem.hashtagObjectID(hashtagObjectID: tag.objectID) - snapshot.appendItems([item], toSection: .mixed) - } + snapshot.appendSections([.mixed]) + + searchHistories.forEach { searchHistory in + let containsAccount = scope == Mastodon.API.Search.SearchType.accounts || scope == Mastodon.API.Search.SearchType.default + let containsHashTag = scope == Mastodon.API.Search.SearchType.hashtags || scope == Mastodon.API.Search.SearchType.default + if let mastodonUser = searchHistory.account, containsAccount { + let item = SearchResultItem.accountObjectID(accountObjectID: mastodonUser.objectID) + snapshot.appendItems([item], toSection: .mixed) + } + if let tag = searchHistory.hashtag, containsHashTag { + let item = SearchResultItem.hashtagObjectID(hashtagObjectID: tag.objectID) + snapshot.appendItems([item], toSection: .mixed) } } dataSource.apply(snapshot, animatingDifferences: false, completion: nil) + } .store(in: &disposeBag)