refactored stackview and added in badge
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
2f603b1a64
commit
f868312b1f
@ -10,31 +10,6 @@ import Foundation
|
||||
import VDSColorTokens
|
||||
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)
|
||||
open class Tilet: TileContainer {
|
||||
|
||||
@ -58,6 +33,17 @@ open class Tilet: TileContainer {
|
||||
//--------------------------------------------------
|
||||
// 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 {
|
||||
let configs = [
|
||||
TypographicalStyleDeviceSpacingConfig([.TitleSmall, .BoldTitleSmall],
|
||||
@ -120,14 +106,18 @@ open class Tilet: TileContainer {
|
||||
$0.bottomTypographicalStyleSpacingConfig = TypographicalStyleSpacingConfig(configs: configs)
|
||||
}
|
||||
|
||||
private var badgeContainerView = UIView().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
}
|
||||
|
||||
private var badge = Badge().with {
|
||||
$0.fillColor = .red
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Properties
|
||||
//--------------------------------------------------
|
||||
//style
|
||||
open var titleTypograpicalStyle: TiletTitleTypographicalStyle = .BoldTitleSmall { didSet { didChange() }}
|
||||
open var otherTypograpicalStyle: TiletOtherTypographicalStyle = .BodySmall { didSet { didChange() }}
|
||||
|
||||
private var _textWidth: CGFloat?
|
||||
open var textWidth: CGFloat? {
|
||||
get { _textWidth }
|
||||
@ -161,12 +151,11 @@ open class Tilet: TileContainer {
|
||||
}
|
||||
}
|
||||
|
||||
//badge
|
||||
open var showBadge: Bool = false { didSet { didChange() }}
|
||||
open var badgeText: String = "" { didSet { didChange() }}
|
||||
open var badgeColor: BadgeFillColor = .red { didSet { didChange() }}
|
||||
public var badgeModel: TiletBadgeModel? { didSet { didChange() }}
|
||||
|
||||
//text
|
||||
open var titleTypograpicalStyle: TiletTitleTypographicalStyle = .BoldTitleSmall { didSet { didChange() }}
|
||||
open var otherTypograpicalStyle: TiletOtherTypographicalStyle = .BodySmall { didSet { didChange() }}
|
||||
open var titleText: String = "" { didSet { didChange() }}
|
||||
open var titleTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }}
|
||||
open var subTitleText: String = "" { didSet { didChange() }}
|
||||
@ -192,14 +181,27 @@ open class Tilet: TileContainer {
|
||||
aspectRatio = .none
|
||||
containerBackgroundColor = .black
|
||||
|
||||
addContentView(titleLockup, shouldPin: false)
|
||||
titleLockup.pinTop()
|
||||
titleLockup.pinLeading()
|
||||
titleLockup.bottomAnchor.constraint(lessThanOrEqualTo: containerView.bottomAnchor).isActive = true
|
||||
addContentView(stackView)
|
||||
|
||||
//either you are 100% width of the tileContainer.contentView
|
||||
titleLockupTrailingConstraint = titleLockup.trailingAnchor.constraint(equalTo: containerView.trailingAnchor)
|
||||
//badge
|
||||
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
|
||||
|
||||
//stackView.addArrangedSubview(badgeContainerView)
|
||||
//stackView.addArrangedSubview(titleLockupContainerView)
|
||||
|
||||
}
|
||||
|
||||
public override func reset() {
|
||||
@ -208,8 +210,12 @@ open class Tilet: TileContainer {
|
||||
surface = .light
|
||||
containerBackgroundColor = .black
|
||||
|
||||
titleLockup.reset()
|
||||
//badge
|
||||
badge.reset()
|
||||
badgeModel = nil
|
||||
|
||||
//titleLockup
|
||||
titleLockup.reset()
|
||||
titleText = ""
|
||||
titleTextAttributes = nil
|
||||
subTitleText = ""
|
||||
@ -225,10 +231,27 @@ open class Tilet: TileContainer {
|
||||
super.updateView()
|
||||
|
||||
//flip the surface for the titleLockup
|
||||
let flippedSurface: Surface = containerBackgroundColor == .black ? .dark : .light
|
||||
titleLockup.surface = flippedSurface
|
||||
let titleLockupSurface: Surface = containerBackgroundColor == .black ? .dark : .light
|
||||
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 {
|
||||
titleLockupTrailingConstraint?.isActive = false
|
||||
titleLockupWidthConstraint?.isActive = false
|
||||
@ -250,7 +273,6 @@ open class Tilet: TileContainer {
|
||||
} else {
|
||||
titleLockupWidthConstraint?.isActive = false
|
||||
titleLockupTrailingConstraint?.isActive = true
|
||||
|
||||
}
|
||||
|
||||
titleLockup.titleText = titleText
|
||||
@ -261,6 +283,10 @@ open class Tilet: TileContainer {
|
||||
titleLockup.otherTypograpicalStyle = otherTypograpicalStyle.value
|
||||
titleLockup.subTitleTextAttributes = titleTextAttributes
|
||||
titleLockup.subTitleColor = subTitleColor
|
||||
|
||||
} else {
|
||||
titleLockupContainerView.removeFromSuperview()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user