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 {
|
||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||
$0.attributes = []
|
||||
}
|
||||
|
||||
internal var errorLabel = Label().with {
|
||||
@ -273,23 +274,36 @@ open class EntryField: Control, Accessable {
|
||||
|
||||
setAccessibilityHint()
|
||||
backgroundColor = surface.color
|
||||
setNeedsLayout()
|
||||
layoutIfNeeded()
|
||||
}
|
||||
|
||||
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
|
||||
titleLabel.attributes?.removeAll()
|
||||
//dealing with the "Optional" addition to the text
|
||||
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
|
||||
titleLabel.addOptional(required: required, colorConfiguration: secondaryColorConfig)
|
||||
|
||||
//tooltip action
|
||||
if let view = getToolTipView() {
|
||||
//add the tool tip
|
||||
if let view = getToolTipView(), let oldText = updatedLabelText {
|
||||
tooltipView = view
|
||||
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
|
||||
self?.showToolTipView()
|
||||
}.store(in: &subscribers)
|
||||
@ -297,9 +311,11 @@ open class EntryField: Control, Accessable {
|
||||
tooltipView = nil
|
||||
}
|
||||
|
||||
//set the titleLabel
|
||||
titleLabel.textPosition = .left
|
||||
titleLabel.typograpicalStyle = .BodySmall
|
||||
titleLabel.text = labelText
|
||||
titleLabel.text = updatedLabelText
|
||||
titleLabel.attributes = attributes
|
||||
titleLabel.surface = surface
|
||||
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