diff --git a/Modules/RSCore/Sources/RSCore/UIKit/UICollectionView+RSCore.swift b/Modules/RSCore/Sources/RSCore/UIKit/UICollectionView+RSCore.swift index fd71a9829..ef25e5968 100644 --- a/Modules/RSCore/Sources/RSCore/UIKit/UICollectionView+RSCore.swift +++ b/Modules/RSCore/Sources/RSCore/UIKit/UICollectionView+RSCore.swift @@ -22,7 +22,7 @@ extension UICollectionView { return } - selectItem(at: indexPath, animated: animations.contains(.select), scrollPosition: []) + selectItem(at: indexPath, animated: true, scrollPosition: []) if !indexPathsForVisibleItems.contains(indexPath) { scrollToItem(at: indexPath, at: .centeredVertically, animated: true) diff --git a/iOS/Base.lproj/Main.storyboard b/iOS/Base.lproj/Main.storyboard index 29398c0ae..c2e788ea7 100644 --- a/iOS/Base.lproj/Main.storyboard +++ b/iOS/Base.lproj/Main.storyboard @@ -469,12 +469,12 @@ - - + + - + @@ -482,81 +482,55 @@ - + - + - - - - + + - - - - - + + - - - - - - - - - - - - - - - - - - - - - + @@ -567,81 +541,55 @@ - + - + - - - - + + - - - - - + + - - - - - - - - - - - - - - - - - - - - - + @@ -652,71 +600,62 @@ - + - - + + - + - - - - - + + - - + + - - - - - - - - - - - - - - + + + + + + + + - + @@ -726,71 +665,65 @@ - + - - + + - + - - - - - + + - - + + - - - - - - - - - - - - - - + + + + + + + + + + + - + diff --git a/iOS/MainTimeline/Cells/MainTimelineCollectionViewCell.swift b/iOS/MainTimeline/Cells/MainTimelineCollectionViewCell.swift index 579504e61..62ca21fd3 100644 --- a/iOS/MainTimeline/Cells/MainTimelineCollectionViewCell.swift +++ b/iOS/MainTimeline/Cells/MainTimelineCollectionViewCell.swift @@ -197,7 +197,9 @@ class MainTimelineCollectionViewCell: UICollectionViewCell { } func titleTextColor(for state: UICellConfigurationState) -> UIColor { - if state.isSelected { + if state.isSwiped { + return .label + } else if state.isSelected { return .white } else { return .label @@ -232,10 +234,6 @@ class MainTimelineCollectionViewCell: UICollectionViewCell { var backgroundConfig = UIBackgroundConfiguration.listCell().updated(for: state) backgroundConfig.cornerRadius = 20 - if traitCollection.userInterfaceIdiom == .pad { - backgroundConfig.edgesAddingLayoutMarginsToBackgroundInsets = [.leading, .trailing] - backgroundConfig.backgroundInsets = NSDirectionalEdgeInsets(top: 0, leading: !isPreview ? -4 : -12, bottom: 0, trailing: !isPreview ? -4 : -12) - } if state.isSwiped { backgroundConfig.backgroundColor = .secondarySystemFill diff --git a/iOS/MainTimeline/MainTimelineCollectionViewController.swift b/iOS/MainTimeline/MainTimelineCollectionViewController.swift index b90ee42c1..46950a175 100644 --- a/iOS/MainTimeline/MainTimelineCollectionViewController.swift +++ b/iOS/MainTimeline/MainTimelineCollectionViewController.swift @@ -189,7 +189,8 @@ final class MainTimelineCollectionViewController: UICollectionViewController, Un navigationItem.largeTitleDisplayMode = .never navigationItem.titleView = navigationBarTitleLabel navigationItem.subtitleView = navigationBarSubtitleTitleLabel - + + } override func viewWillAppear(_ animated: Bool) { @@ -268,9 +269,7 @@ final class MainTimelineCollectionViewController: UICollectionViewController, Un Self.logger.debug("MainTimelineViewController: updateArticleSelection") if let article = currentArticle, let indexPath = dataSource.indexPath(for: article) { - if collectionView.indexPathsForSelectedItems?.first != indexPath { - collectionView.selectItemAndScrollIfNotVisible(at: indexPath, animations: animations) - } + collectionView.selectItemAndScrollIfNotVisible(at: indexPath, animations: animations) } else { collectionView.selectItem(at: nil, animated: animations.contains(.select), scrollPosition: .centeredVertically) } @@ -432,6 +431,91 @@ final class MainTimelineCollectionViewController: UICollectionViewController, Un // MARK: UICollectionViewDelegate + override func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemsAt indexPaths: [IndexPath], point: CGPoint) -> UIContextMenuConfiguration? { + guard let firstIndex = indexPaths.first, let article = dataSource.itemIdentifier(for: firstIndex) else { return nil } + + return UIContextMenuConfiguration(identifier: firstIndex.row as NSCopying, previewProvider: nil, actionProvider: { [weak self] _ in + + guard let self = self else { return nil } + + var menuElements = [UIMenuElement]() + + var markActions = [UIAction]() + if let action = self.toggleArticleReadStatusAction(article) { + markActions.append(action) + } + markActions.append(self.toggleArticleStarStatusAction(article)) + if let action = self.markAboveAsReadAction(article, indexPath: firstIndex) { + markActions.append(action) + } + if let action = self.markBelowAsReadAction(article, indexPath: firstIndex) { + markActions.append(action) + } + menuElements.append(UIMenu(title: "", options: .displayInline, children: markActions)) + + var secondaryActions = [UIAction]() + if let action = self.discloseFeedAction(article) { + secondaryActions.append(action) + } + if let action = self.markAllInFeedAsReadAction(article, indexPath: firstIndex) { + secondaryActions.append(action) + } + if !secondaryActions.isEmpty { + menuElements.append(UIMenu(title: "", options: .displayInline, children: secondaryActions)) + } + + var copyActions = [UIAction]() + if let action = self.copyArticleURLAction(article) { + copyActions.append(action) + } + if let action = self.copyExternalURLAction(article) { + copyActions.append(action) + } + if !copyActions.isEmpty { + menuElements.append(UIMenu(title: "", options: .displayInline, children: copyActions)) + } + + if let action = self.openInBrowserAction(article) { + menuElements.append(UIMenu(title: "", options: .displayInline, children: [action])) + } + + if let action = self.shareAction(article, indexPath: firstIndex) { + menuElements.append(UIMenu(title: "", options: .displayInline, children: [action])) + } + + return UIMenu(title: "", children: menuElements) + + }) + } + + override func collectionView(_ collectionView: UICollectionView, contextMenuConfiguration configuration: UIContextMenuConfiguration, highlightPreviewForItemAt indexPath: IndexPath) -> UITargetedPreview? { + guard let row = configuration.identifier as? Int, + let cell = collectionView.cellForItem(at: IndexPath(row: row, section: 0)) else { + return nil + } + + let previewView = cell.contentView + let parameters = UIPreviewParameters() + parameters.backgroundColor = .white + parameters.visiblePath = UIBezierPath(roundedRect: previewView.bounds, + cornerRadius: 20) + return UITargetedPreview(view: cell, parameters: parameters) + } + + + override func collectionView(_ collectionView: UICollectionView, contextMenuConfiguration configuration: UIContextMenuConfiguration, dismissalPreviewForItemAt indexPath: IndexPath) -> UITargetedPreview? { + guard let row = configuration.identifier as? Int, + let cell = collectionView.cellForItem(at: IndexPath(row: row, section: 0)), let _ = view.window else { + return nil + } + + let previewView = cell.contentView + let parameters = UIPreviewParameters() + parameters.backgroundColor = .white + parameters.visiblePath = UIBezierPath(roundedRect: previewView.bounds, + cornerRadius: 20) + return UITargetedPreview(view: cell, parameters: parameters) + } @@ -512,7 +596,6 @@ private extension MainTimelineCollectionViewController { var config = UICollectionLayoutListConfiguration(appearance: .plain) config.showsSeparators = false config.headerMode = .none - config.trailingSwipeActionsConfigurationProvider = { [unowned self] indexPath in guard let article = dataSource.itemIdentifier(for: indexPath) else { return nil } var actions = [UIContextualAction]() @@ -589,7 +672,7 @@ private extension MainTimelineCollectionViewController { return config } config.leadingSwipeActionsConfigurationProvider = { [unowned self] indexPath in - + Self.logger.debug("Leading swipe provider called for \(indexPath.row)") guard let article = dataSource.itemIdentifier(for: indexPath) else { return nil } guard !article.status.read || article.isAvailableToMarkUnread else { return nil } var actions = [UIContextualAction]() @@ -613,11 +696,13 @@ private extension MainTimelineCollectionViewController { return config } - let layout = UICollectionViewCompositionalLayout.list(using: config) - collectionView.setCollectionViewLayout(layout, animated: false) collectionView.refreshControl = UIRefreshControl() collectionView.refreshControl!.addTarget(self, action: #selector(refreshAccounts(_:)), for: .valueChanged) - collectionView.allowsMultipleSelection = false + collectionView.contentInsetAdjustmentBehavior = .always + + let layout = UICollectionViewCompositionalLayout.list(using: config) + layout.configuration.contentInsetsReference = .safeArea + collectionView.collectionViewLayout = layout } private func makeDataSource() -> UICollectionViewDiffableDataSource { @@ -645,7 +730,6 @@ private extension MainTimelineCollectionViewController { return cell } } - }) return dataSource @@ -733,6 +817,10 @@ private extension MainTimelineCollectionViewController { completion?() } } + + + + } @@ -1195,3 +1283,4 @@ extension MainTimelineCollectionViewController { return action } } +