From 8fd74d5ef9ee01dba35b407dc866d69bcdd1b7e5 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 14 Feb 2024 11:57:08 -0600 Subject: [PATCH] refactored ExpandDirect to the BadgeIndicatorModel Signed-off-by: Matt Bruce --- .../Icon/ButtonIcon/ButtonIcon.swift | 57 +++++++++---------- .../ButtonIconBadgeIndicatorModel.swift | 16 ++++-- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift b/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift index a26765e6..05b41224 100644 --- a/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift +++ b/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift @@ -43,12 +43,7 @@ open class ButtonIcon: Control, Changeable, FormFieldable { public enum SurfaceType: String, CaseIterable { case colorFill, media } - - /// Enum used to describe the badge indicator direction of icon button determining the expand direction. - public enum ExpandDirection: String, CaseIterable { - case right, center, left - } - + /// Enum used to describe the size of button icon. public enum Size: String, EnumSubset { case large @@ -106,6 +101,7 @@ open class ButtonIcon: Control, Changeable, FormFieldable { open var badgeIndicator = BadgeIndicator().with { $0.translatesAutoresizingMaskIntoConstraints = false $0.size = .small + $0.isHidden = true } /// If set, this is used to render the badge indicator. @@ -157,10 +153,7 @@ open class ButtonIcon: Control, Changeable, FormFieldable { /// Used to move the icon inside the button in both x and y axis. open var iconOffset: CGPoint = .init(x: 0, y: 0) { didSet { setNeedsUpdate() } } - - /// Applies expand direction to Badge Indicator if shows badge indicator. - open var expandDirection: ExpandDirection = .right { didSet { setNeedsUpdate() } } - + open var onChangeSubscriber: AnyCancellable? open var inputId: String? { didSet { setNeedsUpdate() } } @@ -203,7 +196,6 @@ open class ButtonIcon: Control, Changeable, FormFieldable { $0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted) $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled) $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .selected) - $0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: [.selected, .highlighted]) $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) }.eraseToAnyColorable() }() @@ -374,7 +366,7 @@ open class ButtonIcon: Control, Changeable, FormFieldable { super.initialSetup() onClick = { control in guard control.isEnabled else { return } - if let selectedIconName = control.selectedIconName, control.selectable { + if control.selectedIconName != nil && control.selectable { control.toggle() } } @@ -402,7 +394,6 @@ open class ButtonIcon: Control, Changeable, FormFieldable { showBadgeIndicator = false selectable = false badgeIndicatorModel = nil - expandDirection = .right shouldUpdateView = true setNeedsUpdate() } @@ -482,27 +473,33 @@ open class ButtonIcon: Control, Changeable, FormFieldable { // MARK: - Private Methods //-------------------------------------------------- private func updateBadgeIndicator() { - if let badgeIndicatorModel { - badgeIndicator.kind = badgeIndicatorModel.kind - badgeIndicator.fillColor = badgeIndicatorModel.fillColor - badgeIndicator.surface = badgeIndicatorModel.surface - badgeIndicator.size = badgeIndicatorModel.size - badgeIndicator.maximumDigits = badgeIndicatorModel.maximumDigits - badgeIndicator.width = badgeIndicatorModel.width - badgeIndicator.height = badgeIndicatorModel.height - badgeIndicator.number = badgeIndicatorModel.number - badgeIndicator.leadingCharacter = badgeIndicatorModel.leadingCharacter - badgeIndicator.trailingText = badgeIndicatorModel.trailingText - badgeIndicator.dotSize = badgeIndicatorModel.dotSize - badgeIndicator.verticalPadding = badgeIndicatorModel.verticalPadding - badgeIndicator.horizontalPadding = badgeIndicatorModel.horizontalPadding - badgeIndicator.hideDot = badgeIndicatorModel.hideDot - badgeIndicator.hideBorder = badgeIndicatorModel.hideBorder + badgeIndicator.isHidden = !showBadgeIndicator + + guard let badgeIndicatorModel else { + badgeIndicator.isHidden = true + return } + + badgeIndicator.surface = surface + badgeIndicator.kind = badgeIndicatorModel.kind + badgeIndicator.fillColor = badgeIndicatorModel.fillColor + badgeIndicator.size = badgeIndicatorModel.size + badgeIndicator.maximumDigits = badgeIndicatorModel.maximumDigits + badgeIndicator.width = badgeIndicatorModel.width + badgeIndicator.height = badgeIndicatorModel.height + badgeIndicator.number = badgeIndicatorModel.number + badgeIndicator.leadingCharacter = badgeIndicatorModel.leadingCharacter + badgeIndicator.trailingText = badgeIndicatorModel.trailingText + badgeIndicator.dotSize = badgeIndicatorModel.dotSize + badgeIndicator.verticalPadding = badgeIndicatorModel.verticalPadding + badgeIndicator.horizontalPadding = badgeIndicatorModel.horizontalPadding + badgeIndicator.hideDot = badgeIndicatorModel.hideDot + badgeIndicator.hideBorder = badgeIndicatorModel.hideBorder } private func updateExpandDirectionalConstraints() { - switch expandDirection { + guard let badgeIndicatorModel else { return } + switch badgeIndicatorModel.expandDirection { case .right: badgeIndicatorLeadingConstraint?.isActive = true badgeIndicatorTrailingConstraint?.isActive = false diff --git a/VDS/Components/Icon/ButtonIcon/ButtonIconBadgeIndicatorModel.swift b/VDS/Components/Icon/ButtonIcon/ButtonIconBadgeIndicatorModel.swift index b30e64e8..61b94c12 100644 --- a/VDS/Components/Icon/ButtonIcon/ButtonIconBadgeIndicatorModel.swift +++ b/VDS/Components/Icon/ButtonIcon/ButtonIconBadgeIndicatorModel.swift @@ -11,16 +11,20 @@ extension ButtonIcon { //Model that represents the options available for the Badge Indicator public struct BadgeIndicatorModel { + /// Enum used to describe the badge indicator direction of icon button determining the expand direction. + public enum ExpandDirection: String, CaseIterable { + case right, center, left + } + + /// Applies expand direction to Badge Indicator if shows badge indicator. + public var expandDirection: ExpandDirection = .right /// Kind that will be used for the badge indicator. public var kind: BadgeIndicator.Kind /// Fill color that will be used for the badge indicator. public var fillColor: BadgeIndicator.FillColor - - /// Current Surface and this is used to pass down to child objects that implement Surfacable - public var surface: Surface - + /// Size that will be used for the badge indicator. public var size: BadgeIndicator.Size @@ -57,10 +61,10 @@ extension ButtonIcon { /// Hide Border that will be used for the badge indicator. public var hideBorder: Bool = false - public init(kind: BadgeIndicator.Kind = .simple, fillColor: BadgeIndicator.FillColor = .red, surface: Surface = .light, size: BadgeIndicator.Size = .xxlarge, maximumDigits: BadgeIndicator.MaximumDigits = .two, width: CGFloat? = nil, height: CGFloat? = nil, number: Int? = nil, leadingCharacter: String = "", trailingText: String = "", dotSize: CGFloat? = nil, verticalPadding: CGFloat? = nil, horizontalPadding: CGFloat? = nil, hideDot: Bool = false, hideBorder: Bool = false) { + public init(kind: BadgeIndicator.Kind = .simple, fillColor: BadgeIndicator.FillColor = .red, expandDirection: ExpandDirection = .right, size: BadgeIndicator.Size = .xxlarge, maximumDigits: BadgeIndicator.MaximumDigits = .two, width: CGFloat? = nil, height: CGFloat? = nil, number: Int? = nil, leadingCharacter: String = "", trailingText: String = "", dotSize: CGFloat? = nil, verticalPadding: CGFloat? = nil, horizontalPadding: CGFloat? = nil, hideDot: Bool = false, hideBorder: Bool = false) { self.kind = kind self.fillColor = fillColor - self.surface = surface + self.expandDirection = expandDirection self.size = size self.maximumDigits = maximumDigits self.width = width