From 53c6bcadebf1af23e94fe429d4666f276dd2b480 Mon Sep 17 00:00:00 2001 From: Chip Snyder Date: Tue, 4 Aug 2020 11:10:57 -0400 Subject: [PATCH 01/23] Create basic category bar cells --- .../GutenbergLayoutCategoryBar.swift | 46 ++++++++++++++++ .../GutenbergLayoutPickerViewController.swift | 14 ++++- ...youtPickerCategoryCollectionViewCell.swift | 18 +++++++ ...LayoutPickerCategoryCollectionViewCell.xib | 54 +++++++++++++++++++ .../LayoutPickerCollectionViewCell.xib | 5 +- .../LayoutPickerStoryboard.storyboard | 8 +-- WordPress/WordPress.xcodeproj/project.pbxproj | 16 +++++- 7 files changed, 150 insertions(+), 11 deletions(-) create mode 100644 WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/GutenbergLayoutCategoryBar.swift create mode 100644 WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/LayoutPickerCategoryCollectionViewCell.swift create mode 100644 WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/LayoutPickerCategoryCollectionViewCell.xib diff --git a/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/GutenbergLayoutCategoryBar.swift b/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/GutenbergLayoutCategoryBar.swift new file mode 100644 index 000000000000..2ff6effd5635 --- /dev/null +++ b/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/GutenbergLayoutCategoryBar.swift @@ -0,0 +1,46 @@ +import UIKit + +protocol CategoryBarDelegate { + func numberOfCategories() -> Int + func category(forIndex: Int) -> GutenbergLayoutDisplayCategory +} + +class GutenbergLayoutCategoryBar: UICollectionView { + var categoryDelegate: CategoryBarDelegate? + + required init?(coder: NSCoder) { + super.init(coder: coder) + register(LayoutPickerCategoryCollectionViewCell.nib, forCellWithReuseIdentifier: LayoutPickerCategoryCollectionViewCell.cellReuseIdentifier) + self.delegate = self + self.dataSource = self + } +} + +extension GutenbergLayoutCategoryBar: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool { + return true + } + + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + } + + func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) { + } +} + +extension GutenbergLayoutCategoryBar: UICollectionViewDelegateFlowLayout { + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { + return CGSize(width: 105.0, height: 44.0) + } +} + +extension GutenbergLayoutCategoryBar: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + return categoryDelegate?.numberOfCategories() ?? 0 + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: LayoutPickerCategoryCollectionViewCell.cellReuseIdentifier, for: indexPath) as! LayoutPickerCategoryCollectionViewCell + return cell + } +} diff --git a/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/GutenbergLayoutPickerViewController.swift b/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/GutenbergLayoutPickerViewController.swift index 64ccc002dd82..bbeec8ea631a 100644 --- a/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/GutenbergLayoutPickerViewController.swift +++ b/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/GutenbergLayoutPickerViewController.swift @@ -22,7 +22,7 @@ class GutenbergLayoutPickerViewController: UIViewController { @IBOutlet weak var titleView: UILabel! @IBOutlet weak var largeTitleView: UILabel! @IBOutlet weak var promptView: UILabel! - @IBOutlet weak var categoryBar: UICollectionView! + @IBOutlet weak var categoryBar: GutenbergLayoutCategoryBar! @IBOutlet weak var tableView: UITableView! @IBOutlet weak var footerView: UIView! @IBOutlet weak var createBlankPageBtn: UIButton! @@ -131,11 +131,13 @@ class GutenbergLayoutPickerViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() tableView.register(LayoutPickerCategoryTableViewCell.nib, forCellReuseIdentifier: LayoutPickerCategoryTableViewCell.cellReuseIdentifier) + categoryBar.categoryDelegate = self setStaticText() closeButton.setImage(UIImage.gridicon(.crossSmall), for: .normal) styleButtons() layoutHeader() layouts = GutenbergPageLayoutFactory.makeDefaultPageLayouts() + categoryBar.reloadData() } override func viewWillAppear(_ animated: Bool) { @@ -355,3 +357,13 @@ extension GutenbergLayoutPickerViewController: LayoutPickerCategoryTableViewCell tableView.scrollToRow(at: cellIndexPath, at: .middle, animated: true) } } + +extension GutenbergLayoutPickerViewController: CategoryBarDelegate { + func numberOfCategories() -> Int { + return displayCategories.count + } + + func category(forIndex index: Int) -> GutenbergLayoutDisplayCategory { + return displayCategories[index] + } +} diff --git a/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/LayoutPickerCategoryCollectionViewCell.swift b/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/LayoutPickerCategoryCollectionViewCell.swift new file mode 100644 index 000000000000..e05571f52226 --- /dev/null +++ b/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/LayoutPickerCategoryCollectionViewCell.swift @@ -0,0 +1,18 @@ +import UIKit + +class LayoutPickerCategoryCollectionViewCell: UICollectionViewCell { + + static var cellReuseIdentifier: String { + return "LayoutPickerCategoryCollectionViewCell" + } + + static var nib: UINib { + return UINib(nibName: "LayoutPickerCategoryCollectionViewCell", bundle: Bundle.main) + } + + override func awakeFromNib() { + super.awakeFromNib() + // Initialization code + } + +} diff --git a/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/LayoutPickerCategoryCollectionViewCell.xib b/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/LayoutPickerCategoryCollectionViewCell.xib new file mode 100644 index 000000000000..fe989a0602e2 --- /dev/null +++ b/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/LayoutPickerCategoryCollectionViewCell.xib @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/LayoutPickerCollectionViewCell.xib b/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/LayoutPickerCollectionViewCell.xib index a0e979be4f88..d19c6ebf1c80 100644 --- a/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/LayoutPickerCollectionViewCell.xib +++ b/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/LayoutPickerCollectionViewCell.xib @@ -38,7 +38,7 @@ -