onTextLayout event
This commit is contained in:
@@ -3,10 +3,15 @@ class RNUITextView: UIView {
|
|||||||
|
|
||||||
@objc var numberOfLines: Int = 0 {
|
@objc var numberOfLines: Int = 0 {
|
||||||
didSet {
|
didSet {
|
||||||
print(numberOfLines)
|
|
||||||
textView.textContainer.maximumNumberOfLines = numberOfLines
|
textView.textContainer.maximumNumberOfLines = numberOfLines
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@objc var selectable: Bool = true {
|
||||||
|
didSet {
|
||||||
|
textView.isSelectable = selectable
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@objc var onTextLayout: RCTDirectEventBlock?
|
||||||
|
|
||||||
override init(frame: CGRect) {
|
override init(frame: CGRect) {
|
||||||
if #available(iOS 16.0, *) {
|
if #available(iOS 16.0, *) {
|
||||||
@@ -52,6 +57,21 @@ class RNUITextView: UIView {
|
|||||||
self.textView.frame.size = size
|
self.textView.frame.size = size
|
||||||
self.textView.textContainer.maximumNumberOfLines = numberOfLines
|
self.textView.textContainer.maximumNumberOfLines = numberOfLines
|
||||||
self.textView.attributedText = string
|
self.textView.attributedText = string
|
||||||
|
|
||||||
|
if let onTextLayout = self.onTextLayout {
|
||||||
|
var lines: [String] = []
|
||||||
|
textView.layoutManager.enumerateLineFragments(
|
||||||
|
forGlyphRange: NSRange(location: 0, length: textView.attributedText.length))
|
||||||
|
{ (rect, usedRect, textContainer, glyphRange, stop) in
|
||||||
|
let characterRange = self.textView.layoutManager.characterRange(forGlyphRange: glyphRange, actualGlyphRange: nil)
|
||||||
|
let line = (self.textView.text as NSString).substring(with: characterRange)
|
||||||
|
lines.append(line)
|
||||||
|
}
|
||||||
|
|
||||||
|
onTextLayout([
|
||||||
|
"lines": lines
|
||||||
|
])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func callOnPress(_ sender: UITapGestureRecognizer) -> Void {
|
@IBAction func callOnPress(_ sender: UITapGestureRecognizer) -> Void {
|
||||||
@@ -82,8 +102,6 @@ class RNUITextView: UIView {
|
|||||||
fractionOfDistanceBetweenInsertionPoints: nil
|
fractionOfDistanceBetweenInsertionPoints: nil
|
||||||
)
|
)
|
||||||
|
|
||||||
let text = textView.attributedText.string
|
|
||||||
|
|
||||||
for child in self.subviews {
|
for child in self.subviews {
|
||||||
guard let child = child as? RNUITextViewChild, let text = child.text else {
|
guard let child = child as? RNUITextViewChild, let text = child.text else {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -105,24 +105,6 @@ class RNUITextViewShadow: RCTShadowView {
|
|||||||
range: NSMakeRange(0, string.length)
|
range: NSMakeRange(0, string.length)
|
||||||
)
|
)
|
||||||
|
|
||||||
// if let textDecorationLine = child.textDecorationLine {
|
|
||||||
// if textDecorationLine == .underline || textDecorationLine == .underlineLineThrough {
|
|
||||||
// string.addAttribute(
|
|
||||||
// NSAttributedString.Key.underlineStyle,
|
|
||||||
// value: NSUnderlineStyle.single.rawValue,
|
|
||||||
// range: NSMakeRange(0, string.length)
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if textDecorationLine == .lineThrough || textDecorationLine == .underlineLineThrough {
|
|
||||||
// string.addAttribute(
|
|
||||||
// NSAttributedString.Key.strikethroughStyle,
|
|
||||||
// value: NSUnderlineStyle.single.rawValue,
|
|
||||||
// range: NSMakeRange(0, string.length)
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
finalAttributedString.append(string)
|
finalAttributedString.append(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user