story:ONEAPP-6315: using struct to set badge indicator properties

This commit is contained in:
vasavk 2024-02-08 13:19:47 +05:30
parent 95d638ebf4
commit 206cbf04e4
3 changed files with 113 additions and 3 deletions

View File

@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
18792A902B7431F2008C0D29 /* ButtonIconBadgeIndicatorModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18792A8F2B7431F2008C0D29 /* ButtonIconBadgeIndicatorModel.swift */; };
445BA07829C07B3D0036A7C5 /* Notification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 445BA07729C07B3D0036A7C5 /* Notification.swift */; };
44604AD429CE186A00E62B51 /* NotificationButtonModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44604AD329CE186A00E62B51 /* NotificationButtonModel.swift */; };
44604AD729CE196600E62B51 /* Line.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44604AD629CE196600E62B51 /* Line.swift */; };
@ -168,6 +169,7 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
18792A8F2B7431F2008C0D29 /* ButtonIconBadgeIndicatorModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonIconBadgeIndicatorModel.swift; sourceTree = "<group>"; };
445BA07729C07B3D0036A7C5 /* Notification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notification.swift; sourceTree = "<group>"; };
44604AD329CE186A00E62B51 /* NotificationButtonModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationButtonModel.swift; sourceTree = "<group>"; };
44604AD629CE196600E62B51 /* Line.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Line.swift; sourceTree = "<group>"; };
@ -671,6 +673,7 @@
isa = PBXGroup;
children = (
EA81410A2A0E8E3C004F60D2 /* ButtonIcon.swift */,
18792A8F2B7431F2008C0D29 /* ButtonIconBadgeIndicatorModel.swift */,
);
path = ButtonIcon;
sourceTree = "<group>";
@ -1060,6 +1063,7 @@
EA5E30532950DDA60082B959 /* TitleLockup.swift in Sources */,
EAD062B02A3B873E0015965D /* BadgeIndicator.swift in Sources */,
EAA5EEB528ECBFB4003B3210 /* ImageLabelAttribute.swift in Sources */,
18792A902B7431F2008C0D29 /* ButtonIconBadgeIndicatorModel.swift in Sources */,
EA0B18062A9E2D2D00F2D0CD /* SelectorItemBase.swift in Sources */,
EAB5FF0129424ACB00998C17 /* UIControl.swift in Sources */,
EA985BF5296C60C000F2FF2E /* Icon.swift in Sources */,

View File

@ -99,14 +99,15 @@ open class ButtonIcon: Control {
// MARK: - Public Properties
//--------------------------------------------------
///BadgeIndicator object used to render for the ButtonIcon.
///Badge Indicator object used to render for the ButtonIcon.
open var badgeIndicator = BadgeIndicator().with {
$0.translatesAutoresizingMaskIntoConstraints = false
// $0.hideBorder = true
// $0.borderWidth = 0
$0.size = .small
}
/// If set, this is used to render the badge indicator.
open var badgeIndicatorModel: BadgeIndicatorModel? { didSet { setNeedsUpdate() } }
/// Icon object used to render out the Icon for this ButtonIcon.
open var icon = Icon().with { $0.isUserInteractionEnabled = false }
@ -305,6 +306,8 @@ open class ButtonIcon: Control {
//add the icon
addSubview(icon)
//add badgeIndicator
addSubview(badgeIndicator)
badgeIndicator.isHidden = !showBadge
@ -343,6 +346,7 @@ open class ButtonIcon: Control {
// selectableIconName = nil
showBadge = false
selectable = false
badgeIndicatorModel = nil
shouldUpdateView = true
setNeedsUpdate()
}
@ -361,6 +365,7 @@ open class ButtonIcon: Control {
} else {
icon.reset()
}
updateBadgeIndicator()
badgeIndicatorLeadingConstraint?.constant = badgeIndicatorOffset.x
badgeIndicatorBottomConstraint?.constant = badgeIndicatorOffset.y
setNeedsLayout()
@ -410,6 +415,29 @@ open class ButtonIcon: Control {
}
}
//--------------------------------------------------
// 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
}
}
}
// MARK: AppleGuidelinesTouchable

View File

@ -0,0 +1,78 @@
//
// ButtonIconBadgeIndicatorModel.swift
// VDS
//
// Created by Kanamarlapudi, Vasavi on 08/02/24.
//
import Foundation
extension ButtonIcon {
//Model that represents the options available for the Badge Indicator
public struct BadgeIndicatorModel {
/// 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
/// Number of digits that will be used for the badge indicator.
public var maximumDigits: BadgeIndicator.MaximumDigits
/// Max width that will be used for the badge indicator.
public var width: CGFloat?
/// Max height that will be used for the badge indicator.
public var height: CGFloat?
/// Number that will be used for the badge indicator.
public var number: Int?
/// Leading Character that will be used for the badge indicator.
public var leadingCharacter: String?
/// Trailing Text height that will be used for the badge indicator.
public var trailingText: String?
/// Dot Size that will be used for the badge indicator.
public var dotSize: CGFloat?
/// Vertical Padding that will be used for the badge indicator.
public var verticalPadding: CGFloat?
/// Horizontal Padding that will be used for the badge indicator.
public var horizontalPadding: CGFloat?
/// Hide Dot that will be used for the badge indicator.
public var hideDot: Bool = false
/// 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) {
self.kind = kind
self.fillColor = fillColor
self.surface = surface
self.size = size
self.maximumDigits = maximumDigits
self.width = width
self.height = height
self.number = number
self.leadingCharacter = leadingCharacter
self.trailingText = trailingText
self.dotSize = dotSize
self.verticalPadding = verticalPadding
self.horizontalPadding = horizontalPadding
self.hideDot = hideDot
self.hideBorder = hideBorder
}
}
}