diff --git a/Mastodon/Protocol/StatusTableViewControllerAspect.swift b/Mastodon/Protocol/StatusTableViewControllerAspect.swift index 5fb36dc6f..dfc1a89eb 100644 --- a/Mastodon/Protocol/StatusTableViewControllerAspect.swift +++ b/Mastodon/Protocol/StatusTableViewControllerAspect.swift @@ -8,20 +8,27 @@ import UIKit import AVKit +/// Status related operations aspect +/// Please check the aspect methods (Option+Click) and add hook to implement features +/// - UI +/// - Media +/// - Data Source protocol StatusTableViewControllerAspect: UIViewController { var tableView: UITableView { get } } // MARK: - UIViewController -// StatusTableViewControllerAspect.aspectViewWillAppear(_:) +// aspectViewWillAppear(_:) extension StatusTableViewControllerAspect { + /// [UI] hook to deselect row in the transitioning for the table view func aspectViewWillAppear(_ animated: Bool) { tableView.deselectRow(with: transitionCoordinator, animated: animated) } } extension StatusTableViewControllerAspect where Self: NeedsDependency { + /// [Media] hook to notify video service func aspectViewDidDisappear(_ animated: Bool) { context.videoPlaybackService.viewDidDisappear(from: self) } @@ -31,6 +38,7 @@ extension StatusTableViewControllerAspect where Self: NeedsDependency { // aspectTableView(_:estimatedHeightForRowAt:) extension StatusTableViewControllerAspect where Self: LoadMoreConfigurableTableViewContainer { + /// [Data Source] hook to notify table view bottom loader func aspectScrollViewDidScroll(_ scrollView: UIScrollView) { handleScrollViewDidScroll(scrollView) } @@ -38,6 +46,7 @@ extension StatusTableViewControllerAspect where Self: LoadMoreConfigurableTableV // aspectTableView(_:estimatedHeightForRowAt:) extension StatusTableViewControllerAspect where Self: TableViewCellHeightCacheableContainer { + /// [UI] hook to estimate table view cell height from cache func aspectTableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { handleTableView(tableView, estimatedHeightForRowAt: indexPath) } @@ -45,21 +54,25 @@ extension StatusTableViewControllerAspect where Self: TableViewCellHeightCacheab // StatusTableViewControllerAspect.aspectTableView(_:didEndDisplaying:forRowAt:) extension StatusTableViewControllerAspect where Self: StatusTableViewCellDelegate & StatusProvider { + /// [Media] hook to notify video service func aspectTableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) { handleTableView(tableView, didEndDisplaying: cell, forRowAt: indexPath) } } extension StatusTableViewControllerAspect where Self: TableViewCellHeightCacheableContainer & StatusProvider { + /// [UI] hook to cache table view cell height func aspectTableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) { - handleTableView(tableView, didEndDisplaying: cell, forRowAt: indexPath) + cacheTableView(tableView, didEndDisplaying: cell, forRowAt: indexPath) } } extension StatusTableViewControllerAspect where Self: StatusTableViewCellDelegate & TableViewCellHeightCacheableContainer & StatusProvider { + /// [Media] hook to notify video service + /// [UI] hook to cache table view cell height func aspectTableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) { - (self as StatusTableViewCellDelegate & StatusProvider).handleTableView(tableView, didEndDisplaying: cell, forRowAt: indexPath) - (self as TableViewCellHeightCacheableContainer & StatusProvider).handleTableView(tableView, didEndDisplaying: cell, forRowAt: indexPath) + handleTableView(tableView, didEndDisplaying: cell, forRowAt: indexPath) + cacheTableView(tableView, didEndDisplaying: cell, forRowAt: indexPath) } } @@ -67,6 +80,7 @@ extension StatusTableViewControllerAspect where Self: StatusTableViewCellDelegat // aspectPlayerViewController(_:willBeginFullScreenPresentationWithAnimationCoordinator:) extension StatusTableViewControllerAspect where Self: AVPlayerViewControllerDelegate & NeedsDependency { + /// [Media] hook to mark transitioning to video service func aspectPlayerViewController(_ playerViewController: AVPlayerViewController, willBeginFullScreenPresentationWithAnimationCoordinator coordinator: UIViewControllerTransitionCoordinator) { handlePlayerViewController(playerViewController, willBeginFullScreenPresentationWithAnimationCoordinator: coordinator) } @@ -74,6 +88,7 @@ extension StatusTableViewControllerAspect where Self: AVPlayerViewControllerDele // aspectPlayerViewController(_:willEndFullScreenPresentationWithAnimationCoordinator:) extension StatusTableViewControllerAspect where Self: AVPlayerViewControllerDelegate & NeedsDependency { + /// [Media] hook to mark transitioning to video service func aspectPlayerViewController(_ playerViewController: AVPlayerViewController, willEndFullScreenPresentationWithAnimationCoordinator coordinator: UIViewControllerTransitionCoordinator) { handlePlayerViewController(playerViewController, willEndFullScreenPresentationWithAnimationCoordinator: coordinator) } diff --git a/Mastodon/Protocol/TableViewCellHeightCacheableContainer.swift b/Mastodon/Protocol/TableViewCellHeightCacheableContainer.swift index 55071d6d7..ce5e453cd 100644 --- a/Mastodon/Protocol/TableViewCellHeightCacheableContainer.swift +++ b/Mastodon/Protocol/TableViewCellHeightCacheableContainer.swift @@ -13,7 +13,7 @@ protocol TableViewCellHeightCacheableContainer: StatusProvider { extension TableViewCellHeightCacheableContainer { - func handleTableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) { + func cacheTableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) { guard let item = item(for: nil, indexPath: indexPath) else { return } let key = item.hashValue