From f0f06ac21b52609b02f70c14d69914890fd48753 Mon Sep 17 00:00:00 2001 From: David Sinclair Date: Tue, 30 Aug 2022 19:00:35 -0700 Subject: [PATCH] #1720 (Grid view) - More work in progress. --- .../ios/Classes/DetailViewController.swift | 9 ++- .../Classes/FeedDetailObjCViewController.m | 3 + .../Classes/GridDetailViewController.swift | 62 ++++++++++++------- clients/ios/Classes/StoriesCollection.h | 1 - clients/ios/Other Sources/BridgingHeader.h | 3 + 5 files changed, 53 insertions(+), 25 deletions(-) diff --git a/clients/ios/Classes/DetailViewController.swift b/clients/ios/Classes/DetailViewController.swift index efe30cf4a..6fd0558e4 100644 --- a/clients/ios/Classes/DetailViewController.swift +++ b/clients/ios/Classes/DetailViewController.swift @@ -250,6 +250,13 @@ class DetailViewController: BaseViewController { tidyNavigationController() } + /// Reloads the grid view, if it is displayed. + @objc func reloadGrid() { + if layout == .grid { + gridDetailViewController?.reload() + } + } + /// Adjusts the container when autoscrolling. Only applies to iPhone. @objc func adjustForAutoscroll() { adjustTopConstraint() @@ -271,7 +278,7 @@ class DetailViewController: BaseViewController { override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { super.viewWillTransition(to: size, with: coordinator) - if layout != .left { + if [.top, .bottom].contains(layout) { coordinator.animate { context in self.dividerViewBottomConstraint.constant = self.dividerPosition } diff --git a/clients/ios/Classes/FeedDetailObjCViewController.m b/clients/ios/Classes/FeedDetailObjCViewController.m index 9a732ad1d..84199636e 100644 --- a/clients/ios/Classes/FeedDetailObjCViewController.m +++ b/clients/ios/Classes/FeedDetailObjCViewController.m @@ -658,6 +658,7 @@ typedef NS_ENUM(NSUInteger, MarkReadShowMenu) [self.notifier hideIn:0]; [self beginOfflineTimer]; [appDelegate.cacheImagesOperationQueue cancelAllOperations]; + [appDelegate.detailViewController reloadGrid]; } - (void)reloadStories { @@ -1340,6 +1341,8 @@ typedef NS_ENUM(NSUInteger, MarkReadShowMenu) [self testForTryFeed]; } + [appDelegate.detailViewController reloadGrid]; + dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0ul); dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), queue, ^(void) { diff --git a/clients/ios/Classes/GridDetailViewController.swift b/clients/ios/Classes/GridDetailViewController.swift index f15ef4a9b..00b55ccd5 100644 --- a/clients/ios/Classes/GridDetailViewController.swift +++ b/clients/ios/Classes/GridDetailViewController.swift @@ -10,14 +10,22 @@ import UIKit /// A view controller to manage the Grid layout. class GridDetailViewController: UIViewController { + /// Returns the shared app delegate. + var appDelegate: NewsBlurAppDelegate { + return NewsBlurAppDelegate.shared() + } + @IBOutlet var collectionView: UICollectionView! enum SectionLayoutKind: Int, CaseIterable { - /// Feed cell kind. - case feed + /// Feed cells before the story. + case feedBeforeStory - /// Story cell kind. - case story + /// The selected story. + case selectedStory + + /// Feed cells after the story. + case feedAfterStory } var feedColumns: Int { @@ -36,6 +44,10 @@ class GridDetailViewController: UIViewController { collectionView.collectionViewLayout = createLayout() configureDataSource() } + + @objc func reload() { + configureDataSource() + } } extension GridDetailViewController { @@ -47,22 +59,23 @@ extension GridDetailViewController { return nil } - let columns = sectionLayoutKind == .feed ? self.feedColumns : 1 + let isStory = sectionLayoutKind == .selectedStory + let columns = isStory ? 1 : self.feedColumns let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalHeight(1.0)) let item = NSCollectionLayoutItem(layoutSize: itemSize) - item.contentInsets = NSDirectionalEdgeInsets(top: 2, leading: 2, bottom: 2, trailing: 2) + item.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10) - let groupHeight = columns == 1 ? - NSCollectionLayoutDimension.absolute(44) : - NSCollectionLayoutDimension.fractionalWidth(0.2) + let groupHeight = isStory ? + NSCollectionLayoutDimension.absolute(1000) : + NSCollectionLayoutDimension.fractionalWidth(0.4) let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: groupHeight) let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitem: item, count: columns) let section = NSCollectionLayoutSection(group: group) - section.contentInsets = NSDirectionalEdgeInsets(top: 20, leading: 20, bottom: 20, trailing: 20) + section.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 0, trailing: 10) return section } @@ -74,32 +87,35 @@ extension GridDetailViewController { extension GridDetailViewController { func configureDataSource() { let feedCellRegistration = UICollectionView.CellRegistration { (cell, indexPath, identifier) in + cell.contentView.backgroundColor = UIColor.red + cell.contentView.layer.borderColor = UIColor.black.cgColor + cell.contentView.layer.borderWidth = 1 +// cell.contentView.layer.cornerRadius = SectionLayoutKind(rawValue: indexPath.section)! == .feed ? 8 : 0 //TODO: 🚧 } let storyCellRegistration = UICollectionView.CellRegistration { (cell, indexPath, identifier) in //TODO: 🚧 - cell.contentView.backgroundColor = UIColor.red - cell.contentView.layer.borderColor = UIColor.black.cgColor - cell.contentView.layer.borderWidth = 1 - cell.contentView.layer.cornerRadius = SectionLayoutKind(rawValue: indexPath.section)! == .feed ? 8 : 0 + cell.contentView.backgroundColor = UIColor.blue } dataSource = UICollectionViewDiffableDataSource(collectionView: collectionView) { (collectionView: UICollectionView, indexPath: IndexPath, identifier: Int) -> UICollectionViewCell? in - return SectionLayoutKind(rawValue: indexPath.section)! == .story ? - collectionView.dequeueConfiguredReusableCell(using: feedCellRegistration, for: indexPath, item: identifier) : - collectionView.dequeueConfiguredReusableCell(using: storyCellRegistration, for: indexPath, item: identifier) + return SectionLayoutKind(rawValue: indexPath.section)! == .selectedStory ? + collectionView.dequeueConfiguredReusableCell(using: storyCellRegistration, for: indexPath, item: identifier) : collectionView.dequeueConfiguredReusableCell(using: feedCellRegistration, for: indexPath, item: identifier) + } - let itemsPerSection = 10 var snapshot = NSDiffableDataSourceSnapshot() - SectionLayoutKind.allCases.forEach { - snapshot.appendSections([$0]) - let itemOffset = $0.rawValue * itemsPerSection - let itemUpperbound = itemOffset + itemsPerSection - snapshot.appendItems(Array(itemOffset.. +#import "NewsBlurAppDelegate.h" #import "ThemeManager.h" +#import "StoriesCollection.h" +#import "BaseViewController.h" #import "FeedsObjCViewController.h" #import "FeedDetailObjCViewController.h" #import "StoryPagesObjCViewController.h"