From 29653ca6123c69733e4d2ebf8ea3c5ea20becc4b Mon Sep 17 00:00:00 2001 From: CMK Date: Sat, 6 Mar 2021 13:29:45 +0800 Subject: [PATCH] feat: set corner radius for the last cell layer --- Mastodon.xcodeproj/project.pbxproj | 4 ++++ .../xcschemes/xcschememanagement.plist | 4 ++-- Mastodon/Diffiable/Section/PickServerItem.swift | 4 +++- Mastodon/Diffiable/Section/PickServerSection.swift | 11 +++++++++++ .../PickServer/MastodonPickServerAppearance.swift | 12 ++++++++++++ .../MastodonPickServerViewController.swift | 10 +++++----- .../PickServer/MastodonPickServerViewModel.swift | 6 +++++- .../TableViewCell/PickServerSearchCell.swift | 2 +- .../PickServer/View/PickServerEmptyStateView.swift | 6 ++++++ 9 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 Mastodon/Scene/Onboarding/PickServer/MastodonPickServerAppearance.swift diff --git a/Mastodon.xcodeproj/project.pbxproj b/Mastodon.xcodeproj/project.pbxproj index ecec2916..115a32ed 100644 --- a/Mastodon.xcodeproj/project.pbxproj +++ b/Mastodon.xcodeproj/project.pbxproj @@ -170,6 +170,7 @@ DB9D6C2425E502C60051B173 /* MosaicImageViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB9D6C2225E502C60051B173 /* MosaicImageViewModel.swift */; }; DB9D6C2E25E504AC0051B173 /* Attachment.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB9D6C2D25E504AC0051B173 /* Attachment.swift */; }; DB9D6C3825E508BE0051B173 /* Attachment.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB9D6C3725E508BE0051B173 /* Attachment.swift */; }; + DBBE1B4525F3474B0081417A /* MastodonPickServerAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBBE1B4425F3474B0081417A /* MastodonPickServerAppearance.swift */; }; DBD9149025DF6D8D00903DFD /* APIService+Onboarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBD9148F25DF6D8D00903DFD /* APIService+Onboarding.swift */; }; DBE0821525CD382600FD6BBD /* MastodonRegisterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBE0821425CD382600FD6BBD /* MastodonRegisterViewController.swift */; }; DBE0822425CD3F1E00FD6BBD /* MastodonRegisterViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBE0822325CD3F1E00FD6BBD /* MastodonRegisterViewModel.swift */; }; @@ -398,6 +399,7 @@ DB9D6C2225E502C60051B173 /* MosaicImageViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MosaicImageViewModel.swift; sourceTree = ""; }; DB9D6C2D25E504AC0051B173 /* Attachment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Attachment.swift; sourceTree = ""; }; DB9D6C3725E508BE0051B173 /* Attachment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Attachment.swift; sourceTree = ""; }; + DBBE1B4425F3474B0081417A /* MastodonPickServerAppearance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonPickServerAppearance.swift; sourceTree = ""; }; DBD9148F25DF6D8D00903DFD /* APIService+Onboarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "APIService+Onboarding.swift"; sourceTree = ""; }; DBE0821425CD382600FD6BBD /* MastodonRegisterViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonRegisterViewController.swift; sourceTree = ""; }; DBE0822325CD3F1E00FD6BBD /* MastodonRegisterViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonRegisterViewModel.swift; sourceTree = ""; }; @@ -473,6 +475,7 @@ 0FB3D30D25E525C000AAD544 /* View */, 0FB3D31825E525DE00AAD544 /* CollectionViewCell */, 0FB3D2FC25E4CB4B00AAD544 /* TableViewCell */, + DBBE1B4425F3474B0081417A /* MastodonPickServerAppearance.swift */, 0FAA102625E1126A0017CCDE /* MastodonPickServerViewController.swift */, 0FB3D2F625E4C24D00AAD544 /* MastodonPickServerViewModel.swift */, DB1FD44F25F26FA1004CFCFC /* MastodonPickServerViewModel+Diffable.swift */, @@ -1563,6 +1566,7 @@ DB2B3AE925E38850007045F9 /* UIViewPreview.swift in Sources */, DB427DD625BAA00100D1B89D /* AppDelegate.swift in Sources */, DB9D6C0E25E4F9780051B173 /* MosaicImageViewContainer.swift in Sources */, + DBBE1B4525F3474B0081417A /* MastodonPickServerAppearance.swift in Sources */, DB98338725C945ED00AD9700 /* Strings.swift in Sources */, DB1FD46025F278AF004CFCFC /* CategoryPickerSection.swift in Sources */, DB45FAB625CA5485005A8AC7 /* UIAlertController.swift in Sources */, diff --git a/Mastodon.xcodeproj/xcuserdata/mainasuk.xcuserdatad/xcschemes/xcschememanagement.plist b/Mastodon.xcodeproj/xcuserdata/mainasuk.xcuserdatad/xcschemes/xcschememanagement.plist index 60ccd3d8..d9c64a5e 100644 --- a/Mastodon.xcodeproj/xcuserdata/mainasuk.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/Mastodon.xcodeproj/xcuserdata/mainasuk.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,7 +7,7 @@ CoreDataStack.xcscheme_^#shared#^_ orderHint - 7 + 8 Mastodon - RTL.xcscheme_^#shared#^_ @@ -22,7 +22,7 @@ Mastodon.xcscheme_^#shared#^_ orderHint - 8 + 7 SuppressBuildableAutocreation diff --git a/Mastodon/Diffiable/Section/PickServerItem.swift b/Mastodon/Diffiable/Section/PickServerItem.swift index 09ca72c3..13acefea 100644 --- a/Mastodon/Diffiable/Section/PickServerItem.swift +++ b/Mastodon/Diffiable/Section/PickServerItem.swift @@ -18,9 +18,11 @@ enum PickServerItem { extension PickServerItem { final class ServerItemAttribute: Equatable, Hashable { + var isLast: Bool var isExpand: Bool - init(isExpand: Bool) { + init(isLast: Bool, isExpand: Bool) { + self.isLast = isLast self.isExpand = isExpand } diff --git a/Mastodon/Diffiable/Section/PickServerSection.swift b/Mastodon/Diffiable/Section/PickServerSection.swift index 813ef9b2..3ae91798 100644 --- a/Mastodon/Diffiable/Section/PickServerSection.swift +++ b/Mastodon/Diffiable/Section/PickServerSection.swift @@ -84,6 +84,17 @@ extension PickServerSection { cell.updateExpandMode(mode: attribute.isExpand ? .expand : .collapse) + if attribute.isLast { + cell.containerView.layer.maskedCorners = [ + .layerMinXMaxYCorner, + .layerMaxXMaxYCorner + ] + cell.containerView.layer.cornerCurve = .continuous + cell.containerView.layer.cornerRadius = MastodonPickServerAppearance.tableViewCornerRadius + } else { + cell.containerView.layer.cornerRadius = 0 + } + cell.expandMode .receive(on: DispatchQueue.main) .sink { mode in diff --git a/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerAppearance.swift b/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerAppearance.swift new file mode 100644 index 00000000..c5bc56c0 --- /dev/null +++ b/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerAppearance.swift @@ -0,0 +1,12 @@ +// +// MastodonPickServerAppearance.swift +// Mastodon +// +// Created by Cirno MainasuK on 2021/3/6. +// + +import UIKit + +enum MastodonPickServerAppearance { + static let tableViewCornerRadius: CGFloat = 10 +} diff --git a/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerViewController.swift b/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerViewController.swift index d803e005..6af592f8 100644 --- a/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerViewController.swift +++ b/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerViewController.swift @@ -76,7 +76,7 @@ extension MastodonPickServerViewController { emptyStateView.topAnchor.constraint(equalTo: view.topAnchor), emptyStateView.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor), emptyStateView.trailingAnchor.constraint(equalTo: view.readableContentGuide.trailingAnchor), - nextStepButton.topAnchor.constraint(equalTo: emptyStateView.bottomAnchor, constant: 7) + nextStepButton.topAnchor.constraint(equalTo: emptyStateView.bottomAnchor, constant: 21), ]) // fix AutoLayout warning when observe before view appear @@ -107,7 +107,7 @@ extension MastodonPickServerViewController { tableView.topAnchor.constraint(equalTo: view.topAnchor), tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor), tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor), - nextStepButton.topAnchor.constraint(equalTo: tableView.bottomAnchor, constant: 7) + nextStepButton.topAnchor.constraint(equalTo: tableView.bottomAnchor, constant: 7), ]) switch viewModel.mode { @@ -181,16 +181,16 @@ extension MastodonPickServerViewController { guard let self = self else { return } switch state { case .none: - self.emptyStateView.networkIndicatorImageView.isHidden = true - self.emptyStateView.activityIndicatorView.stopAnimating() - self.emptyStateView.infoLabel.isHidden = true + self.emptyStateView.isHidden = true case .loading: + self.emptyStateView.isHidden = false self.emptyStateView.networkIndicatorImageView.isHidden = true self.emptyStateView.activityIndicatorView.startAnimating() self.emptyStateView.infoLabel.isHidden = false self.emptyStateView.infoLabel.text = L10n.Scene.ServerPicker.EmptyState.findingServers self.emptyStateView.infoLabel.textAlignment = self.traitCollection.layoutDirection == .rightToLeft ? .right : .left case .badNetwork: + self.emptyStateView.isHidden = false self.emptyStateView.networkIndicatorImageView.isHidden = false self.emptyStateView.activityIndicatorView.stopAnimating() self.emptyStateView.infoLabel.isHidden = false diff --git a/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerViewModel.swift b/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerViewModel.swift index 8953e2ed..e86d1c59 100644 --- a/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerViewModel.swift +++ b/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerViewModel.swift @@ -100,10 +100,14 @@ class MastodonPickServerViewModel: NSObject { // TODO: handle filter var serverItems: [PickServerItem] = [] for server in indexedServers { - let attribute = oldSnapshotServerItemAttributeDict[server.domain] ?? PickServerItem.ServerItemAttribute(isExpand: false) + let attribute = oldSnapshotServerItemAttributeDict[server.domain] ?? PickServerItem.ServerItemAttribute(isLast: false, isExpand: false) + attribute.isLast = false let item = PickServerItem.server(server: server, attribute: attribute) serverItems.append(item) } + if case let .server(_, attribute) = serverItems.last { + attribute.isLast = true + } snapshot.appendItems(serverItems, toSection: .servers) diffableDataSource.apply(snapshot) diff --git a/Mastodon/Scene/Onboarding/PickServer/TableViewCell/PickServerSearchCell.swift b/Mastodon/Scene/Onboarding/PickServer/TableViewCell/PickServerSearchCell.swift index 510df3a0..23c93a7d 100644 --- a/Mastodon/Scene/Onboarding/PickServer/TableViewCell/PickServerSearchCell.swift +++ b/Mastodon/Scene/Onboarding/PickServer/TableViewCell/PickServerSearchCell.swift @@ -24,7 +24,7 @@ class PickServerSearchCell: UITableViewCell { .layerMaxXMinYCorner ] view.layer.cornerCurve = .continuous - view.layer.cornerRadius = 10 + view.layer.cornerRadius = MastodonPickServerAppearance.tableViewCornerRadius return view }() diff --git a/Mastodon/Scene/Onboarding/PickServer/View/PickServerEmptyStateView.swift b/Mastodon/Scene/Onboarding/PickServer/View/PickServerEmptyStateView.swift index c553b51f..af744fa9 100644 --- a/Mastodon/Scene/Onboarding/PickServer/View/PickServerEmptyStateView.swift +++ b/Mastodon/Scene/Onboarding/PickServer/View/PickServerEmptyStateView.swift @@ -45,6 +45,12 @@ extension PickServerEmptyStateView { private func _init() { backgroundColor = Asset.Colors.Background.secondaryGroupedSystemBackground.color + layer.maskedCorners = [ + .layerMinXMaxYCorner, + .layerMaxXMaxYCorner + ] + layer.cornerCurve = .continuous + layer.cornerRadius = MastodonPickServerAppearance.tableViewCornerRadius let topPaddingView = UIView() topPaddingView.translatesAutoresizingMaskIntoConstraints = false