Compare commits

..

No commits in common. "d83052fd48ae0ffc37b547fcce42f726a1b02a67" and "f862c8bd1ce326aefdecf20fa7c54b6749331dff" have entirely different histories.

6 changed files with 55 additions and 108 deletions

View File

@ -57,28 +57,20 @@ final class BreadcrumbCellItem: UICollectionViewCell {
///Configuring the cell with default setup
private func setUp() {
separator.textColorConfiguration = textColorConfiguration.eraseToAnyColorable()
// contentView.addSubview(stackView)
// stackView.pinToSuperView()
contentView.addSubview(stackView)
stackView.pinToSuperView()
separator.backgroundColor = .clear
}
///Updating the breadCrumbItem and UI based on the selected flag along with the surface
func update(surface: Surface, hideSlash: Bool, breadCrumbItem: BreadcrumbItem) {
contentView.subviews.forEach { $0.removeFromSuperview() }
contentView.addSubview(breadCrumbItem)
breadCrumbItem.pinToSuperView()
// separator.surface = surface
// breadCrumbItem.surface = surface
// separator.removeFromSuperview()
// self.breadCrumbItem?.removeFromSuperview()
//
//// stackView.addArrangedSubview(separator)
// stackView.addArrangedSubview(breadCrumbItem)
//// stackView.setCustomSpacing(VDSLayout.Spacing.space1X.value, after: separator)
//
// separator.textColor = textColorConfiguration.getColor(surface)
// separator.isHidden = hideSlash
separator.surface = surface
breadCrumbItem.surface = surface
stackView.addArrangedSubview(separator)
stackView.addArrangedSubview(breadCrumbItem)
stackView.setCustomSpacing(VDSLayout.Spacing.space1X.value, after: separator)
separator.textColor = textColorConfiguration.getColor(surface)
separator.isHidden = hideSlash
self.breadCrumbItem = breadCrumbItem
layoutIfNeeded()
}

View File

@ -15,7 +15,7 @@ import Combine
/// Breadcrumb contains text with a separator by default, highlights text in bold without a separator if selected.
@objc (VDSBreadcrumbItem)
open class BreadcrumbItem: ButtonBase {
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------
@ -34,38 +34,19 @@ open class BreadcrumbItem: ButtonBase {
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
open var hideSlash: Bool = false { didSet { setNeedsUpdate() } }
/// TextStyle used on the titleLabel.
open override var textStyle: TextStyle { isSelected ? TextStyle.boldBodySmall : TextStyle.bodySmall }
/// UIColor used on the titleLabel text.
open override var textColor: UIColor {
textColorConfiguration.getColor(self)
}
open override var textAttributes: [any LabelAttributeModel]? {
guard hideSlash else { return nil }
}
open override var text: String? {
get { hideSlash ? super.text : "/ \(super.text ?? "")"}
set { super.text = newValue }
}
/// The natural size for the receiving view, considering only properties of the view itself.
/// The natural size for the receiving view, considering only properties of the view itself.
open override var intrinsicContentSize: CGSize {
guard let titleLabel else { return super.intrinsicContentSize }
// Calculate the titleLabel's intrinsic content size
let labelSize = titleLabel.sizeThatFits(CGSize(width: self.frame.width, height: CGFloat.greatestFiniteMagnitude))
// Adjust the size if needed (add any additional padding if your design requires)
let adjustedSize = CGSize(width: labelSize.width + contentEdgeInsets.left + contentEdgeInsets.right,
height: labelSize.height + contentEdgeInsets.top + contentEdgeInsets.bottom)
return adjustedSize
return titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize
}
//--------------------------------------------------
// MARK: - Private Properties
//--------------------------------------------------

View File

@ -15,21 +15,11 @@ import Combine
@objc(VDSBreadcrumbs)
open class Breadcrumbs: View {
struct BreadcrumbsSpacerConfig: ButtonGroupSpaceable {
func getSpacing(for axis: NSLayoutConstraint.Axis, with primary: ButtonBase, neighboring: ButtonBase) -> CGFloat {
VDSLayout.Spacing.space1X.value
}
func getVerticalSpacing(for row: ButtonCollectionViewRow, neighboringRow: ButtonCollectionViewRow?) -> CGFloat {
VDSLayout.Spacing.space1X.value
}
}
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
/// Array of ``BreadcrumbItem`` views for the Breadcrumbs.
open var breadcrumbs: [BreadcrumbItem] = [] { didSet { collectionView.buttons = breadcrumbs } }
open var breadcrumbs: [BreadcrumbItem] = [] { didSet { setNeedsUpdate() } }
/// Array of ``BreadcurmbItemModel`` you are wanting to show.
open var breadcrumbModels: [BreadcrumbItemModel] = [] { didSet { updateBreadcrumbItems() } }
@ -65,23 +55,19 @@ open class Breadcrumbs: View {
$0.scrollDirection = .vertical
}
// ///Collectionview to render Breadcrumb Items
// private lazy var collectionView: SelfSizingCollectionView = {
// let collectionView = SelfSizingCollectionView(frame: .zero, collectionViewLayout: layout)
// collectionView.isScrollEnabled = false
// collectionView.translatesAutoresizingMaskIntoConstraints = false
// collectionView.delegate = self
// collectionView.dataSource = self
// collectionView.showsHorizontalScrollIndicator = false
// collectionView.showsVerticalScrollIndicator = false
// collectionView.register(BreadcrumbCellItem.self, forCellWithReuseIdentifier: BreadcrumbCellItem.identifier)
// collectionView.backgroundColor = .clear
// return collectionView
// }()
private var collectionView = ButtonGroup().with {
$0.alignment = .left
$0.spacerConfiguration = BreadcrumbsSpacerConfig()
}
///Collectionview to render Breadcrumb Items
private lazy var collectionView: SelfSizingCollectionView = {
let collectionView = SelfSizingCollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.isScrollEnabled = false
collectionView.translatesAutoresizingMaskIntoConstraints = false
collectionView.delegate = self
collectionView.dataSource = self
collectionView.showsHorizontalScrollIndicator = false
collectionView.showsVerticalScrollIndicator = false
collectionView.register(BreadcrumbCellItem.self, forCellWithReuseIdentifier: BreadcrumbCellItem.identifier)
collectionView.backgroundColor = .clear
return collectionView
}()
//--------------------------------------------------
// MARK: - Private Methods
@ -132,22 +118,22 @@ open class Breadcrumbs: View {
/// Used to make changes to the View based off a change events or from local properties.
open override func updateView() {
super.updateView()
collectionView.surface = surface
collectionView.reloadData()
}
// open override func layoutSubviews() {
// //Turn off the ability to execute updateView() in the super
// //since we don't want an infinite loop
// shouldUpdateView = false
// super.layoutSubviews()
// shouldUpdateView = true
//
// // Accounts for any collection size changes
// DispatchQueue.main.async { [weak self] in
// guard let self else { return }
// self.collectionView.collectionViewLayout.invalidateLayout()
// }
// }
open override func layoutSubviews() {
//Turn off the ability to execute updateView() in the super
//since we don't want an infinite loop
shouldUpdateView = false
super.layoutSubviews()
shouldUpdateView = true
// Accounts for any collection size changes
DispatchQueue.main.async { [weak self] in
guard let self else { return }
self.collectionView.collectionViewLayout.invalidateLayout()
}
}
}
extension Breadcrumbs: UICollectionViewDelegate, UICollectionViewDataSource {

View File

@ -111,16 +111,6 @@ open class ButtonGroup: View {
$0.delegate = self
}
internal var spacerConfiguration: (any ButtonGroupSpaceable)? {
didSet {
if let spacerConfiguration {
positionLayout.spacerConfiguration = spacerConfiguration
}
collectionView.collectionViewLayout.invalidateLayout()
collectionView.reloadData()
}
}
/// CollectionView that renders the array of buttonBase obects.
fileprivate lazy var collectionView: SelfSizingCollectionView = {

View File

@ -6,23 +6,21 @@
//
import Foundation
import UIKit
protocol ButtonGroupSpaceable {
func getSpacing(for axis: NSLayoutConstraint.Axis, with primary: ButtonBase, neighboring: ButtonBase) -> CGFloat
func getVerticalSpacing(for row: ButtonCollectionViewRow, neighboringRow: ButtonCollectionViewRow?) -> CGFloat
}
struct ButtonGroupSpacerConstants: ButtonGroupSpaceable {
let defaultSpace = 12.0
struct ButtonGroupConstants {
static let defaultSpace = 12.0
enum ButtonSpacingAxis {
case horizontal, vertical
}
/// This will determine the spacing that will go between 2 ButtonBases either horizontally or vertically
/// - Parameters:
/// - axis: horizontal/vertical
/// - primary: first ButtonBase
/// - neighboring: next ButtonBase based off of axis
/// - Returns: float value
func getSpacing(for axis: NSLayoutConstraint.Axis, with primary: ButtonBase, neighboring: ButtonBase) -> CGFloat {
static func getSpacing(for axis: ButtonSpacingAxis, with primary: ButtonBase, neighboring: ButtonBase) -> CGFloat {
//large button
if let button = primary as? Button, button.size == .large {
@ -92,7 +90,7 @@ struct ButtonGroupSpacerConstants: ButtonGroupSpaceable {
/// Gets the tallest ButtonBases within the row
/// - Parameter row: Row that includes the attributes
/// - Returns: Array of [ButtonLayoutAttributes] of the tallest items
private func getTallestAttributes(for row: ButtonCollectionViewRow) -> [ButtonLayoutAttributes] {
private static func getTallestAttributes(for row: ButtonCollectionViewRow) -> [ButtonLayoutAttributes] {
var height = 0.0
var foundIndexes:[Int] = []
for (index, attribute) in row.attributes.enumerated() {
@ -104,12 +102,13 @@ struct ButtonGroupSpacerConstants: ButtonGroupSpaceable {
return foundIndexes.compactMap { row.attributes[$0] }
}
/// Gets the vertical spacing that will go between rows.
/// - Parameters:
/// - row: Primary row that the space will go between
/// - neighboringRow: Secondary row that will be below the Primary
/// - Returns: Amount of space that should live between these rows based off of the items. The largest space will win when the comparison occurs.
func getVerticalSpacing(for row: ButtonCollectionViewRow, neighboringRow: ButtonCollectionViewRow?) -> CGFloat {
static func getVerticalSpacing(for row: ButtonCollectionViewRow, neighboringRow: ButtonCollectionViewRow?) -> CGFloat {
// if the neighboringRow is nil, this is the last row in the collection
// so return no space
guard let neighboringRow else { return 0.0 }

View File

@ -146,7 +146,6 @@ class ButtonLayoutAttributes: UICollectionViewLayoutAttributes{
class ButtonGroupPositionLayout: UICollectionViewLayout {
weak var delegate: ButtongGroupPositionLayoutDelegate?
var spacerConfiguration: ButtonGroupSpaceable = ButtonGroupSpacerConstants()
// Total height of the content. Will be used to configure the scrollview content
var layoutHeight: CGFloat = 0.0
@ -227,7 +226,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout {
let neighbor = delegate.collectionView(collectionView, buttonBaseAtIndexPath: IndexPath(item: nextItem, section: section))
// get the spacing to go between the current and next button
itemSpacing = spacerConfiguration.getSpacing(for: .horizontal, with: itemButtonBase, neighboring: neighbor)
itemSpacing = ButtonGroupConstants.getSpacing(for: .horizontal, with: itemButtonBase, neighboring: neighbor)
}
// create the custom layout attribute
@ -256,7 +255,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout {
if item > 0 {
let prevRow = rows[item - 1]
rowSpacing = spacerConfiguration.getVerticalSpacing(for: prevRow, neighboringRow: row)
rowSpacing = ButtonGroupConstants.getVerticalSpacing(for: prevRow, neighboringRow: row)
row.rowY = layoutHeight + rowSpacing
layoutHeight += rowSpacing
}
@ -274,7 +273,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout {
itemCache = rowAttributes
}
override func layoutAttributesForElements(in rect: CGRect)-> [UICollectionViewLayoutAttributes]? {
var visibleLayoutAttributes: [UICollectionViewLayoutAttributes] = []