From bcb3c24027ebdca29308151899dc81ec073c0d3b Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 8 Oct 2022 15:31:08 -0400 Subject: [PATCH] Fix context menu presentation animation getting clipped in new status cells --- Tusker/Screens/Timeline/TimelineViewController.swift | 4 ++-- Tusker/Views/Status/StatusCollectionViewCell.swift | 9 +++++++-- Tusker/Views/Status/StatusContentContainer.swift | 5 +---- .../Views/Status/TimelineStatusCollectionViewCell.swift | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index fa453d0b..412632c8 100644 --- a/Tusker/Screens/Timeline/TimelineViewController.swift +++ b/Tusker/Screens/Timeline/TimelineViewController.swift @@ -357,11 +357,11 @@ extension TimelineViewController: MenuActionProvider { } extension TimelineViewController: StatusCollectionViewCellDelegate { - func statusCellNeedsReconfigure(_ cell: StatusCollectionViewCell, animated: Bool) { + func statusCellNeedsReconfigure(_ cell: StatusCollectionViewCell, animated: Bool, completion: (() -> Void)?) { if let indexPath = collectionView.indexPath(for: cell) { var snapshot = dataSource.snapshot() snapshot.reconfigureItems([dataSource.itemIdentifier(for: indexPath)!]) - dataSource.apply(snapshot, animatingDifferences: animated) + dataSource.apply(snapshot, animatingDifferences: animated, completion: completion) } } } diff --git a/Tusker/Views/Status/StatusCollectionViewCell.swift b/Tusker/Views/Status/StatusCollectionViewCell.swift index 99b420cc..107b0101 100644 --- a/Tusker/Views/Status/StatusCollectionViewCell.swift +++ b/Tusker/Views/Status/StatusCollectionViewCell.swift @@ -12,7 +12,7 @@ import Combine @MainActor protocol StatusCollectionViewCellDelegate: AnyObject, TuskerNavigationDelegate, MenuActionProvider { - func statusCellNeedsReconfigure(_ cell: StatusCollectionViewCell, animated: Bool) + func statusCellNeedsReconfigure(_ cell: StatusCollectionViewCell, animated: Bool, completion: (() -> Void)?) } @MainActor @@ -196,8 +196,13 @@ extension StatusCollectionViewCell { extension StatusCollectionViewCell { func toggleCollapse() { statusState.collapsed!.toggle() + // mask so that the content appears to expand with the container during the animation + // but only while the animation is taking place, otherwise the mask interferes with context menu presentation animation + contentContainer.layer.masksToBounds = true // this delegate call causes the collection view to reconfigure this cell, at which point (and inside of the collection view's animation handling) we'll update the contentContainer - delegate?.statusCellNeedsReconfigure(self, animated: true) + delegate?.statusCellNeedsReconfigure(self, animated: true) { + self.contentContainer.layer.masksToBounds = false + } } func toggleFavorite() { diff --git a/Tusker/Views/Status/StatusContentContainer.swift b/Tusker/Views/Status/StatusContentContainer.swift index ffbb7ff2..5abceb53 100644 --- a/Tusker/Views/Status/StatusContentContainer.swift +++ b/Tusker/Views/Status/StatusContentContainer.swift @@ -60,10 +60,7 @@ class StatusContentContainer: UIView { zeroHeightConstraint.priority = .defaultLow setNeedsUpdateConstraints() - - // mask to bounds so that the during the expand/collapse animation, subviews are clipped - layer.masksToBounds = true - + isHiddenObservations = arrangedSubviews.map { $0.observe(\.isHidden) { [unowned self] _, _ in self.setNeedsUpdateConstraints() diff --git a/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift b/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift index d9e232d7..f445feb7 100644 --- a/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift +++ b/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift @@ -474,7 +474,7 @@ class TimelineStatusCollectionViewCell: UICollectionViewListCell, StatusCollecti let oldState = actionsContainer.isHidden if oldState != Preferences.shared.hideActionsInTimeline { updateActionsVisibility() - delegate?.statusCellNeedsReconfigure(self, animated: true) + delegate?.statusCellNeedsReconfigure(self, animated: true, completion: nil) } }