Put compose text view attributed string behavior behind feature flag
This commit is contained in:
parent
e9e08bdadd
commit
96f5ea8af1
@ -139,12 +139,14 @@ private final class WrappedTextViewCoordinator: NSObject {
|
|||||||
attributedText.string.replacingOccurrences(of: "\u{FFFC}", with: "")
|
attributedText.string.replacingOccurrences(of: "\u{FFFC}", with: "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MainActor
|
||||||
private func attributedTextFromPlain(_ text: String) -> NSAttributedString {
|
private func attributedTextFromPlain(_ text: String) -> NSAttributedString {
|
||||||
let str = NSMutableAttributedString(string: text)
|
let str = NSMutableAttributedString(string: text)
|
||||||
str.addAttributes([
|
str.addAttributes([
|
||||||
.foregroundColor: UIColor.label,
|
.foregroundColor: UIColor.label,
|
||||||
.font: UIFontMetrics.default.scaledFont(for: .systemFont(ofSize: 20)),
|
.font: UIFontMetrics.default.scaledFont(for: .systemFont(ofSize: 20)),
|
||||||
], range: NSRange(location: 0, length: str.length))
|
], range: NSRange(location: 0, length: str.length))
|
||||||
|
if Preferences.shared.hasFeatureFlag(.composeTextAttributes) {
|
||||||
let mentionMatches = CharacterCounter.mention.matches(in: text, range: NSRange(location: 0, length: str.length))
|
let mentionMatches = CharacterCounter.mention.matches(in: text, range: NSRange(location: 0, length: str.length))
|
||||||
for match in mentionMatches.reversed() {
|
for match in mentionMatches.reversed() {
|
||||||
str.insert(NSAttributedString(attachment: Self.attachment), at: match.range.location)
|
str.insert(NSAttributedString(attachment: Self.attachment), at: match.range.location)
|
||||||
@ -154,16 +156,23 @@ private final class WrappedTextViewCoordinator: NSObject {
|
|||||||
.foregroundColor: UIColor.tintColor,
|
.foregroundColor: UIColor.tintColor,
|
||||||
], range: range)
|
], range: range)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MainActor
|
||||||
func updateTextViewTextIfNecessary(_ text: String, textView: UITextView) {
|
func updateTextViewTextIfNecessary(_ text: String, textView: UITextView) {
|
||||||
if text != plainTextFromAttributed(textView.attributedText) {
|
if text != plainTextFromAttributed(textView.attributedText) {
|
||||||
textView.attributedText = attributedTextFromPlain(text)
|
textView.attributedText = attributedTextFromPlain(text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MainActor
|
||||||
private func updateAttributes(in textView: UITextView) {
|
private func updateAttributes(in textView: UITextView) {
|
||||||
|
guard Preferences.shared.hasFeatureFlag(.composeTextAttributes) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let str = NSMutableAttributedString(attributedString: textView.attributedText!)
|
let str = NSMutableAttributedString(attributedString: textView.attributedText!)
|
||||||
var changed = false
|
var changed = false
|
||||||
var cursorOffset = 0
|
var cursorOffset = 0
|
||||||
|
@ -10,5 +10,6 @@ import Foundation
|
|||||||
public enum FeatureFlag: String, Codable {
|
public enum FeatureFlag: String, Codable {
|
||||||
case iPadBrowserNavigation = "ipad-browser-navigation"
|
case iPadBrowserNavigation = "ipad-browser-navigation"
|
||||||
case composeRewrite = "compose-rewrite"
|
case composeRewrite = "compose-rewrite"
|
||||||
|
case composeTextAttributes = "compose-text-attributes"
|
||||||
case pushNotifCustomEmoji = "push-notif-custom-emoji"
|
case pushNotifCustomEmoji = "push-notif-custom-emoji"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user