diff --git a/VDS/Components/TextFields/TextArea/TextView.swift b/VDS/Components/TextFields/TextArea/TextView.swift index 54fa9452..3f40ae38 100644 --- a/VDS/Components/TextFields/TextArea/TextView.swift +++ b/VDS/Components/TextFields/TextArea/TextView.swift @@ -41,10 +41,23 @@ open class TextView: UITextView, ViewProtocol, Errorable { // MARK: - Private Properties //-------------------------------------------------- private var initialSetupPerformed = false - + //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- + open var placeholder: String? { + didSet { + placeholderLabel.text = placeholder + } + } + + open var placeholderLabel = Label().with { + $0.textColorConfiguration = ViewColorConfiguration().with { + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forDisabled: true) + $0.setSurfaceColors(VDSColor.elementsSecondaryOnlight, VDSColor.elementsSecondaryOndark, forDisabled: false) + }.eraseToAnyColorable() + } + /// Key of whether or not updateView() is called in setNeedsUpdate() open var shouldUpdateView: Bool = true @@ -88,6 +101,7 @@ open class TextView: UITextView, ViewProtocol, Errorable { if textAlignment != oldValue { // Text alignment can be part of our paragraph style, so we may need to // re-style when changed + placeholderLabel.textAlignment = textAlignment updateLabel() } } @@ -118,6 +132,9 @@ open class TextView: UITextView, ViewProtocol, Errorable { done.pinCenterY() .pinTrailing(16) inputAccessoryView = accessView + + addSubview(placeholderLabel) + placeholderLabel.pinToSuperView() } @objc func doneButtonAction() { @@ -145,7 +162,11 @@ open class TextView: UITextView, ViewProtocol, Errorable { setNeedsUpdate() } - + open override func layoutSubviews() { + super.layoutSubviews() + placeholderLabel.preferredMaxLayoutWidth = textContainer.size.width - textContainer.lineFragmentPadding * 2 + } + //-------------------------------------------------- // MARK: - Accessibility //-------------------------------------------------- @@ -297,6 +318,9 @@ open class TextView: UITextView, ViewProtocol, Errorable { } else { attributedText = nil } + placeholderLabel.textStyle = textStyle + placeholderLabel.isHidden = !text.isEmpty + placeholderLabel.surface = surface } }