From a371ccdec6b4109e1339ed75c287cb56d02bff2b Mon Sep 17 00:00:00 2001 From: CMK Date: Thu, 15 Jul 2021 12:01:01 +0800 Subject: [PATCH] chore: add separator line back for search result cell --- Mastodon.xcodeproj/project.pbxproj | 8 +-- .../SearchResultViewController.swift | 10 +++ ....swift => SearchResultTableViewCell.swift} | 65 ++++++++++++++++++- 3 files changed, 78 insertions(+), 5 deletions(-) rename Mastodon/Scene/Search/SearchResult/TableViewCell/{SearchingTableViewCell.swift => SearchResultTableViewCell.swift} (70%) diff --git a/Mastodon.xcodeproj/project.pbxproj b/Mastodon.xcodeproj/project.pbxproj index 6da303ad3..24f935559 100644 --- a/Mastodon.xcodeproj/project.pbxproj +++ b/Mastodon.xcodeproj/project.pbxproj @@ -140,7 +140,7 @@ 2DF75BA725D10E1000694EC8 /* APIService+Favorite.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DF75BA625D10E1000694EC8 /* APIService+Favorite.swift */; }; 2DF75BB925D1474100694EC8 /* ManagedObjectObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DF75BB825D1474100694EC8 /* ManagedObjectObserver.swift */; }; 2DF75BC725D1475D00694EC8 /* ManagedObjectContextObjectsDidChange.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DF75BC625D1475D00694EC8 /* ManagedObjectContextObjectsDidChange.swift */; }; - 2DFAD5372617010500F9EE7C /* SearchingTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DFAD5362617010500F9EE7C /* SearchingTableViewCell.swift */; }; + 2DFAD5372617010500F9EE7C /* SearchResultTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DFAD5362617010500F9EE7C /* SearchResultTableViewCell.swift */; }; 5B24BBDA262DB14800A9381B /* ReportViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B24BBD7262DB14800A9381B /* ReportViewModel.swift */; }; 5B24BBDB262DB14800A9381B /* ReportViewModel+Diffable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B24BBD8262DB14800A9381B /* ReportViewModel+Diffable.swift */; }; 5B24BBE2262DB19100A9381B /* APIService+Report.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B24BBE1262DB19100A9381B /* APIService+Report.swift */; }; @@ -760,7 +760,7 @@ 2DF75BA625D10E1000694EC8 /* APIService+Favorite.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "APIService+Favorite.swift"; sourceTree = ""; }; 2DF75BB825D1474100694EC8 /* ManagedObjectObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ManagedObjectObserver.swift; sourceTree = ""; }; 2DF75BC625D1475D00694EC8 /* ManagedObjectContextObjectsDidChange.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ManagedObjectContextObjectsDidChange.swift; sourceTree = ""; }; - 2DFAD5362617010500F9EE7C /* SearchingTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchingTableViewCell.swift; sourceTree = ""; }; + 2DFAD5362617010500F9EE7C /* SearchResultTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResultTableViewCell.swift; sourceTree = ""; }; 2E1F6A67FDF9771D3E064FDC /* Pods-Mastodon.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Mastodon.debug.xcconfig"; path = "Target Support Files/Pods-Mastodon/Pods-Mastodon.debug.xcconfig"; sourceTree = ""; }; 374AA339A20E0FAC75BCDA6D /* Pods_NotificationService.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NotificationService.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 3B7FD8F28DDA8FBCE5562B78 /* Pods-NotificationService.asdk - debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationService.asdk - debug.xcconfig"; path = "Target Support Files/Pods-NotificationService/Pods-NotificationService.asdk - debug.xcconfig"; sourceTree = ""; }; @@ -1701,7 +1701,7 @@ 2DFAD5212616F8E300F9EE7C /* TableViewCell */ = { isa = PBXGroup; children = ( - 2DFAD5362617010500F9EE7C /* SearchingTableViewCell.swift */, + 2DFAD5362617010500F9EE7C /* SearchResultTableViewCell.swift */, ); path = TableViewCell; sourceTree = ""; @@ -3263,7 +3263,7 @@ DB66729625F9F91600D60309 /* ComposeStatusSection.swift in Sources */, DB482A3F261331E8008AE74C /* UserTimelineViewModel+State.swift in Sources */, 2D38F1F725CD47AC00561493 /* HomeTimelineViewModel+LoadOldestState.swift in Sources */, - 2DFAD5372617010500F9EE7C /* SearchingTableViewCell.swift in Sources */, + 2DFAD5372617010500F9EE7C /* SearchResultTableViewCell.swift in Sources */, DB447681260B3ED600B66B82 /* CustomEmojiPickerSection.swift in Sources */, 5BB04FEF262F0DCB0043BFF6 /* ReportViewModel+Data.swift in Sources */, 5B8E055826319E47006E3C53 /* ReportFooterView.swift in Sources */, diff --git a/Mastodon/Scene/Search/SearchResult/SearchResultViewController.swift b/Mastodon/Scene/Search/SearchResult/SearchResultViewController.swift index 508390b70..cadb7d2d7 100644 --- a/Mastodon/Scene/Search/SearchResult/SearchResultViewController.swift +++ b/Mastodon/Scene/Search/SearchResult/SearchResultViewController.swift @@ -24,6 +24,7 @@ final class SearchResultViewController: UIViewController, NeedsDependency, Media tableView.register(SearchResultTableViewCell.self, forCellReuseIdentifier: String(describing: SearchResultTableViewCell.self)) tableView.register(StatusTableViewCell.self, forCellReuseIdentifier: String(describing: StatusTableViewCell.self)) tableView.register(TimelineBottomLoaderTableViewCell.self, forCellReuseIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self)) + tableView.separatorStyle = .none return tableView }() @@ -52,6 +53,7 @@ extension SearchResultViewController { tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor), ]) + tableView.delegate = self viewModel.setupDiffableDataSource( tableView: tableView, dependency: self, @@ -138,3 +140,11 @@ extension SearchResultViewController: StatusTableViewCellDelegate { // var loadMoreConfigurableTableView: UITableView { searchingTableView } // var loadMoreConfigurableStateMachine: GKStateMachine { viewModel.loadoldestStateMachine } //} + +// MARK: - StatusTableViewControllerAspect +extension SearchResultViewController: StatusTableViewControllerAspect { } + +// MARK: - UITableViewDelegate +extension SearchResultViewController: UITableViewDelegate { + +} diff --git a/Mastodon/Scene/Search/SearchResult/TableViewCell/SearchingTableViewCell.swift b/Mastodon/Scene/Search/SearchResult/TableViewCell/SearchResultTableViewCell.swift similarity index 70% rename from Mastodon/Scene/Search/SearchResult/TableViewCell/SearchingTableViewCell.swift rename to Mastodon/Scene/Search/SearchResult/TableViewCell/SearchResultTableViewCell.swift index fa1401346..ca563845a 100644 --- a/Mastodon/Scene/Search/SearchResult/TableViewCell/SearchingTableViewCell.swift +++ b/Mastodon/Scene/Search/SearchResult/TableViewCell/SearchResultTableViewCell.swift @@ -1,5 +1,5 @@ // -// SearchingTableViewCell.swift +// SearchResultTableViewCell.swift // Mastodon // // Created by sxiaojian on 2021/4/2. @@ -37,6 +37,14 @@ final class SearchResultTableViewCell: UITableViewCell { label.font = .preferredFont(forTextStyle: .body) return label }() + + let separatorLine = UIView.separatorLine + + var separatorLineToEdgeLeadingLayoutConstraint: NSLayoutConstraint! + var separatorLineToEdgeTrailingLayoutConstraint: NSLayoutConstraint! + + var separatorLineToMarginLeadingLayoutConstraint: NSLayoutConstraint! + var separatorLineToMarginTrailingLayoutConstraint: NSLayoutConstraint! override func prepareForReuse() { super.prepareForReuse() @@ -89,7 +97,62 @@ extension SearchResultTableViewCell { _subTitleLabel.setContentHuggingPriority(.defaultLow - 1, for: .vertical) containerStackView.addArrangedSubview(textStackView) + + separatorLine.translatesAutoresizingMaskIntoConstraints = false + contentView.addSubview(separatorLine) + separatorLineToEdgeLeadingLayoutConstraint = separatorLine.leadingAnchor.constraint(equalTo: contentView.leadingAnchor) + separatorLineToEdgeTrailingLayoutConstraint = separatorLine.trailingAnchor.constraint(equalTo: contentView.trailingAnchor) + separatorLineToMarginLeadingLayoutConstraint = separatorLine.leadingAnchor.constraint(equalTo: contentView.readableContentGuide.leadingAnchor) + separatorLineToMarginTrailingLayoutConstraint = separatorLine.trailingAnchor.constraint(equalTo: contentView.readableContentGuide.trailingAnchor) + NSLayoutConstraint.activate([ + separatorLine.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), + separatorLine.heightAnchor.constraint(equalToConstant: UIView.separatorLineHeight(of: contentView)), + ]) + resetSeparatorLineLayout() } + + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + + resetSeparatorLineLayout() + } + +} + +extension SearchResultTableViewCell { + + private func resetSeparatorLineLayout() { + separatorLineToEdgeLeadingLayoutConstraint.isActive = false + separatorLineToEdgeTrailingLayoutConstraint.isActive = false + separatorLineToMarginLeadingLayoutConstraint.isActive = false + separatorLineToMarginTrailingLayoutConstraint.isActive = false + + if traitCollection.userInterfaceIdiom == .phone { + // to edge + NSLayoutConstraint.activate([ + separatorLineToEdgeLeadingLayoutConstraint, + separatorLineToEdgeTrailingLayoutConstraint, + ]) + } else { + if traitCollection.horizontalSizeClass == .compact { + // to edge + NSLayoutConstraint.activate([ + separatorLineToEdgeLeadingLayoutConstraint, + separatorLineToEdgeTrailingLayoutConstraint, + ]) + } else { + // to margin + NSLayoutConstraint.activate([ + separatorLineToMarginLeadingLayoutConstraint, + separatorLineToMarginTrailingLayoutConstraint, + ]) + } + } + } + +} + +extension SearchResultTableViewCell { func config(with account: Mastodon.Entity.Account) { Nuke.loadImage(