refactored text into properties
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
d866a4e3c3
commit
05e23f7d58
@ -87,6 +87,16 @@ public class Notification: View {
|
|||||||
$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,15 +115,9 @@ 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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -149,33 +153,13 @@ public class Notification: View {
|
|||||||
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)
|
||||||
typeIcon.name = type.styleIconName()
|
updateIcons()
|
||||||
typeIcon.color = surface == .dark ? Icon.Color.white : Icon.Color.black
|
updateLabels()
|
||||||
closeButton.color = surface == .dark ? Icon.Color.white : Icon.Color.black
|
updateButtons()
|
||||||
titleLabel.textColorConfiguration = textColorConfig.eraseToAnyColorable()
|
}
|
||||||
subTitleLabel.textColorConfiguration = textColorConfig.eraseToAnyColorable()
|
|
||||||
|
|
||||||
|
private func updateIcons() {
|
||||||
|
let iconColor = surface == .dark ? Icon.Color.white : Icon.Color.black
|
||||||
|
typeIcon.name = type.styleIconName()
|
||||||
|
typeIcon.color = iconColor
|
||||||
|
closeButton.color = iconColor
|
||||||
|
}
|
||||||
|
|
||||||
|
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() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user