refactored the adding of footnotes similar to the Tabs
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
9f6c115f50
commit
8ce9108d45
@ -42,7 +42,7 @@ open class FootnoteGroup: View {
|
||||
// MARK: - Public Properties
|
||||
//--------------------------------------------------
|
||||
/// Array of ``Footnote`` for the Footnote items.
|
||||
open var footnoteItems: [FootnoteItem] = [] { didSet { setNeedsUpdate() } }
|
||||
open var footnoteItems: [FootnoteItem] = [] { didSet { updateFootnoteItems() } }
|
||||
|
||||
/// Any percentage or pixel value and cannot exceed container size.
|
||||
/// If there is a width that is larger than container size, the footnote will resize to container's width.
|
||||
@ -127,26 +127,28 @@ open class FootnoteGroup: View {
|
||||
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
|
||||
if footnoteItems.count > 0 {
|
||||
for index in 0...footnoteItems.count - 1 {
|
||||
let footnote: FootnoteItem = footnoteItems[index]
|
||||
let separatorWidth = Label().with { $0.text = footnote.symbolType; $0.sizeToFit() }.intrinsicContentSize.width
|
||||
symbolMaxWidth = separatorWidth > symbolMaxWidth ? separatorWidth : symbolMaxWidth
|
||||
}
|
||||
|
||||
footnoteItems.forEach { footnote in
|
||||
let separatorWidth = Label().with {
|
||||
$0.text = footnote.symbolType
|
||||
$0.textStyle = footnote.symbolLabel.textStyle
|
||||
$0.sizeToFit()
|
||||
}.intrinsicContentSize.width
|
||||
symbolMaxWidth = max(separatorWidth, symbolMaxWidth)
|
||||
}
|
||||
|
||||
stackView.subviews.forEach{$0.removeFromSuperview()}
|
||||
stackView.removeArrangedSubviews()
|
||||
|
||||
// add symbol label, text label to stack.
|
||||
if footnoteItems.count > 0 {
|
||||
for index in 0...footnoteItems.count - 1 {
|
||||
let footnote: FootnoteItem = footnoteItems[index]
|
||||
footnote.symbolWidth = symbolMaxWidth
|
||||
footnote.surface = surface
|
||||
stackView.addArrangedSubview(footnote)
|
||||
}
|
||||
footnoteItems.forEach { footnote in
|
||||
footnote.symbolWidth = symbolMaxWidth
|
||||
footnote.surface = surface
|
||||
stackView.addArrangedSubview(footnote)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user