Merge branch 'feature/buttonGroupUpdate' into 'develop'

refactored code

See merge request BPHV_MIPS/vds_ios!19
This commit is contained in:
Bruce, Matt R 2022-12-02 19:54:16 +00:00
commit cf32ea5ac3
7 changed files with 56 additions and 20 deletions

View File

@ -143,6 +143,11 @@ open class Button: ButtonBase, Useable {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Overrides // 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() { open override func updateView() {
super.updateView() super.updateView()
let bgColor = buttonBackgroundColorConfiguration.getColor(self) let bgColor = buttonBackgroundColorConfiguration.getColor(self)

View File

@ -149,9 +149,10 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath)
cell.subviews.forEach { $0.removeFromSuperview() } cell.subviews.forEach { $0.removeFromSuperview() }
cell.addSubview(button) cell.addSubview(button)
button.pinToSuperView() button.pinLeading()
// cell.layer.borderColor = UIColor.black.cgColor button.pinTrailing()
// cell.layer.borderWidth = 1 button.centerYAnchor.constraint(equalTo: cell.centerYAnchor).isActive = true
//cell.debugBorder()
return cell return cell
} }

View File

@ -97,11 +97,15 @@ struct ButtonGroupConstants {
} }
//text link caret //text link caret
else if let _ = primary as? TextLinkCaret { else if let _ = primary as? TextLinkCaret {
if let _ = neighboring as? TextLinkCaret { if let neighboringButton = neighboring as? Button, neighboringButton.size == .large {
return 24.0 return 16.0
} else { } else if let _ = neighboring as? TextLinkCaret {
return defaultSpace return 24.0
} } else if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .large {
return 24.0
} else {
return defaultSpace
}
} }
//small button //small button
else if let button = primary as? Button, button.size == .small { 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 { else if let textLink = primary as? TextLink, textLink.size == .small {
if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .small { if let neighboringTextLink = neighboring as? TextLink, neighboringTextLink.size == .small {
return 32.0 return 32.0
} else if let neighboringButton = neighboring as? Button, neighboringButton.size == .small {
return 24.0
} else { } else {
return defaultSpace return defaultSpace
} }

View File

@ -32,6 +32,11 @@ class ButtonCollectionViewRow {
attributes.compactMap{$0.frame.height}.max() ?? 0 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 { var rowY: CGFloat = 0 {
didSet { didSet {
for attribute in attributes { for attribute in attributes {
@ -42,7 +47,7 @@ class ButtonCollectionViewRow {
func layout(for position: ButtonPosition, with collectionViewWidth: CGFloat){ func layout(for position: ButtonPosition, with collectionViewWidth: CGFloat){
var offset = 0.0 var offset = 0.0
let height = rowHeight
attributes.last?.spacing = 0 attributes.last?.spacing = 0
switch position { switch position {
@ -56,6 +61,9 @@ class ButtonCollectionViewRow {
for attribute in attributes { for attribute in attributes {
attribute.frame.origin.x = offset attribute.frame.origin.x = offset
if attribute.frame.height < height {
attribute.frame.size.height = height
}
offset += attribute.frame.width + attribute.spacing offset += attribute.frame.width + attribute.spacing
} }
} }
@ -176,10 +184,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout {
} }
layoutWidthIterator = 0.0 layoutWidthIterator = 0.0
// recalculate rows x based off of positions
rows.forEach { $0.layout(for: position, with: collectionViewWidth) }
// calculate the // calculate the
layoutHeight = 0.0 layoutHeight = 0.0
@ -191,7 +196,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout {
var rowSpacing = 0.0 var rowSpacing = 0.0
if item > 0 { if item > 0 {
rowSpacing = row.hasButtons ? ButtonGroupConstants.rowSpacingButton : ButtonGroupConstants.rowSpacingTextLink rowSpacing = 12.0
row.rowY = layoutHeight + rowSpacing row.rowY = layoutHeight + rowSpacing
layoutHeight += rowSpacing layoutHeight += rowSpacing
} }
@ -199,6 +204,9 @@ class ButtonGroupPositionLayout: UICollectionViewLayout {
layoutHeight += row.rowHeight layoutHeight += row.rowHeight
} }
// recalculate rows x based off of positions
rows.forEach { $0.layout(for: position, with: collectionViewWidth) }
let rowAttributes = rows.flatMap { $0.attributes } let rowAttributes = rows.flatMap { $0.attributes }
itemCache = rowAttributes itemCache = rowAttributes

View File

@ -103,9 +103,9 @@ open class TextLink: ButtonBase {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Overrides // MARK: - Overrides
//-------------------------------------------------- //--------------------------------------------------
override open var intrinsicContentSize: CGSize { open override var intrinsicContentSize: CGSize {
var itemWidth = super.intrinsicContentSize.width let size = titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize
return CGSize(width: itemWidth, height: height) return CGSize(width: size.width, height: height)
} }
open override func updateView() { open override func updateView() {

View File

@ -55,7 +55,7 @@ open class TextLinkCaret: ButtonBase {
get{ _text } get{ _text }
set { set {
var updatedText = newValue ?? "" var updatedText = newValue ?? ""
updatedText = iconPosition == .right ? "\(updatedText) " : " \(updatedText)" updatedText = iconPosition == .right ? "\(updatedText) " : " \(updatedText)"
_text = updatedText _text = updatedText
didChange() didChange()
} }
@ -95,7 +95,6 @@ open class TextLinkCaret: ButtonBase {
//-------------------------------------------------- //--------------------------------------------------
open override func setup() { open override func setup() {
super.setup() super.setup()
//constraints //constraints
heightAnchor.constraint(greaterThanOrEqualToConstant: height).isActive = true heightAnchor.constraint(greaterThanOrEqualToConstant: height).isActive = true
@ -112,7 +111,11 @@ open class TextLinkCaret: ButtonBase {
// MARK: - Overrides // MARK: - Overrides
//-------------------------------------------------- //--------------------------------------------------
override open var intrinsicContentSize: CGSize { 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 { if let caretWidth = caretView.size?.dimensions().width {
itemWidth += caretWidth itemWidth += caretWidth
} }

View File

@ -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
}
}
}