removed constraints and for this class to be setup correctly in its parent rather than doing it in the view. similar to how UIButton works.
This commit is contained in:
parent
58b83fc37f
commit
8028c8a785
@ -63,7 +63,7 @@ open class FootnoteGroup: View {
|
||||
} else {
|
||||
_width = nil
|
||||
}
|
||||
setNeedsUpdate()
|
||||
updateContainerWidth()
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ open class FootnoteGroup: View {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Configuration Properties
|
||||
//--------------------------------------------------
|
||||
internal var maxWidth: CGFloat { frame.size.width }
|
||||
internal var maxWidth: CGFloat { horizontalPinnedWidth() ?? (superview?.frame.size.width ?? frame.size.width) }
|
||||
internal var minWidth: CGFloat { containerSize.width }
|
||||
internal var containerSize: CGSize { CGSize(width: 55, height: 44) }
|
||||
|
||||
@ -91,8 +91,6 @@ open class FootnoteGroup: View {
|
||||
// MARK: - Constraints
|
||||
//--------------------------------------------------
|
||||
internal var widthConstraint: NSLayoutConstraint?
|
||||
internal var trailingEqualsConstraint: NSLayoutConstraint?
|
||||
internal var trailingLessThanEqualsConstraint: NSLayoutConstraint?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Overrides
|
||||
@ -104,12 +102,8 @@ open class FootnoteGroup: View {
|
||||
|
||||
// add footnote item stackview.
|
||||
addSubview(stackView)
|
||||
stackView.pinTop().pinBottom().pinLeading()
|
||||
trailingEqualsConstraint = stackView.pinTrailing(anchor: trailingAnchor)
|
||||
|
||||
// width constraints
|
||||
trailingLessThanEqualsConstraint = stackView.pinTrailingLessThanOrEqualTo(anchor: trailingAnchor)?.deactivate()
|
||||
widthConstraint = stackView.widthAnchor.constraint(equalToConstant: 0).deactivate()
|
||||
stackView.pinToSuperView()
|
||||
widthConstraint = widthAnchor.constraint(equalToConstant: 0).deactivate()
|
||||
}
|
||||
|
||||
open override func setDefaults() {
|
||||
@ -117,18 +111,7 @@ open class FootnoteGroup: View {
|
||||
width = nil
|
||||
footnoteItems = []
|
||||
}
|
||||
|
||||
/// Resets to default settings.
|
||||
open override func reset() {
|
||||
super.reset()
|
||||
}
|
||||
|
||||
/// Used to make changes to the View based off a change events or from local properties.
|
||||
open override func updateView() {
|
||||
super.updateView()
|
||||
updateContainerWidth()
|
||||
}
|
||||
|
||||
|
||||
internal func updateFootnoteItems() {
|
||||
// symbol containers are as wide as the widest symbol container in the group.
|
||||
var symbolMaxWidth = 0.0
|
||||
@ -151,10 +134,11 @@ open class FootnoteGroup: View {
|
||||
stackView.addArrangedSubview(footnote)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Update container width after updating content.
|
||||
internal func updateContainerWidth() {
|
||||
var newWidth = 0.0
|
||||
|
||||
switch width {
|
||||
case .percentage(let percentage):
|
||||
newWidth = max(maxWidth * ((percentage) / 100), minWidth)
|
||||
@ -162,20 +146,15 @@ open class FootnoteGroup: View {
|
||||
case .value(let value):
|
||||
newWidth = value > maxWidth ? maxWidth : value
|
||||
|
||||
case nil:
|
||||
newWidth = maxWidth
|
||||
case nil: break
|
||||
|
||||
}
|
||||
|
||||
widthConstraint?.deactivate()
|
||||
trailingLessThanEqualsConstraint?.deactivate()
|
||||
trailingEqualsConstraint?.deactivate()
|
||||
|
||||
if newWidth > minWidth && newWidth < maxWidth {
|
||||
widthConstraint?.constant = newWidth
|
||||
widthConstraint?.activate()
|
||||
trailingLessThanEqualsConstraint?.activate()
|
||||
} else {
|
||||
trailingEqualsConstraint?.activate()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,7 +117,7 @@ open class FootnoteItem: View {
|
||||
} else {
|
||||
_width = nil
|
||||
}
|
||||
setNeedsUpdate()
|
||||
updateContainerWidth()
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ open class FootnoteItem: View {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Configuration Properties
|
||||
//--------------------------------------------------
|
||||
internal var maxWidth: CGFloat { frame.size.width }
|
||||
internal var maxWidth: CGFloat { horizontalPinnedWidth() ?? (superview?.frame.size.width ?? frame.size.width) }
|
||||
internal var minWidth: CGFloat { containerSize.width }
|
||||
internal var containerSize: CGSize { CGSize(width: 45, height: 44) }
|
||||
|
||||
@ -161,8 +161,6 @@ open class FootnoteItem: View {
|
||||
//--------------------------------------------------
|
||||
internal var symbolWidthConstraint: NSLayoutConstraint?
|
||||
internal var itemWidthConstraint: NSLayoutConstraint?
|
||||
internal var trailingEqualsConstraint: NSLayoutConstraint?
|
||||
internal var trailingLessThanEqualsConstraint: NSLayoutConstraint?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Overrides
|
||||
@ -174,12 +172,10 @@ open class FootnoteItem: View {
|
||||
|
||||
// add footnote item stackview.
|
||||
addSubview(itemStackView)
|
||||
itemStackView.pinTop().pinBottom().pinLeading()
|
||||
trailingEqualsConstraint = itemStackView.pinTrailing(anchor: trailingAnchor)
|
||||
itemStackView.pinToSuperView()
|
||||
|
||||
// width constraints
|
||||
itemWidthConstraint = itemStackView.widthAnchor.constraint(equalToConstant: 0).deactivate()
|
||||
trailingLessThanEqualsConstraint = itemStackView.pinTrailingLessThanOrEqualTo(anchor: trailingAnchor)?.deactivate()
|
||||
itemWidthConstraint = widthAnchor.constraint(equalToConstant: 0).deactivate()
|
||||
|
||||
// add symbol label, text label to stack.
|
||||
itemStackView.addArrangedSubview(symbolLabel)
|
||||
@ -236,8 +232,6 @@ open class FootnoteItem: View {
|
||||
attributes.append(TooltipLabelAttribute(surface: surface, model: tooltipModel, presenter: self))
|
||||
textLabel.attributes = attributes
|
||||
}
|
||||
|
||||
updateContainerWidth()
|
||||
}
|
||||
|
||||
/// Update container width after updating content.
|
||||
@ -251,18 +245,13 @@ open class FootnoteItem: View {
|
||||
newWidth = value > maxWidth ? maxWidth : value
|
||||
|
||||
case nil:
|
||||
newWidth = maxWidth
|
||||
}
|
||||
break
|
||||
}
|
||||
itemWidthConstraint?.deactivate()
|
||||
trailingLessThanEqualsConstraint?.deactivate()
|
||||
trailingEqualsConstraint?.deactivate()
|
||||
|
||||
if newWidth > minWidth && newWidth < maxWidth {
|
||||
itemWidthConstraint?.constant = newWidth
|
||||
itemWidthConstraint?.activate()
|
||||
trailingLessThanEqualsConstraint?.activate()
|
||||
} else {
|
||||
trailingEqualsConstraint?.activate()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user