refactored the adding of footnotes similar to the Tabs

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-09-18 15:14:39 -05:00
parent 9f6c115f50
commit 8ce9108d45

View File

@ -42,7 +42,7 @@ open class FootnoteGroup: View {
// MARK: - Public Properties // MARK: - Public Properties
//-------------------------------------------------- //--------------------------------------------------
/// Array of ``Footnote`` for the Footnote items. /// 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. /// 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. /// 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() { open override func updateView() {
super.updateView() super.updateView()
updateContainerWidth() updateContainerWidth()
}
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
if footnoteItems.count > 0 {
for index in 0...footnoteItems.count - 1 { footnoteItems.forEach { footnote in
let footnote: FootnoteItem = footnoteItems[index] let separatorWidth = Label().with {
let separatorWidth = Label().with { $0.text = footnote.symbolType; $0.sizeToFit() }.intrinsicContentSize.width $0.text = footnote.symbolType
symbolMaxWidth = separatorWidth > symbolMaxWidth ? separatorWidth : symbolMaxWidth $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. // add symbol label, text label to stack.
if footnoteItems.count > 0 { footnoteItems.forEach { footnote in
for index in 0...footnoteItems.count - 1 { footnote.symbolWidth = symbolMaxWidth
let footnote: FootnoteItem = footnoteItems[index] footnote.surface = surface
footnote.symbolWidth = symbolMaxWidth stackView.addArrangedSubview(footnote)
footnote.surface = surface
stackView.addArrangedSubview(footnote)
}
} }
} }