Various improvements

This commit is contained in:
Ilya Laktyushin
2022-05-19 21:15:31 +04:00
parent b0cb39b8cd
commit 3fb304bd6f
30 changed files with 319 additions and 136 deletions

View File

@@ -20,6 +20,10 @@ public final class MultilineTextComponent: Component {
public let insets: UIEdgeInsets
public let textShadowColor: UIColor?
public let textStroke: (UIColor, CGFloat)?
public let highlightColor: UIColor?
public let highlightAction: (([NSAttributedString.Key: Any]) -> NSAttributedString.Key?)?
public let tapAction: (([NSAttributedString.Key: Any], Int) -> Void)?
public let longTapAction: (([NSAttributedString.Key: Any], Int) -> Void)?
public init(
text: TextContent,
@@ -31,7 +35,11 @@ public final class MultilineTextComponent: Component {
cutout: TextNodeCutout? = nil,
insets: UIEdgeInsets = UIEdgeInsets(),
textShadowColor: UIColor? = nil,
textStroke: (UIColor, CGFloat)? = nil
textStroke: (UIColor, CGFloat)? = nil,
highlightColor: UIColor? = nil,
highlightAction: (([NSAttributedString.Key: Any]) -> NSAttributedString.Key?)? = nil,
tapAction: (([NSAttributedString.Key: Any], Int) -> Void)? = nil,
longTapAction: (([NSAttributedString.Key: Any], Int) -> Void)? = nil
) {
self.text = text
self.horizontalAlignment = horizontalAlignment
@@ -43,6 +51,10 @@ public final class MultilineTextComponent: Component {
self.insets = insets
self.textShadowColor = textShadowColor
self.textStroke = textStroke
self.highlightColor = highlightColor
self.highlightAction = highlightAction
self.tapAction = tapAction
self.longTapAction = longTapAction
}
public static func ==(lhs: MultilineTextComponent, rhs: MultilineTextComponent) -> Bool {
@@ -90,10 +102,18 @@ public final class MultilineTextComponent: Component {
return false
}
if let lhsHighlightColor = lhs.highlightColor, let rhsHighlightColor = rhs.highlightColor {
if !lhsHighlightColor.isEqual(rhsHighlightColor) {
return false
}
} else if (lhs.highlightColor != nil) != (rhs.highlightColor != nil) {
return false
}
return true
}
public final class View: TextView {
public final class View: ImmediateTextView {
public func update(component: MultilineTextComponent, availableSize: CGSize) -> CGSize {
let attributedString: NSAttributedString
switch component.text {
@@ -102,26 +122,25 @@ public final class MultilineTextComponent: Component {
case let .markdown(text, attributes):
attributedString = parseMarkdownIntoAttributedString(text, attributes: attributes)
}
self.attributedText = attributedString
self.maximumNumberOfLines = component.maximumNumberOfLines
self.truncationType = component.truncationType
self.textAlignment = component.horizontalAlignment
self.verticalAlignment = component.verticalAlignment
self.lineSpacing = component.lineSpacing
self.cutout = component.cutout
self.insets = component.insets
self.textShadowColor = component.textShadowColor
self.textStroke = component.textStroke
self.linkHighlightColor = component.highlightColor
self.highlightAttributeAction = component.highlightAction
self.tapAttributeAction = component.tapAction
self.longTapAttributeAction = component.longTapAction
let makeLayout = TextView.asyncLayout(self)
let (layout, apply) = makeLayout(TextNodeLayoutArguments(
attributedString: attributedString,
backgroundColor: nil,
maximumNumberOfLines: component.maximumNumberOfLines,
truncationType: component.truncationType,
constrainedSize: availableSize,
alignment: component.horizontalAlignment,
verticalAlignment: component.verticalAlignment,
lineSpacing: component.lineSpacing,
cutout: component.cutout,
insets: component.insets,
textShadowColor: component.textShadowColor,
textStroke: component.textStroke,
displaySpoilers: false
))
let _ = apply()
return layout.size
let size = self.updateLayout(availableSize)
return size
}
}