refactored text into properties
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
d866a4e3c3
commit
05e23f7d58
@ -86,6 +86,16 @@ public class Notification: View {
|
||||
open var buttonsView = ButtonGroup().with {
|
||||
$0.buttonPosition = .left
|
||||
}
|
||||
|
||||
//Text
|
||||
open var titleText: String? { didSet{didChange()}}
|
||||
|
||||
open var subTitleText: String? { didSet{didChange()}}
|
||||
|
||||
//Buttons (will need to think about this one, probably create a model and follow how Tilelet is working)
|
||||
open var primaryButton: Button? { didSet{didChange()}}
|
||||
|
||||
open var secondaryButton: Button? { didSet{didChange()}}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Modal Properties
|
||||
@ -105,17 +115,11 @@ public class Notification: View {
|
||||
return config.eraseToAnyColorable()
|
||||
}()
|
||||
|
||||
private var textColorConfig = ViewColorConfiguration()
|
||||
public func updateTextColorConfig() {
|
||||
textColorConfig.reset()
|
||||
|
||||
switch type {
|
||||
case .info, .success, .warning, .error:
|
||||
textColorConfig.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forDisabled: false)
|
||||
textColorConfig.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forDisabled: true)
|
||||
}
|
||||
private var textColorConfig = ViewColorConfiguration().with {
|
||||
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forDisabled: false)
|
||||
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forDisabled: true)
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
//--------------------------------------------------
|
||||
@ -134,7 +138,7 @@ public class Notification: View {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Lifecycle
|
||||
//--------------------------------------------------
|
||||
|
||||
|
||||
open override func setup() {
|
||||
super.setup()
|
||||
addSubview(mainStackView)
|
||||
@ -148,34 +152,14 @@ public class Notification: View {
|
||||
mainStackView.addArrangedSubview(typeIcon)
|
||||
mainStackView.addArrangedSubview(labelsView)
|
||||
mainStackView.addArrangedSubview(closeButton)
|
||||
|
||||
labelsView.addArrangedSubview(titleLabel)
|
||||
labelsView.addArrangedSubview(subTitleLabel)
|
||||
labelsView.setCustomSpacing(VDSLayout.Spacing.space3X.value, after: subTitleLabel)
|
||||
|
||||
let firstButton = Button().with {
|
||||
$0.text = "Button 1"
|
||||
$0.use = .secondary
|
||||
$0.size = .small
|
||||
}
|
||||
|
||||
firstButton.onClickSubscriber = firstButton.publisher(for: .touchUpInside).sink { button in
|
||||
print("\(button.text) has been pressed")
|
||||
}
|
||||
|
||||
#warning("Upon adding the button into the stack view, button is visible. Where as ButtonGroup with a single button is not rendered")
|
||||
|
||||
///This below doesn't work
|
||||
buttonsView.buttons = [firstButton]
|
||||
labelsView.addArrangedSubview(buttonsView)
|
||||
|
||||
///This below works
|
||||
//labelsView.addArrangedSubview(firstButton)
|
||||
|
||||
|
||||
closeButton.publisher(for: UITapGestureRecognizer()).sink { [weak self] _ in
|
||||
self?.didClickOnCloseButton()
|
||||
}.store(in: &subscribers)
|
||||
|
||||
//labels
|
||||
titleLabel.textColorConfiguration = textColorConfig.eraseToAnyColorable()
|
||||
subTitleLabel.textColorConfiguration = textColorConfig.eraseToAnyColorable()
|
||||
}
|
||||
|
||||
open override func reset() {
|
||||
@ -183,25 +167,72 @@ public class Notification: View {
|
||||
type = .info
|
||||
typeIcon.name = .infoBold
|
||||
closeButton.name = .close
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - State
|
||||
//--------------------------------------------------
|
||||
open override func updateView() {
|
||||
updateTextColorConfig()
|
||||
|
||||
backgroundColor = backgroundColorConfiguration.getColor(self)
|
||||
updateIcons()
|
||||
updateLabels()
|
||||
updateButtons()
|
||||
}
|
||||
|
||||
private func updateIcons() {
|
||||
let iconColor = surface == .dark ? Icon.Color.white : Icon.Color.black
|
||||
typeIcon.name = type.styleIconName()
|
||||
typeIcon.color = surface == .dark ? Icon.Color.white : Icon.Color.black
|
||||
closeButton.color = surface == .dark ? Icon.Color.white : Icon.Color.black
|
||||
titleLabel.textColorConfiguration = textColorConfig.eraseToAnyColorable()
|
||||
subTitleLabel.textColorConfiguration = textColorConfig.eraseToAnyColorable()
|
||||
|
||||
typeIcon.color = iconColor
|
||||
closeButton.color = iconColor
|
||||
}
|
||||
|
||||
private func updateLabels() {
|
||||
titleLabel.surface = surface
|
||||
subTitleLabel.surface = surface
|
||||
|
||||
if let titleText {
|
||||
titleLabel.text = titleText
|
||||
labelsView.addArrangedSubview(titleLabel)
|
||||
} else {
|
||||
titleLabel.removeFromSuperview()
|
||||
}
|
||||
|
||||
if let subTitleText {
|
||||
subTitleLabel.text = subTitleText
|
||||
labelsView.addArrangedSubview(subTitleLabel)
|
||||
} else {
|
||||
subTitleLabel.removeFromSuperview()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private func updateButtons() {
|
||||
var buttons: [Button] = []
|
||||
if let primaryButton {
|
||||
primaryButton.size = .small
|
||||
primaryButton.use = .primary
|
||||
buttons.append(primaryButton)
|
||||
}
|
||||
|
||||
if let secondaryButton {
|
||||
secondaryButton.size = .small
|
||||
secondaryButton.use = .secondary
|
||||
buttons.append(secondaryButton)
|
||||
}
|
||||
|
||||
if buttons.isEmpty {
|
||||
labelsView.setCustomSpacing(0, after: subTitleLabel)
|
||||
buttonsView.removeFromSuperview()
|
||||
} else {
|
||||
labelsView.setCustomSpacing(VDSLayout.Spacing.space3X.value, after: subTitleLabel)
|
||||
///This below doesn't work
|
||||
buttonsView.buttons = buttons
|
||||
labelsView.addArrangedSubview(buttonsView)
|
||||
|
||||
buttonsView
|
||||
.pinLeading()
|
||||
.pinTrailing()
|
||||
}
|
||||
}
|
||||
|
||||
func didClickOnCloseButton() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user