Skip to content

Commit 1523075

Browse files
committed
Use an explicit defaultColor instead of relying on textColor
We found that textColor changes dynamic depending of the cursor position on the attributed text.
1 parent 9f8a149 commit 1523075

3 files changed

Lines changed: 30 additions & 5 deletions

File tree

Aztec/Classes/TextKit/TextView.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,22 @@ open class TextView: UITextView {
242242
.font: defaultFont,
243243
.paragraphStyle: defaultParagraphStyle,
244244
]
245-
if let color = textColor {
245+
if let color = defaultTextColor {
246246
attributes[.foregroundColor] = color
247247
}
248248
return attributes
249249
}
250-
250+
251+
open var defaultTextColor: UIColor?
252+
253+
override open var textColor: UIColor? {
254+
get {
255+
return super.textColor
256+
}
257+
set {
258+
super.textColor = newValue
259+
}
260+
}
251261
// MARK: - Plugin Loading
252262

253263
var pluginManager: PluginManager {

Aztec/Classes/TextKit/TextViewPasteboardDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ open class AztecTextViewPasteboardDelegate: TextViewPasteboardDelegate {
6969
textView?.undoTextReplacement(of: originalText, finalRange: finalRange)
7070
})
7171

72-
let colorCorrectedString = fixColors(in: string, using: textView.textColor)
72+
let colorCorrectedString = fixColors(in: string, using: textView.defaultTextColor)
7373

7474
storage.replaceCharacters(in: selectedRange, with: colorCorrectedString)
7575
textView.notifyTextViewDidChange()

Example/Example/EditorDemoController.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class EditorDemoController: UIViewController {
6565

6666
private func setupHTMLTextView(_ textView: UITextView) {
6767
let accessibilityLabel = NSLocalizedString("HTML Content", comment: "Post HTML content")
68-
self.configureDefaultProperties(for: textView, accessibilityLabel: accessibilityLabel)
68+
self.configureDefaultProperties(htmlTextView: textView, accessibilityLabel: accessibilityLabel)
6969

7070
textView.isHidden = true
7171
textView.delegate = self
@@ -325,7 +325,22 @@ class EditorDemoController: UIViewController {
325325
}
326326

327327

328-
private func configureDefaultProperties(for textView: UITextView, accessibilityLabel: String) {
328+
private func configureDefaultProperties(for textView: TextView, accessibilityLabel: String) {
329+
textView.accessibilityLabel = accessibilityLabel
330+
textView.font = Constants.defaultContentFont
331+
textView.keyboardDismissMode = .interactive
332+
if #available(iOS 13.0, *) {
333+
textView.textColor = UIColor.label
334+
textView.defaultTextColor = UIColor.label
335+
} else {
336+
// Fallback on earlier versions
337+
textView.textColor = UIColor(red: 0x1A/255.0, green: 0x1A/255.0, blue: 0x1A/255.0, alpha: 1)
338+
textView.defaultTextColor = UIColor(red: 0x1A/255.0, green: 0x1A/255.0, blue: 0x1A/255.0, alpha: 1)
339+
}
340+
textView.linkTextAttributes = [.foregroundColor: UIColor(red: 0x01 / 255.0, green: 0x60 / 255.0, blue: 0x87 / 255.0, alpha: 1), NSAttributedString.Key.underlineStyle: NSNumber(value: NSUnderlineStyle.single.rawValue)]
341+
}
342+
343+
private func configureDefaultProperties(htmlTextView textView: UITextView, accessibilityLabel: String) {
329344
textView.accessibilityLabel = accessibilityLabel
330345
textView.font = Constants.defaultContentFont
331346
textView.keyboardDismissMode = .interactive

0 commit comments

Comments
 (0)