diff --git a/VDS/Components/Footnote/FootnoteGroup.swift b/VDS/Components/Footnote/FootnoteGroup.swift index 693639ee..cb129f04 100644 --- a/VDS/Components/Footnote/FootnoteGroup.swift +++ b/VDS/Components/Footnote/FootnoteGroup.swift @@ -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) } }