From ecf622b86672167c84507d8c8861399a66e798bd Mon Sep 17 00:00:00 2001 From: sunxiaojian Date: Thu, 15 Apr 2021 12:35:40 +0800 Subject: [PATCH] fix: statusView layout issue --- ...tagTimelineViewModel+LoadOldestState.swift | 8 +++++--- ...omeTimelineViewModel+LoadOldestState.swift | 8 +++++--- ...otificationViewModel+LoadOldestState.swift | 8 +++++--- .../NotificationViewModel+diffable.swift | 19 ++++++++++--------- .../NotificationStatusTableViewCell.swift | 8 ++++---- .../SearchViewModel+LoadOldestState.swift | 8 +++++--- .../TableViewCell/CommonBottomLoader.swift | 3 --- 7 files changed, 34 insertions(+), 28 deletions(-) diff --git a/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewModel+LoadOldestState.swift b/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewModel+LoadOldestState.swift index e5c78f3d5..137373647 100644 --- a/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewModel+LoadOldestState.swift +++ b/Mastodon/Scene/HashtagTimeline/HashtagTimelineViewModel+LoadOldestState.swift @@ -123,9 +123,11 @@ extension HashtagTimelineViewModel.LoadOldestState { assertionFailure() return } - var snapshot = diffableDataSource.snapshot() - snapshot.deleteItems([.bottomLoader]) - diffableDataSource.apply(snapshot) + DispatchQueue.main.async { + var snapshot = diffableDataSource.snapshot() + snapshot.deleteItems([.bottomLoader]) + diffableDataSource.apply(snapshot) + } } } } diff --git a/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+LoadOldestState.swift b/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+LoadOldestState.swift index aaabd7a8b..a74d03a52 100644 --- a/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+LoadOldestState.swift +++ b/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel+LoadOldestState.swift @@ -103,9 +103,11 @@ extension HomeTimelineViewModel.LoadOldestState { assertionFailure() return } - var snapshot = diffableDataSource.snapshot() - snapshot.deleteItems([.bottomLoader]) - diffableDataSource.apply(snapshot) + DispatchQueue.main.async { + var snapshot = diffableDataSource.snapshot() + snapshot.deleteItems([.bottomLoader]) + diffableDataSource.apply(snapshot) + } } } } diff --git a/Mastodon/Scene/Notification/NotificationViewModel+LoadOldestState.swift b/Mastodon/Scene/Notification/NotificationViewModel+LoadOldestState.swift index 4885d7025..a26dedeeb 100644 --- a/Mastodon/Scene/Notification/NotificationViewModel+LoadOldestState.swift +++ b/Mastodon/Scene/Notification/NotificationViewModel+LoadOldestState.swift @@ -133,9 +133,11 @@ extension NotificationViewModel.LoadOldestState { assertionFailure() return } - var snapshot = diffableDataSource.snapshot() - snapshot.deleteItems([.bottomLoader]) - diffableDataSource.apply(snapshot) + DispatchQueue.main.async { + var snapshot = diffableDataSource.snapshot() + snapshot.deleteItems([.bottomLoader]) + diffableDataSource.apply(snapshot) + } } } } diff --git a/Mastodon/Scene/Notification/NotificationViewModel+diffable.swift b/Mastodon/Scene/Notification/NotificationViewModel+diffable.swift index be516a501..774620f8a 100644 --- a/Mastodon/Scene/Notification/NotificationViewModel+diffable.swift +++ b/Mastodon/Scene/Notification/NotificationViewModel+diffable.swift @@ -46,7 +46,6 @@ extension NotificationViewModel: NSFetchedResultsControllerDelegate { guard let navigationBar = contentOffsetAdjustableTimelineViewControllerDelegate?.navigationBar() else { return } guard let diffableDataSource = self.diffableDataSource else { return } - let oldSnapshot = diffableDataSource.snapshot() let predicate = fetchedResultsController.fetchRequest.predicate let parentManagedObjectContext = fetchedResultsController.managedObjectContext @@ -66,16 +65,18 @@ extension NotificationViewModel: NSFetchedResultsControllerDelegate { } }() - var newSnapshot = NSDiffableDataSourceSnapshot() - newSnapshot.appendSections([.main]) - newSnapshot.appendItems(notifications.map { NotificationItem.notification(objectID: $0.objectID) }, toSection: .main) - if !notifications.isEmpty, self.noMoreNotification.value == false { - newSnapshot.appendItems([.bottomLoader], toSection: .main) - } - DispatchQueue.main.async { + let oldSnapshot = diffableDataSource.snapshot() + var newSnapshot = NSDiffableDataSourceSnapshot() + newSnapshot.appendSections([.main]) + newSnapshot.appendItems(notifications.map { NotificationItem.notification(objectID: $0.objectID) }, toSection: .main) + if !notifications.isEmpty, self.noMoreNotification.value == false { + newSnapshot.appendItems([.bottomLoader], toSection: .main) + } guard let difference = self.calculateReloadSnapshotDifference(navigationBar: navigationBar, tableView: tableView, oldSnapshot: oldSnapshot, newSnapshot: newSnapshot) else { - diffableDataSource.apply(newSnapshot) + diffableDataSource.apply(newSnapshot, animatingDifferences: false) { + tableView.reloadData() + } self.isFetchingLatestNotification.value = false return } diff --git a/Mastodon/Scene/Notification/TableViewCell/NotificationStatusTableViewCell.swift b/Mastodon/Scene/Notification/TableViewCell/NotificationStatusTableViewCell.swift index 0f7a8fbdc..6bea35ead 100644 --- a/Mastodon/Scene/Notification/TableViewCell/NotificationStatusTableViewCell.swift +++ b/Mastodon/Scene/Notification/TableViewCell/NotificationStatusTableViewCell.swift @@ -58,7 +58,7 @@ final class NotificationStatusTableViewCell: UITableViewCell { return label }() - let statusContainer: UIView = { + let statusBorder: UIView = { let view = UIView() view.backgroundColor = .clear view.layer.cornerRadius = 6 @@ -147,8 +147,8 @@ extension NotificationStatusTableViewCell { statusView.avatarView.removeFromSuperview() statusView.usernameLabel.removeFromSuperview() - container.addSubview(statusContainer) - statusContainer.pin(top: 40, left: 63, bottom: 14, right: 14) + container.addSubview(statusBorder) + statusBorder.pin(top: 40, left: 63, bottom: 14, right: 14) container.addSubview(statusView) statusView.pin(top: NotificationStatusTableViewCell.statusPadding.top, left: NotificationStatusTableViewCell.statusPadding.left, bottom: NotificationStatusTableViewCell.statusPadding.bottom, right: NotificationStatusTableViewCell.statusPadding.right) @@ -156,7 +156,7 @@ extension NotificationStatusTableViewCell { override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { super.traitCollectionDidChange(previousTraitCollection) - statusContainer.layer.borderColor = Asset.Colors.Border.notification.color.cgColor + statusBorder.layer.borderColor = Asset.Colors.Border.notification.color.cgColor actionImageBackground.layer.borderColor = Asset.Colors.Background.pure.color.cgColor } } diff --git a/Mastodon/Scene/Search/SearchViewModel+LoadOldestState.swift b/Mastodon/Scene/Search/SearchViewModel+LoadOldestState.swift index c76ab202c..b486df774 100644 --- a/Mastodon/Scene/Search/SearchViewModel+LoadOldestState.swift +++ b/Mastodon/Scene/Search/SearchViewModel+LoadOldestState.swift @@ -136,9 +136,11 @@ extension SearchViewModel.LoadOldestState { assertionFailure() return } - var snapshot = diffableDataSource.snapshot() - snapshot.deleteItems([.bottomLoader]) - diffableDataSource.apply(snapshot) + DispatchQueue.main.async { + var snapshot = diffableDataSource.snapshot() + snapshot.deleteItems([.bottomLoader]) + diffableDataSource.apply(snapshot) + } } } } diff --git a/Mastodon/Scene/Search/TableViewCell/CommonBottomLoader.swift b/Mastodon/Scene/Search/TableViewCell/CommonBottomLoader.swift index bb2ae9ce0..2d529972e 100644 --- a/Mastodon/Scene/Search/TableViewCell/CommonBottomLoader.swift +++ b/Mastodon/Scene/Search/TableViewCell/CommonBottomLoader.swift @@ -43,8 +43,5 @@ final class CommonBottomLoader: UITableViewCell { backgroundColor = Asset.Colors.Background.systemGroupedBackground.color contentView.addSubview(activityIndicatorView) activityIndicatorView.constrainToCenter() - NSLayoutConstraint.activate([ - contentView.heightAnchor.constraint(equalToConstant: 44) - ]) } }