diff --git a/VDS/Components/Notification/Notification.swift b/VDS/Components/Notification/Notification.swift index 9cdba0fb..427b0ed8 100644 --- a/VDS/Components/Notification/Notification.swift +++ b/VDS/Components/Notification/Notification.swift @@ -76,24 +76,40 @@ public class Notification: View { return UIDevice.isIPad ? VDSLayout.Spacing.space5X.value : VDSLayout.Spacing.space4X.value } + private var minViewWidth: CGFloat { + return fullBleed ? 320 : 288 + } + + ///Max view width is for Tablet + private var maxViewWidth: CGFloat { + return fullBleed ? 1272 : 1232 + } + + private var maxWidthConstraint: NSLayoutConstraint? + + open var leadingConstraint: NSLayoutConstraint? + + open var trailingConstraint: NSLayoutConstraint? //-------------------------------------------------- // MARK: - View Properties //-------------------------------------------------- open var typeIcon = Icon().with { $0.name = .infoBold + $0.size = UIDevice.isIPad ? .medium : .small } open var closeButton = Icon().with { $0.name = .close + $0.size = UIDevice.isIPad ? .medium : .small } open var titleLabel = Label().with { - $0.textStyle = .boldBodyLarge + $0.textStyle = UIDevice.isIPad ? .boldBodyLarge : .boldBodySmall } open var subTitleLabel = Label().with { - $0.textStyle = .bodyLarge + $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall } open var buttonsView = ButtonGroup().with { @@ -140,6 +156,8 @@ public class Notification: View { open var type: Style = .info { didSet{didChange()}} + open var fullBleed: Bool = false { didSet {didChange()}} + var _layout: Layout = .vertical open var layout: Layout { set { @@ -194,8 +212,10 @@ public class Notification: View { NSLayoutConstraint.activate([ heightAnchor.constraint(greaterThanOrEqualToConstant: minViewHeight), - mainStackView.heightAnchor.constraint(greaterThanOrEqualToConstant: minContentHeight) + mainStackView.heightAnchor.constraint(greaterThanOrEqualToConstant: minContentHeight), + widthAnchor.constraint(greaterThanOrEqualToConstant: minViewWidth) ]) + maxWidthConstraint = widthAnchor.constraint(lessThanOrEqualToConstant: maxViewWidth) labelButtonView.addArrangedSubview(labelsView) @@ -212,14 +232,24 @@ public class Notification: View { super.reset() titleLabel.reset() + titleLabel.textStyle = .boldBodyLarge + subTitleLabel.reset() + subTitleLabel.textStyle = .bodyLarge + buttonsView.reset() + buttonsView.buttonPosition = .left + primaryButton.reset() secondaryButton.reset() type = .info + typeIcon.size = .medium typeIcon.name = .infoBold + + closeButton.size = .medium closeButton.name = .close + layout = .vertical hideCloseButton = false } @@ -232,6 +262,7 @@ public class Notification: View { updateIcons() updateLabels() updateButtons() + setConstraints() } private func updateIcons() { @@ -293,5 +324,22 @@ public class Notification: View { .pinTrailing() } } + + private func setConstraints() { + + maxWidthConstraint?.constant = maxViewWidth + maxWidthConstraint?.isActive = UIDevice.isIPad + + if leadingConstraint == nil, let superview { + leadingConstraint = NSLayoutConstraint(item: self, attribute: .leading, relatedBy: .equal, toItem: superview, attribute: .leading, multiplier: 1, constant: 0) + } + + if trailingConstraint == nil, let superview { + trailingConstraint = NSLayoutConstraint(item: superview, attribute: .trailing, relatedBy: .equal, toItem: self, attribute: .trailing, multiplier: 1, constant: 0) + } + + leadingConstraint?.isActive = fullBleed + trailingConstraint?.isActive = fullBleed + } }