refactored text into properties

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-03-17 15:36:06 -05:00
parent d866a4e3c3
commit 05e23f7d58

View File

@ -86,6 +86,16 @@ public class Notification: View {
open var buttonsView = ButtonGroup().with { open var buttonsView = ButtonGroup().with {
$0.buttonPosition = .left $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 // MARK: - Modal Properties
@ -105,17 +115,11 @@ public class Notification: View {
return config.eraseToAnyColorable() return config.eraseToAnyColorable()
}() }()
private var textColorConfig = ViewColorConfiguration() private var textColorConfig = ViewColorConfiguration().with {
public func updateTextColorConfig() { $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forDisabled: false)
textColorConfig.reset() $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forDisabled: true)
switch type {
case .info, .success, .warning, .error:
textColorConfig.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forDisabled: false)
textColorConfig.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forDisabled: true)
}
} }
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializers // MARK: - Initializers
//-------------------------------------------------- //--------------------------------------------------
@ -134,7 +138,7 @@ public class Notification: View {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Lifecycle // MARK: - Lifecycle
//-------------------------------------------------- //--------------------------------------------------
open override func setup() { open override func setup() {
super.setup() super.setup()
addSubview(mainStackView) addSubview(mainStackView)
@ -148,34 +152,14 @@ public class Notification: View {
mainStackView.addArrangedSubview(typeIcon) mainStackView.addArrangedSubview(typeIcon)
mainStackView.addArrangedSubview(labelsView) mainStackView.addArrangedSubview(labelsView)
mainStackView.addArrangedSubview(closeButton) 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 closeButton.publisher(for: UITapGestureRecognizer()).sink { [weak self] _ in
self?.didClickOnCloseButton() self?.didClickOnCloseButton()
}.store(in: &subscribers) }.store(in: &subscribers)
//labels
titleLabel.textColorConfiguration = textColorConfig.eraseToAnyColorable()
subTitleLabel.textColorConfiguration = textColorConfig.eraseToAnyColorable()
} }
open override func reset() { open override func reset() {
@ -183,25 +167,72 @@ public class Notification: View {
type = .info type = .info
typeIcon.name = .infoBold typeIcon.name = .infoBold
closeButton.name = .close closeButton.name = .close
} }
//-------------------------------------------------- //--------------------------------------------------
// MARK: - State // MARK: - State
//-------------------------------------------------- //--------------------------------------------------
open override func updateView() { open override func updateView() {
updateTextColorConfig()
backgroundColor = backgroundColorConfiguration.getColor(self) 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.name = type.styleIconName()
typeIcon.color = surface == .dark ? Icon.Color.white : Icon.Color.black typeIcon.color = iconColor
closeButton.color = surface == .dark ? Icon.Color.white : Icon.Color.black closeButton.color = iconColor
titleLabel.textColorConfiguration = textColorConfig.eraseToAnyColorable() }
subTitleLabel.textColorConfiguration = textColorConfig.eraseToAnyColorable()
private func updateLabels() {
titleLabel.surface = surface titleLabel.surface = surface
subTitleLabel.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() { func didClickOnCloseButton() {