From 5291de36bc768f523a23d43833e9819aed13b920 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 2 Dec 2022 09:18:06 -0600 Subject: [PATCH 1/8] refactored code Signed-off-by: Matt Bruce --- VDS/Components/Buttons/TextLink/TextLink.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/VDS/Components/Buttons/TextLink/TextLink.swift b/VDS/Components/Buttons/TextLink/TextLink.swift index 36e415ec..c50fc9d5 100644 --- a/VDS/Components/Buttons/TextLink/TextLink.swift +++ b/VDS/Components/Buttons/TextLink/TextLink.swift @@ -104,8 +104,7 @@ open class TextLink: ButtonBase { // MARK: - Overrides //-------------------------------------------------- override open var intrinsicContentSize: CGSize { - var itemWidth = super.intrinsicContentSize.width - return CGSize(width: itemWidth, height: height) + return CGSize(width: super.intrinsicContentSize.width, height: height) } open override func updateView() { From d08cce48002b04ecbc3fbe7a7e4bcebc373c4905 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 2 Dec 2022 09:53:08 -0600 Subject: [PATCH 2/8] removed anything manually setting height Signed-off-by: Matt Bruce --- .../Buttons/TextLink/TextLink.swift | 20 +------------------ .../Buttons/TextLinkCaret/TextLinkCaret.swift | 15 ++++---------- 2 files changed, 5 insertions(+), 30 deletions(-) diff --git a/VDS/Components/Buttons/TextLink/TextLink.swift b/VDS/Components/Buttons/TextLink/TextLink.swift index c50fc9d5..0a9901c6 100644 --- a/VDS/Components/Buttons/TextLink/TextLink.swift +++ b/VDS/Components/Buttons/TextLink/TextLink.swift @@ -17,7 +17,6 @@ open class TextLink: ButtonBase { //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- - private var heightConstraint: NSLayoutConstraint? private var lineHeightConstraint: NSLayoutConstraint? //-------------------------------------------------- @@ -45,15 +44,6 @@ open class TextLink: ButtonBase { $0.highlighted.darkColor = VDSColor.interactiveActiveOndark } - - private var height: CGFloat { - switch size { - case .large: - return 44 - case .small: - return 32 - } - } //-------------------------------------------------- // MARK: - Initializers @@ -88,9 +78,6 @@ open class TextLink: ButtonBase { lineHeightConstraint = line.heightAnchor.constraint(equalToConstant: 1.0) lineHeightConstraint?.isActive = true } - - heightConstraint = heightAnchor.constraint(equalToConstant: height) - heightConstraint?.isActive = true } open override func reset() { @@ -102,15 +89,10 @@ open class TextLink: ButtonBase { //-------------------------------------------------- // MARK: - Overrides - //-------------------------------------------------- - override open var intrinsicContentSize: CGSize { - return CGSize(width: super.intrinsicContentSize.width, height: height) - } - + //-------------------------------------------------- open override func updateView() { //need to set the properties so the super class //can render out the label correctly - heightConstraint?.constant = height lineHeightConstraint?.constant = isHighlighted ? 2.0 : 1.0 line.backgroundColor = textColor diff --git a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift index 368e0c14..77c3261c 100644 --- a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift +++ b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift @@ -21,8 +21,6 @@ open class TextLinkCaret: ButtonBase { //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- - private var heightConstraint: NSLayoutConstraint? - open override var typograpicalStyle: TypographicalStyle { TypographicalStyle.BoldBodyLarge } @@ -45,10 +43,6 @@ open class TextLinkCaret: ButtonBase { open var iconPosition: TextLinkCaretPosition = .right { didSet { didChange() } } - private var height: CGFloat { - 44 - } - private var _text: String? open override var text: String? { @@ -96,9 +90,6 @@ open class TextLinkCaret: ButtonBase { open override func setup() { super.setup() - //constraints - heightAnchor.constraint(greaterThanOrEqualToConstant: height).isActive = true - let size = caretView.size!.dimensions() caretView.frame = .init(x: 0, y: 0, width: size.width, height: size.height) } @@ -112,11 +103,13 @@ open class TextLinkCaret: ButtonBase { // MARK: - Overrides //-------------------------------------------------- override open var intrinsicContentSize: CGSize { - var itemWidth = super.intrinsicContentSize.width + let size = super.intrinsicContentSize + var itemWidth = size.width + if let caretWidth = caretView.size?.dimensions().width { itemWidth += caretWidth } - return CGSize(width: itemWidth, height: height) + return CGSize(width: itemWidth, height: size.height) } open override func updateView() { From 482ebc18a8f4cfa0d3d6bf2c04dbc615d7349311 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 2 Dec 2022 09:53:26 -0600 Subject: [PATCH 3/8] in a row make everything the same height of the max height Signed-off-by: Matt Bruce --- .../Buttons/ButtonGroup/ButtonGroupPositionLayout.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift index 32bdab7b..aea4e7f6 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift @@ -42,7 +42,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 +56,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 } } From 5567c1174a4284e47e9112fd0571354153b3475a Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 2 Dec 2022 10:07:37 -0600 Subject: [PATCH 4/8] removed ui button default padding around UILabel Signed-off-by: Matt Bruce --- VDS/Components/Buttons/TextLink/TextLink.swift | 6 +++++- VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/VDS/Components/Buttons/TextLink/TextLink.swift b/VDS/Components/Buttons/TextLink/TextLink.swift index 0a9901c6..e3e1bf44 100644 --- a/VDS/Components/Buttons/TextLink/TextLink.swift +++ b/VDS/Components/Buttons/TextLink/TextLink.swift @@ -89,7 +89,11 @@ open class TextLink: ButtonBase { //-------------------------------------------------- // MARK: - Overrides - //-------------------------------------------------- + //-------------------------------------------------- + open override var intrinsicContentSize: CGSize { + return titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize + } + open override func updateView() { //need to set the properties so the super class //can render out the label correctly diff --git a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift index 77c3261c..d0e5978e 100644 --- a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift +++ b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift @@ -49,7 +49,7 @@ open class TextLinkCaret: ButtonBase { get{ _text } set { var updatedText = newValue ?? "" - updatedText = iconPosition == .right ? "\(updatedText) " : " \(updatedText)" + updatedText = iconPosition == .right ? "\(updatedText) " : " \(updatedText)" _text = updatedText didChange() } @@ -89,7 +89,7 @@ open class TextLinkCaret: ButtonBase { //-------------------------------------------------- open override func setup() { super.setup() - + let size = caretView.size!.dimensions() caretView.frame = .init(x: 0, y: 0, width: size.width, height: size.height) } @@ -103,7 +103,9 @@ open class TextLinkCaret: ButtonBase { // MARK: - Overrides //-------------------------------------------------- override open var intrinsicContentSize: CGSize { - let size = super.intrinsicContentSize + //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 { From b67cda26f18c3f53215b8b4f62c3e2aba2cd16e9 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 2 Dec 2022 13:29:31 -0600 Subject: [PATCH 5/8] Revert "removed anything manually setting height" This reverts commit d08cce48002b04ecbc3fbe7a7e4bcebc373c4905. # Conflicts: # VDS/Components/Buttons/TextLink/TextLink.swift # VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift Signed-off-by: Matt Bruce --- VDS/Components/Buttons/TextLink/TextLink.swift | 17 ++++++++++++++++- .../Buttons/TextLinkCaret/TextLinkCaret.swift | 12 ++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/VDS/Components/Buttons/TextLink/TextLink.swift b/VDS/Components/Buttons/TextLink/TextLink.swift index e3e1bf44..7dd4839f 100644 --- a/VDS/Components/Buttons/TextLink/TextLink.swift +++ b/VDS/Components/Buttons/TextLink/TextLink.swift @@ -17,6 +17,7 @@ open class TextLink: ButtonBase { //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- + private var heightConstraint: NSLayoutConstraint? private var lineHeightConstraint: NSLayoutConstraint? //-------------------------------------------------- @@ -44,6 +45,15 @@ open class TextLink: ButtonBase { $0.highlighted.darkColor = VDSColor.interactiveActiveOndark } + + private var height: CGFloat { + switch size { + case .large: + return 44 + case .small: + return 32 + } + } //-------------------------------------------------- // MARK: - Initializers @@ -78,6 +88,9 @@ open class TextLink: ButtonBase { lineHeightConstraint = line.heightAnchor.constraint(equalToConstant: 1.0) lineHeightConstraint?.isActive = true } + + heightConstraint = heightAnchor.constraint(equalToConstant: height) + heightConstraint?.isActive = true } open override func reset() { @@ -91,12 +104,14 @@ open class TextLink: ButtonBase { // MARK: - Overrides //-------------------------------------------------- open override var intrinsicContentSize: CGSize { - return titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize + let size = titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize + return CGSize(width: size.width, height: height) } open override func updateView() { //need to set the properties so the super class //can render out the label correctly + heightConstraint?.constant = height lineHeightConstraint?.constant = isHighlighted ? 2.0 : 1.0 line.backgroundColor = textColor diff --git a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift index d0e5978e..ee702981 100644 --- a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift +++ b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift @@ -21,6 +21,8 @@ open class TextLinkCaret: ButtonBase { //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- + private var heightConstraint: NSLayoutConstraint? + open override var typograpicalStyle: TypographicalStyle { TypographicalStyle.BoldBodyLarge } @@ -43,6 +45,10 @@ open class TextLinkCaret: ButtonBase { open var iconPosition: TextLinkCaretPosition = .right { didSet { didChange() } } + private var height: CGFloat { + 44 + } + private var _text: String? open override var text: String? { @@ -89,7 +95,9 @@ open class TextLinkCaret: ButtonBase { //-------------------------------------------------- open override func setup() { super.setup() - + //constraints + heightAnchor.constraint(greaterThanOrEqualToConstant: height).isActive = true + let size = caretView.size!.dimensions() caretView.frame = .init(x: 0, y: 0, width: size.width, height: size.height) } @@ -111,7 +119,7 @@ open class TextLinkCaret: ButtonBase { if let caretWidth = caretView.size?.dimensions().width { itemWidth += caretWidth } - return CGSize(width: itemWidth, height: size.height) + return CGSize(width: itemWidth, height: height) } open override func updateView() { From 91b0b4415cca643df28c94d278f5e47bdd07f510 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 2 Dec 2022 13:29:47 -0600 Subject: [PATCH 6/8] updated button to deal with width for cells Signed-off-by: Matt Bruce --- VDS/Components/Buttons/Button/Button.swift | 5 +++++ 1 file changed, 5 insertions(+) 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) From 178df4ed0a56c430131284fcca6129546c974986 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 2 Dec 2022 13:29:58 -0600 Subject: [PATCH 7/8] more constants Signed-off-by: Matt Bruce --- .../ButtonGroup/ButtonGroupConstants.swift | 16 +++++++++++----- .../ButtonGroup/ButtonGroupPositionLayout.swift | 15 ++++++++++----- 2 files changed, 21 insertions(+), 10 deletions(-) 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 aea4e7f6..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 { @@ -179,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 @@ -194,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 } @@ -202,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 From 9387b0cff9a9f2f0e79cd00eb9abb0de86e18bd3 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 2 Dec 2022 13:47:01 -0600 Subject: [PATCH 8/8] refactored to debugBorder Signed-off-by: Matt Bruce --- .../Buttons/ButtonGroup/ButtonGroup.swift | 7 ++++--- VDS/Extensions/UIView.swift | 13 +++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) 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/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 + } + } +}