Notification, default setting changes & fullBleed changes

This commit is contained in:
Sumanth Nadigadda 2023-04-04 16:25:48 +05:30
parent fc02175c5d
commit 027fabae12

View File

@ -76,24 +76,40 @@ public class Notification: View {
return UIDevice.isIPad ? VDSLayout.Spacing.space5X.value : VDSLayout.Spacing.space4X.value 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 // MARK: - View Properties
//-------------------------------------------------- //--------------------------------------------------
open var typeIcon = Icon().with { open var typeIcon = Icon().with {
$0.name = .infoBold $0.name = .infoBold
$0.size = UIDevice.isIPad ? .medium : .small
} }
open var closeButton = Icon().with { open var closeButton = Icon().with {
$0.name = .close $0.name = .close
$0.size = UIDevice.isIPad ? .medium : .small
} }
open var titleLabel = Label().with { open var titleLabel = Label().with {
$0.textStyle = .boldBodyLarge $0.textStyle = UIDevice.isIPad ? .boldBodyLarge : .boldBodySmall
} }
open var subTitleLabel = Label().with { open var subTitleLabel = Label().with {
$0.textStyle = .bodyLarge $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall
} }
open var buttonsView = ButtonGroup().with { open var buttonsView = ButtonGroup().with {
@ -140,6 +156,8 @@ public class Notification: View {
open var type: Style = .info { didSet{didChange()}} open var type: Style = .info { didSet{didChange()}}
open var fullBleed: Bool = false { didSet {didChange()}}
var _layout: Layout = .vertical var _layout: Layout = .vertical
open var layout: Layout { open var layout: Layout {
set { set {
@ -194,8 +212,10 @@ public class Notification: View {
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
heightAnchor.constraint(greaterThanOrEqualToConstant: minViewHeight), 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) labelButtonView.addArrangedSubview(labelsView)
@ -212,14 +232,24 @@ public class Notification: View {
super.reset() super.reset()
titleLabel.reset() titleLabel.reset()
titleLabel.textStyle = .boldBodyLarge
subTitleLabel.reset() subTitleLabel.reset()
subTitleLabel.textStyle = .bodyLarge
buttonsView.reset() buttonsView.reset()
buttonsView.buttonPosition = .left
primaryButton.reset() primaryButton.reset()
secondaryButton.reset() secondaryButton.reset()
type = .info type = .info
typeIcon.size = .medium
typeIcon.name = .infoBold typeIcon.name = .infoBold
closeButton.size = .medium
closeButton.name = .close closeButton.name = .close
layout = .vertical layout = .vertical
hideCloseButton = false hideCloseButton = false
} }
@ -232,6 +262,7 @@ public class Notification: View {
updateIcons() updateIcons()
updateLabels() updateLabels()
updateButtons() updateButtons()
setConstraints()
} }
private func updateIcons() { private func updateIcons() {
@ -293,5 +324,22 @@ public class Notification: View {
.pinTrailing() .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
}
} }