diff --git a/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift b/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift index 5e1e792e..19b78e6f 100644 --- a/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift +++ b/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift @@ -73,7 +73,9 @@ open class ButtonIcon: Control { private var layoutGuideWidthConstraint: NSLayoutConstraint? private var layoutGuideHeightConstraint: NSLayoutConstraint? private var badgeIndicatorLeadingConstraint: NSLayoutConstraint? - private var badgeIndicatorBottomConstraint: NSLayoutConstraint? + private var badgeIndicatorTrailingConstraint: NSLayoutConstraint? + private var badgeIndicatorCenterXConstraint: NSLayoutConstraint? + private var badgeIndicatorCenterYConstraint: NSLayoutConstraint? private var currentIconName: Icon.Name? { if let selectedIconName, selectable { return selectedIconName @@ -295,7 +297,9 @@ open class ButtonIcon: Control { var shadowOffset: CGSize = .init(width: 0, height: 2) var shadowRadius: CGFloat = 6 } - + + private var badgeIndicatorDefaultSize: CGSize = .zero + //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- @@ -313,13 +317,17 @@ open class ButtonIcon: Control { //add badgeIndicator addSubview(badgeIndicator) badgeIndicator.isHidden = !showBadgeIndicator - + badgeIndicatorDefaultSize = badgeIndicator.frame.size + //determines the height/width of the icon layoutGuideWidthConstraint = iconLayoutGuide.width(constant: size.containerSize) layoutGuideHeightConstraint = iconLayoutGuide.height(constant: size.containerSize) - badgeIndicatorBottomConstraint = icon.centerYAnchor.constraint(equalTo: badgeIndicator.bottomAnchor) badgeIndicatorLeadingConstraint = badgeIndicator.leadingAnchor.constraint(equalTo: icon.centerXAnchor) - badgeIndicatorBottomConstraint?.isActive = true + badgeIndicatorTrailingConstraint = badgeIndicator.trailingAnchor.constraint(equalTo: icon.centerXAnchor) + badgeIndicatorCenterXConstraint = badgeIndicator.centerXAnchor.constraint(equalTo: icon.centerXAnchor) + badgeIndicatorCenterYConstraint = icon.centerYAnchor.constraint(equalTo: badgeIndicator.centerYAnchor) + badgeIndicatorCenterYConstraint?.isActive = true + badgeIndicatorLeadingConstraint?.isActive = true //pin layout guide iconLayoutGuide @@ -370,8 +378,6 @@ open class ButtonIcon: Control { icon.reset() } updateBadgeIndicator() - badgeIndicatorLeadingConstraint?.constant = badgeIndicatorOffset.x - badgeIndicatorBottomConstraint?.constant = badgeIndicatorOffset.y setNeedsLayout() } @@ -417,7 +423,12 @@ open class ButtonIcon: Control { } else { removeDropShadow() } - + + badgeIndicatorCenterXConstraint?.constant = badgeIndicatorOffset.x + badgeIndicatorDefaultSize.width/2 + badgeIndicatorCenterYConstraint?.constant = badgeIndicatorOffset.y + badgeIndicatorDefaultSize.height/2 + badgeIndicatorLeadingConstraint?.constant = badgeIndicatorOffset.x + badgeIndicatorTrailingConstraint?.constant = badgeIndicatorOffset.x + badgeIndicatorDefaultSize.width + if showBadgeIndicator { updateExpandDirectionalConstraints() } @@ -447,12 +458,19 @@ open class ButtonIcon: Control { } private func updateExpandDirectionalConstraints() { - if expandDirection == .right { - print("expandDirection -> Right") - } else if expandDirection == .center { - print("expandDirection -> center") - } else if expandDirection == .left { - print("expandDirection -> left") + switch expandDirection { + case .right: + badgeIndicatorLeadingConstraint?.isActive = true + badgeIndicatorTrailingConstraint?.isActive = false + badgeIndicatorCenterXConstraint?.isActive = false + case .center: + badgeIndicatorLeadingConstraint?.isActive = false + badgeIndicatorTrailingConstraint?.isActive = false + badgeIndicatorCenterXConstraint?.isActive = true + case .left: + badgeIndicatorLeadingConstraint?.isActive = false + badgeIndicatorCenterXConstraint?.isActive = false + badgeIndicatorTrailingConstraint?.isActive = true } } }