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 {
|
} else {
|
||||||
_width = nil
|
_width = nil
|
||||||
}
|
}
|
||||||
setNeedsUpdate()
|
updateContainerWidth()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ open class FootnoteGroup: View {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Configuration Properties
|
// 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 minWidth: CGFloat { containerSize.width }
|
||||||
internal var containerSize: CGSize { CGSize(width: 55, height: 44) }
|
internal var containerSize: CGSize { CGSize(width: 55, height: 44) }
|
||||||
|
|
||||||
@ -91,8 +91,6 @@ open class FootnoteGroup: View {
|
|||||||
// MARK: - Constraints
|
// MARK: - Constraints
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
internal var widthConstraint: NSLayoutConstraint?
|
internal var widthConstraint: NSLayoutConstraint?
|
||||||
internal var trailingEqualsConstraint: NSLayoutConstraint?
|
|
||||||
internal var trailingLessThanEqualsConstraint: NSLayoutConstraint?
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Overrides
|
// MARK: - Overrides
|
||||||
@ -104,12 +102,8 @@ open class FootnoteGroup: View {
|
|||||||
|
|
||||||
// add footnote item stackview.
|
// add footnote item stackview.
|
||||||
addSubview(stackView)
|
addSubview(stackView)
|
||||||
stackView.pinTop().pinBottom().pinLeading()
|
stackView.pinToSuperView()
|
||||||
trailingEqualsConstraint = stackView.pinTrailing(anchor: trailingAnchor)
|
widthConstraint = widthAnchor.constraint(equalToConstant: 0).deactivate()
|
||||||
|
|
||||||
// width constraints
|
|
||||||
trailingLessThanEqualsConstraint = stackView.pinTrailingLessThanOrEqualTo(anchor: trailingAnchor)?.deactivate()
|
|
||||||
widthConstraint = stackView.widthAnchor.constraint(equalToConstant: 0).deactivate()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func setDefaults() {
|
open override func setDefaults() {
|
||||||
@ -118,17 +112,6 @@ open class FootnoteGroup: View {
|
|||||||
footnoteItems = []
|
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() {
|
internal func updateFootnoteItems() {
|
||||||
// symbol containers are as wide as the widest symbol container in the group.
|
// symbol containers are as wide as the widest symbol container in the group.
|
||||||
var symbolMaxWidth = 0.0
|
var symbolMaxWidth = 0.0
|
||||||
@ -155,6 +138,7 @@ open class FootnoteGroup: View {
|
|||||||
/// Update container width after updating content.
|
/// Update container width after updating content.
|
||||||
internal func updateContainerWidth() {
|
internal func updateContainerWidth() {
|
||||||
var newWidth = 0.0
|
var newWidth = 0.0
|
||||||
|
|
||||||
switch width {
|
switch width {
|
||||||
case .percentage(let percentage):
|
case .percentage(let percentage):
|
||||||
newWidth = max(maxWidth * ((percentage) / 100), minWidth)
|
newWidth = max(maxWidth * ((percentage) / 100), minWidth)
|
||||||
@ -162,20 +146,15 @@ open class FootnoteGroup: View {
|
|||||||
case .value(let value):
|
case .value(let value):
|
||||||
newWidth = value > maxWidth ? maxWidth : value
|
newWidth = value > maxWidth ? maxWidth : value
|
||||||
|
|
||||||
case nil:
|
case nil: break
|
||||||
newWidth = maxWidth
|
|
||||||
}
|
}
|
||||||
|
|
||||||
widthConstraint?.deactivate()
|
widthConstraint?.deactivate()
|
||||||
trailingLessThanEqualsConstraint?.deactivate()
|
|
||||||
trailingEqualsConstraint?.deactivate()
|
|
||||||
|
|
||||||
if newWidth > minWidth && newWidth < maxWidth {
|
if newWidth > minWidth && newWidth < maxWidth {
|
||||||
widthConstraint?.constant = newWidth
|
widthConstraint?.constant = newWidth
|
||||||
widthConstraint?.activate()
|
widthConstraint?.activate()
|
||||||
trailingLessThanEqualsConstraint?.activate()
|
|
||||||
} else {
|
|
||||||
trailingEqualsConstraint?.activate()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -117,7 +117,7 @@ open class FootnoteItem: View {
|
|||||||
} else {
|
} else {
|
||||||
_width = nil
|
_width = nil
|
||||||
}
|
}
|
||||||
setNeedsUpdate()
|
updateContainerWidth()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ open class FootnoteItem: View {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Configuration Properties
|
// 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 minWidth: CGFloat { containerSize.width }
|
||||||
internal var containerSize: CGSize { CGSize(width: 45, height: 44) }
|
internal var containerSize: CGSize { CGSize(width: 45, height: 44) }
|
||||||
|
|
||||||
@ -161,8 +161,6 @@ open class FootnoteItem: View {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
internal var symbolWidthConstraint: NSLayoutConstraint?
|
internal var symbolWidthConstraint: NSLayoutConstraint?
|
||||||
internal var itemWidthConstraint: NSLayoutConstraint?
|
internal var itemWidthConstraint: NSLayoutConstraint?
|
||||||
internal var trailingEqualsConstraint: NSLayoutConstraint?
|
|
||||||
internal var trailingLessThanEqualsConstraint: NSLayoutConstraint?
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Overrides
|
// MARK: - Overrides
|
||||||
@ -174,12 +172,10 @@ open class FootnoteItem: View {
|
|||||||
|
|
||||||
// add footnote item stackview.
|
// add footnote item stackview.
|
||||||
addSubview(itemStackView)
|
addSubview(itemStackView)
|
||||||
itemStackView.pinTop().pinBottom().pinLeading()
|
itemStackView.pinToSuperView()
|
||||||
trailingEqualsConstraint = itemStackView.pinTrailing(anchor: trailingAnchor)
|
|
||||||
|
|
||||||
// width constraints
|
// width constraints
|
||||||
itemWidthConstraint = itemStackView.widthAnchor.constraint(equalToConstant: 0).deactivate()
|
itemWidthConstraint = widthAnchor.constraint(equalToConstant: 0).deactivate()
|
||||||
trailingLessThanEqualsConstraint = itemStackView.pinTrailingLessThanOrEqualTo(anchor: trailingAnchor)?.deactivate()
|
|
||||||
|
|
||||||
// add symbol label, text label to stack.
|
// add symbol label, text label to stack.
|
||||||
itemStackView.addArrangedSubview(symbolLabel)
|
itemStackView.addArrangedSubview(symbolLabel)
|
||||||
@ -236,8 +232,6 @@ open class FootnoteItem: View {
|
|||||||
attributes.append(TooltipLabelAttribute(surface: surface, model: tooltipModel, presenter: self))
|
attributes.append(TooltipLabelAttribute(surface: surface, model: tooltipModel, presenter: self))
|
||||||
textLabel.attributes = attributes
|
textLabel.attributes = attributes
|
||||||
}
|
}
|
||||||
|
|
||||||
updateContainerWidth()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update container width after updating content.
|
/// Update container width after updating content.
|
||||||
@ -251,18 +245,13 @@ open class FootnoteItem: View {
|
|||||||
newWidth = value > maxWidth ? maxWidth : value
|
newWidth = value > maxWidth ? maxWidth : value
|
||||||
|
|
||||||
case nil:
|
case nil:
|
||||||
newWidth = maxWidth
|
break
|
||||||
}
|
}
|
||||||
itemWidthConstraint?.deactivate()
|
itemWidthConstraint?.deactivate()
|
||||||
trailingLessThanEqualsConstraint?.deactivate()
|
|
||||||
trailingEqualsConstraint?.deactivate()
|
|
||||||
|
|
||||||
if newWidth > minWidth && newWidth < maxWidth {
|
if newWidth > minWidth && newWidth < maxWidth {
|
||||||
itemWidthConstraint?.constant = newWidth
|
itemWidthConstraint?.constant = newWidth
|
||||||
itemWidthConstraint?.activate()
|
itemWidthConstraint?.activate()
|
||||||
trailingLessThanEqualsConstraint?.activate()
|
|
||||||
} else {
|
|
||||||
trailingEqualsConstraint?.activate()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user