diff --git a/VDS/Components/Buttons/Button/Button.swift b/VDS/Components/Buttons/Button/Button.swift index 72953bdb..d23106af 100644 --- a/VDS/Components/Buttons/Button/Button.swift +++ b/VDS/Components/Buttons/Button/Button.swift @@ -143,6 +143,11 @@ open class Button: ButtonBase, Useable { //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- + open override var intrinsicContentSize: CGSize { + guard let width, width > 0 else { return super.intrinsicContentSize } + return CGSize(width: width > size.minimumWidth ? width : size.minimumWidth, height: size.height) + } + open override func updateView() { super.updateView() let bgColor = buttonBackgroundColorConfiguration.getColor(self) diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index cc7c54f4..165ac959 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -149,9 +149,10 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) cell.subviews.forEach { $0.removeFromSuperview() } cell.addSubview(button) - button.pinToSuperView() -// cell.layer.borderColor = UIColor.black.cgColor -// cell.layer.borderWidth = 1 + button.pinLeading() + button.pinTrailing() + button.centerYAnchor.constraint(equalTo: cell.centerYAnchor).isActive = true + //cell.debugBorder() return cell } diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroupConstants.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroupConstants.swift index 193f5723..015be8b4 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroupConstants.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroupConstants.swift @@ -97,11 +97,15 @@ struct ButtonGroupConstants { } //text link caret else if let _ = primary as? TextLinkCaret { - if let _ = neighboring as? TextLinkCaret { - return 24.0 - } else { - return defaultSpace - } + if let neighboringButton = neighboring as? Button, neighboringButton.size == .large { + return 16.0 + } else if let _ = neighboring as? TextLinkCaret { + return 24.0 + } else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .large { + return 24.0 + } else { + return defaultSpace + } } //small button else if let button = primary as? Button, button.size == .small { @@ -117,6 +121,8 @@ struct ButtonGroupConstants { else if let textLink = primary as? TextLink, textLink.size == .small { if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .small { return 32.0 + } else if let neighboringButton = neighboring as? Button, neighboringButton.size == .small { + return 24.0 } else { return defaultSpace } diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift index 32bdab7b..5ab5fe37 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift @@ -32,6 +32,11 @@ class ButtonCollectionViewRow { attributes.compactMap{$0.frame.height}.max() ?? 0 } + var maxHeightIndexPath: IndexPath { + let maxHeight = rowHeight + return attributes.first(where: {$0.frame.height == maxHeight})!.indexPath + } + var rowY: CGFloat = 0 { didSet { for attribute in attributes { @@ -42,7 +47,7 @@ class ButtonCollectionViewRow { func layout(for position: ButtonPosition, with collectionViewWidth: CGFloat){ var offset = 0.0 - + let height = rowHeight attributes.last?.spacing = 0 switch position { @@ -56,6 +61,9 @@ class ButtonCollectionViewRow { for attribute in attributes { attribute.frame.origin.x = offset + if attribute.frame.height < height { + attribute.frame.size.height = height + } offset += attribute.frame.width + attribute.spacing } } @@ -176,10 +184,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout { } layoutWidthIterator = 0.0 - - // recalculate rows x based off of positions - rows.forEach { $0.layout(for: position, with: collectionViewWidth) } - + // calculate the layoutHeight = 0.0 @@ -191,7 +196,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout { var rowSpacing = 0.0 if item > 0 { - rowSpacing = row.hasButtons ? ButtonGroupConstants.rowSpacingButton : ButtonGroupConstants.rowSpacingTextLink + rowSpacing = 12.0 row.rowY = layoutHeight + rowSpacing layoutHeight += rowSpacing } @@ -199,6 +204,9 @@ class ButtonGroupPositionLayout: UICollectionViewLayout { layoutHeight += row.rowHeight } + // recalculate rows x based off of positions + rows.forEach { $0.layout(for: position, with: collectionViewWidth) } + let rowAttributes = rows.flatMap { $0.attributes } itemCache = rowAttributes diff --git a/VDS/Components/Buttons/TextLink/TextLink.swift b/VDS/Components/Buttons/TextLink/TextLink.swift index 36e415ec..7dd4839f 100644 --- a/VDS/Components/Buttons/TextLink/TextLink.swift +++ b/VDS/Components/Buttons/TextLink/TextLink.swift @@ -103,9 +103,9 @@ open class TextLink: ButtonBase { //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- - override open var intrinsicContentSize: CGSize { - var itemWidth = super.intrinsicContentSize.width - return CGSize(width: itemWidth, height: height) + open override var intrinsicContentSize: CGSize { + let size = titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize + return CGSize(width: size.width, height: height) } open override func updateView() { diff --git a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift index 368e0c14..ee702981 100644 --- a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift +++ b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift @@ -55,7 +55,7 @@ open class TextLinkCaret: ButtonBase { get{ _text } set { var updatedText = newValue ?? "" - updatedText = iconPosition == .right ? "\(updatedText) " : " \(updatedText)" + updatedText = iconPosition == .right ? "\(updatedText) " : " \(updatedText)" _text = updatedText didChange() } @@ -95,7 +95,6 @@ open class TextLinkCaret: ButtonBase { //-------------------------------------------------- open override func setup() { super.setup() - //constraints heightAnchor.constraint(greaterThanOrEqualToConstant: height).isActive = true @@ -112,7 +111,11 @@ open class TextLinkCaret: ButtonBase { // MARK: - Overrides //-------------------------------------------------- override open var intrinsicContentSize: CGSize { - var itemWidth = super.intrinsicContentSize.width + //get the labels size, if not the button + let size = titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize + + var itemWidth = size.width + if let caretWidth = caretView.size?.dimensions().width { itemWidth += caretWidth } diff --git a/VDS/Extensions/UIView.swift b/VDS/Extensions/UIView.swift index 0214c67a..eb041400 100644 --- a/VDS/Extensions/UIView.swift +++ b/VDS/Extensions/UIView.swift @@ -116,3 +116,16 @@ extension UIView { } } + + +extension UIView { + public func debugBorder(show shouldShow: Bool = true) { + if shouldShow { + layer.borderColor = UIColor.red.cgColor + layer.borderWidth = 1 + } else { + layer.borderColor = UIColor.clear.cgColor + layer.borderWidth = 0 + } + } +}