refactored entryfield
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
85337833d4
commit
d611960ac8
@ -44,6 +44,7 @@ open class EntryField: Control, Accessable {
|
|||||||
|
|
||||||
internal var titleLabel = Label().with {
|
internal var titleLabel = Label().with {
|
||||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
|
$0.attributes = []
|
||||||
}
|
}
|
||||||
|
|
||||||
internal var errorLabel = Label().with {
|
internal var errorLabel = Label().with {
|
||||||
@ -273,23 +274,36 @@ open class EntryField: Control, Accessable {
|
|||||||
|
|
||||||
setAccessibilityHint()
|
setAccessibilityHint()
|
||||||
backgroundColor = surface.color
|
backgroundColor = surface.color
|
||||||
setNeedsLayout()
|
|
||||||
layoutIfNeeded()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open func updateTitleLabel() {
|
open func updateTitleLabel() {
|
||||||
|
|
||||||
|
//update the local vars for the label since we no
|
||||||
|
//long have a model
|
||||||
|
var attributes: [any LabelAttributeModel] = []
|
||||||
|
var updatedLabelText = labelText
|
||||||
|
|
||||||
//remove all attributes
|
//dealing with the "Optional" addition to the text
|
||||||
titleLabel.attributes?.removeAll()
|
if let oldText = updatedLabelText, !required, !oldText.hasSuffix("Optional") {
|
||||||
|
let optionColorAttr = ColorLabelAttribute(location: oldText.count + 2,
|
||||||
|
length: 8,
|
||||||
|
color: secondaryColorConfig.getColor(self))
|
||||||
|
|
||||||
|
updatedLabelText = "\(oldText) Optional"
|
||||||
|
attributes.append(optionColorAttr)
|
||||||
|
}
|
||||||
|
|
||||||
//update the title model if the required flag is false
|
//add the tool tip
|
||||||
titleLabel.addOptional(required: required, colorConfiguration: secondaryColorConfig)
|
if let view = getToolTipView(), let oldText = updatedLabelText {
|
||||||
|
|
||||||
//tooltip action
|
|
||||||
if let view = getToolTipView() {
|
|
||||||
tooltipView = view
|
tooltipView = view
|
||||||
let toolTipAction = PassthroughSubject<Void, Never>()
|
let toolTipAction = PassthroughSubject<Void, Never>()
|
||||||
titleLabel.addToolTip(action: toolTipAction, colorConfiguration: primaryColorConfig)
|
let toolTipUpdateText = "\(oldText) " //create a little space between the final character and tooltip image
|
||||||
|
let toolTipAttribute = ToolTipLabelAttribute(action: toolTipAction,
|
||||||
|
location: toolTipUpdateText.count,
|
||||||
|
length: 1,
|
||||||
|
tintColor: primaryColorConfig.getColor(self))
|
||||||
|
updatedLabelText = toolTipUpdateText
|
||||||
|
attributes.append(toolTipAttribute)
|
||||||
toolTipAction.sink { [weak self] in
|
toolTipAction.sink { [weak self] in
|
||||||
self?.showToolTipView()
|
self?.showToolTipView()
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
@ -297,9 +311,11 @@ open class EntryField: Control, Accessable {
|
|||||||
tooltipView = nil
|
tooltipView = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//set the titleLabel
|
||||||
titleLabel.textPosition = .left
|
titleLabel.textPosition = .left
|
||||||
titleLabel.typograpicalStyle = .BodySmall
|
titleLabel.typograpicalStyle = .BodySmall
|
||||||
titleLabel.text = labelText
|
titleLabel.text = updatedLabelText
|
||||||
|
titleLabel.attributes = attributes
|
||||||
titleLabel.surface = surface
|
titleLabel.surface = surface
|
||||||
titleLabel.disabled = disabled
|
titleLabel.disabled = disabled
|
||||||
|
|
||||||
@ -355,29 +371,3 @@ internal class ErrorDisabledSurfaceColorConfiguration: DisabledSurfaceColorable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Label {
|
|
||||||
public func addOptional(required: Bool, colorConfiguration: DisabledSurfaceColorConfiguration) {
|
|
||||||
guard let oldText = text, !required, !oldText.hasSuffix("Optional") else { return }
|
|
||||||
let optionColorAttr = ColorLabelAttribute(location: oldText.count + 2,
|
|
||||||
length: 8,
|
|
||||||
color: colorConfiguration.getColor(self))
|
|
||||||
|
|
||||||
let newText = "\(oldText) Optional"
|
|
||||||
text = newText
|
|
||||||
attributes = [optionColorAttr]
|
|
||||||
}
|
|
||||||
|
|
||||||
public func addToolTip(action: PassthroughSubject<Void, Never>, colorConfiguration: DisabledSurfaceColorConfiguration) {
|
|
||||||
guard let oldText = text else { return}
|
|
||||||
var newAttributes = attributes ?? []
|
|
||||||
let newText = "\(oldText) " //create a little space between the final character and tooltip image
|
|
||||||
let toolTip = ToolTipLabelAttribute(action: action,
|
|
||||||
location: newText.count,
|
|
||||||
length: 1,
|
|
||||||
tintColor: colorConfiguration.getColor(self))
|
|
||||||
newAttributes.append(toolTip)
|
|
||||||
text = newText
|
|
||||||
attributes = newAttributes
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user