Merge branch 'feature/buttonGroupUpdate' into 'develop'
refactored code See merge request BPHV_MIPS/vds_ios!19
This commit is contained in:
commit
cf32ea5ac3
@ -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)
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user