refactored stackview and added in badge

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-01-06 11:40:19 -06:00
parent 2f603b1a64
commit f868312b1f

View File

@ -10,31 +10,6 @@ import Foundation
import VDSColorTokens import VDSColorTokens
import UIKit import UIKit
public enum TiletTitleTypographicalStyle: String, Codable, EnumSubset {
case TitleXLarge
case BoldTitleXLarge
case TitleLarge
case BoldTitleLarge
case TitleMedium
case BoldTitleMedium
case TitleSmall
case BoldTitleSmall
public var defaultValue: TitleLockupTitleTypographicalStyle { .BoldTitleSmall }
}
public enum TiletOtherTypographicalStyle: String, Codable, EnumSubset {
case BodyLarge
case BoldBodyLarge
case BodyMedium
case BoldBodyMedium
case BodySmall
case BoldBodySmall
public var defaultValue: TitleLockupOtherTypographicalStyle { .BodySmall }
}
@objc(VDSTilet) @objc(VDSTilet)
open class Tilet: TileContainer { open class Tilet: TileContainer {
@ -58,6 +33,17 @@ open class Tilet: TileContainer {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Properties // MARK: - Private Properties
//-------------------------------------------------- //--------------------------------------------------
private var stackView = UIStackView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.axis = .vertical
$0.distribution = .fill
$0.spacing = 5
}
private var titleLockupContainerView = UIView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
}
private var titleLockup = TitleLockup().with { private var titleLockup = TitleLockup().with {
let configs = [ let configs = [
TypographicalStyleDeviceSpacingConfig([.TitleSmall, .BoldTitleSmall], TypographicalStyleDeviceSpacingConfig([.TitleSmall, .BoldTitleSmall],
@ -120,14 +106,18 @@ open class Tilet: TileContainer {
$0.bottomTypographicalStyleSpacingConfig = TypographicalStyleSpacingConfig(configs: configs) $0.bottomTypographicalStyleSpacingConfig = TypographicalStyleSpacingConfig(configs: configs)
} }
private var badgeContainerView = UIView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
}
private var badge = Badge().with {
$0.fillColor = .red
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Public Properties // MARK: - Public Properties
//-------------------------------------------------- //--------------------------------------------------
//style //style
open var titleTypograpicalStyle: TiletTitleTypographicalStyle = .BoldTitleSmall { didSet { didChange() }}
open var otherTypograpicalStyle: TiletOtherTypographicalStyle = .BodySmall { didSet { didChange() }}
private var _textWidth: CGFloat? private var _textWidth: CGFloat?
open var textWidth: CGFloat? { open var textWidth: CGFloat? {
get { _textWidth } get { _textWidth }
@ -161,12 +151,11 @@ open class Tilet: TileContainer {
} }
} }
//badge public var badgeModel: TiletBadgeModel? { didSet { didChange() }}
open var showBadge: Bool = false { didSet { didChange() }}
open var badgeText: String = "" { didSet { didChange() }}
open var badgeColor: BadgeFillColor = .red { didSet { didChange() }}
//text //text
open var titleTypograpicalStyle: TiletTitleTypographicalStyle = .BoldTitleSmall { didSet { didChange() }}
open var otherTypograpicalStyle: TiletOtherTypographicalStyle = .BodySmall { didSet { didChange() }}
open var titleText: String = "" { didSet { didChange() }} open var titleText: String = "" { didSet { didChange() }}
open var titleTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} open var titleTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }}
open var subTitleText: String = "" { didSet { didChange() }} open var subTitleText: String = "" { didSet { didChange() }}
@ -192,14 +181,27 @@ open class Tilet: TileContainer {
aspectRatio = .none aspectRatio = .none
containerBackgroundColor = .black containerBackgroundColor = .black
addContentView(titleLockup, shouldPin: false) addContentView(stackView)
titleLockup.pinTop()
titleLockup.pinLeading()
titleLockup.bottomAnchor.constraint(lessThanOrEqualTo: containerView.bottomAnchor).isActive = true
//either you are 100% width of the tileContainer.contentView //badge
titleLockupTrailingConstraint = titleLockup.trailingAnchor.constraint(equalTo: containerView.trailingAnchor) badgeContainerView.addSubview(badge)
badge
.pinTop()
.pinLeading()
.pinBottom()
badge.trailingAnchor.constraint(lessThanOrEqualTo: badgeContainerView.trailingAnchor).isActive = true
titleLockupContainerView.addSubview(titleLockup)
titleLockup
.pinTop()
.pinLeading()
.pinBottom()
titleLockupTrailingConstraint = titleLockup.trailingAnchor.constraint(equalTo: titleLockupContainerView.trailingAnchor)
titleLockupTrailingConstraint?.isActive = true titleLockupTrailingConstraint?.isActive = true
//stackView.addArrangedSubview(badgeContainerView)
//stackView.addArrangedSubview(titleLockupContainerView)
} }
public override func reset() { public override func reset() {
@ -208,8 +210,12 @@ open class Tilet: TileContainer {
surface = .light surface = .light
containerBackgroundColor = .black containerBackgroundColor = .black
titleLockup.reset() //badge
badge.reset()
badgeModel = nil
//titleLockup
titleLockup.reset()
titleText = "" titleText = ""
titleTextAttributes = nil titleTextAttributes = nil
subTitleText = "" subTitleText = ""
@ -225,10 +231,27 @@ open class Tilet: TileContainer {
super.updateView() super.updateView()
//flip the surface for the titleLockup //flip the surface for the titleLockup
let flippedSurface: Surface = containerBackgroundColor == .black ? .dark : .light let titleLockupSurface: Surface = containerBackgroundColor == .black ? .dark : .light
titleLockup.surface = flippedSurface titleLockup.surface = titleLockupSurface
//either use textWidth //update constraints
//badge
if let badgeModel {
if badgeContainerView.superview == nil {
stackView.insertArrangedSubview(badgeContainerView, at: 0)
}
badge.set(with: badgeModel)
} else {
badgeContainerView.removeFromSuperview()
}
if !titleText.isEmpty || !subTitleText.isEmpty {
if titleLockupContainerView.superview == nil {
stackView.insertArrangedSubview(titleLockupContainerView, at: badgeContainerView.superview == nil ? 0 : 1)
}
//titleLockup
if let textWidth { if let textWidth {
titleLockupTrailingConstraint?.isActive = false titleLockupTrailingConstraint?.isActive = false
titleLockupWidthConstraint?.isActive = false titleLockupWidthConstraint?.isActive = false
@ -250,7 +273,6 @@ open class Tilet: TileContainer {
} else { } else {
titleLockupWidthConstraint?.isActive = false titleLockupWidthConstraint?.isActive = false
titleLockupTrailingConstraint?.isActive = true titleLockupTrailingConstraint?.isActive = true
} }
titleLockup.titleText = titleText titleLockup.titleText = titleText
@ -261,6 +283,10 @@ open class Tilet: TileContainer {
titleLockup.otherTypograpicalStyle = otherTypograpicalStyle.value titleLockup.otherTypograpicalStyle = otherTypograpicalStyle.value
titleLockup.subTitleTextAttributes = titleTextAttributes titleLockup.subTitleTextAttributes = titleTextAttributes
titleLockup.subTitleColor = subTitleColor titleLockup.subTitleColor = subTitleColor
} else {
titleLockupContainerView.removeFromSuperview()
}
} }
} }