Digital ACT-191 ONEAPP-10586 story: updating content as per configuration
This commit is contained in:
parent
9cbfe1d46a
commit
73caedce5f
@ -10,7 +10,8 @@ import UIKit
|
|||||||
import VDSCoreTokens
|
import VDSCoreTokens
|
||||||
import Combine
|
import Combine
|
||||||
|
|
||||||
/// A footnote is text that provides supporting details, legal copy and links to related content. If exists at the bottom or "foot" of a page or section.
|
/// A footnote is text that provides supporting details, legal copy and links to related content.
|
||||||
|
/// It exists at the bottom or "foot" of a page or section.
|
||||||
@objcMembers
|
@objcMembers
|
||||||
@objc(VDSFootnote)
|
@objc(VDSFootnote)
|
||||||
open class Footnote: View {
|
open class Footnote: View {
|
||||||
@ -117,6 +118,8 @@ open class Footnote: View {
|
|||||||
/// Text of the footnote item.
|
/// Text of the footnote item.
|
||||||
open var text: String? { didSet { setNeedsUpdate() } }
|
open var text: String? { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
|
open var tooltipModel: Tooltip.TooltipModel? { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
/// 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.
|
||||||
open var width: Width? {
|
open var width: Width? {
|
||||||
@ -145,25 +148,30 @@ open class Footnote: View {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private var _width: Width? = nil
|
private var _width: Width? = nil
|
||||||
|
|
||||||
internal var footnoteItem = UIStackView().with {
|
private lazy var itemStackView = UIStackView().with {
|
||||||
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
$0.axis = .horizontal
|
$0.axis = .horizontal
|
||||||
$0.spacing = VDSLayout.space1X
|
|
||||||
$0.alignment = .top
|
$0.alignment = .top
|
||||||
$0.distribution = .fillEqually
|
$0.distribution = .fill
|
||||||
|
$0.spacing = VDSLayout.space1X
|
||||||
|
$0.backgroundColor = .clear
|
||||||
}
|
}
|
||||||
|
|
||||||
internal var symbolLabel = Label().with {
|
internal var symbolLabel = Label().with {
|
||||||
$0.isAccessibilityElement = true
|
$0.isAccessibilityElement = true
|
||||||
|
$0.numberOfLines = 1
|
||||||
|
$0.sizeToFit()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal var footnoteItemLabel = Label().with {
|
internal var textLabel = Label().with {
|
||||||
$0.isAccessibilityElement = true
|
$0.isAccessibilityElement = true
|
||||||
$0.lineBreakMode = .byWordWrapping
|
$0.lineBreakMode = .byWordWrapping
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Configuration Properties
|
// MARK: - Constraints
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
internal var symbolWidthConstraint: NSLayoutConstraint?
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Overrides
|
// MARK: - Overrides
|
||||||
@ -173,29 +181,61 @@ open class Footnote: View {
|
|||||||
open override func setup() {
|
open override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
|
|
||||||
addSubview(symbolLabel)
|
// add footnote item stackview.
|
||||||
symbolLabel.pinToSuperView()
|
addSubview(itemStackView)
|
||||||
|
itemStackView.pinToSuperView()
|
||||||
|
|
||||||
addSubview(footnoteItemLabel)
|
// add symbol label, text label to stack.
|
||||||
footnoteItemLabel.pinToSuperView()
|
itemStackView.addArrangedSubview(symbolLabel)
|
||||||
|
itemStackView.addArrangedSubview(textLabel)
|
||||||
|
itemStackView.setCustomSpacing(VDSLayout.space1X, after: symbolLabel)
|
||||||
|
|
||||||
|
symbolWidthConstraint = symbolLabel.widthAnchor.constraint(greaterThanOrEqualToConstant: 0)
|
||||||
|
symbolWidthConstraint?.isActive = true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func setDefaults() {
|
open override func setDefaults() {
|
||||||
super.setDefaults()
|
super.setDefaults()
|
||||||
|
hideSymbol = false
|
||||||
|
text = nil
|
||||||
|
tooltipModel = nil
|
||||||
|
width = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resets to default settings.
|
/// Resets to default settings.
|
||||||
open override func reset() {
|
open override func reset() {
|
||||||
|
symbolLabel.reset()
|
||||||
|
textLabel.reset()
|
||||||
super.reset()
|
super.reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used to make changes to the View based off a change events or from local properties.
|
/// Used to make changes to the View based off a change events or from local properties.
|
||||||
open override func updateView() {
|
open override func updateView() {
|
||||||
super.updateView()
|
super.updateView()
|
||||||
|
|
||||||
|
// Update symbolLabel
|
||||||
|
symbolWidthConstraint?.isActive = false
|
||||||
symbolLabel.text = hideSymbol ? "" : symbolType.text
|
symbolLabel.text = hideSymbol ? "" : symbolType.text
|
||||||
footnoteItemLabel.text = text
|
symbolLabel.textColor = kind.colorConfiguration.getColor(self)
|
||||||
|
symbolLabel.textStyle = size.textStyle.regular
|
||||||
symbolLabel.surface = surface
|
symbolLabel.surface = surface
|
||||||
footnoteItemLabel.surface = surface
|
|
||||||
|
// Update symbolLabel width as per updated text size
|
||||||
|
symbolWidthConstraint = symbolLabel.widthAnchor.constraint(equalToConstant: symbolLabel.intrinsicContentSize.width)
|
||||||
|
symbolWidthConstraint?.isActive = true
|
||||||
|
|
||||||
|
// Update textLabel
|
||||||
|
textLabel.text = text
|
||||||
|
textLabel.textColor = kind.colorConfiguration.getColor(self)
|
||||||
|
textLabel.textStyle = size.textStyle.regular
|
||||||
|
textLabel.surface = surface
|
||||||
|
|
||||||
|
// Set the textLabel attributes
|
||||||
|
if let tooltipModel {
|
||||||
|
var attributes: [any LabelAttributeModel] = []
|
||||||
|
attributes.append(TooltipLabelAttribute(surface: surface, model: tooltipModel, presenter: self))
|
||||||
|
textLabel.attributes = attributes
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user