Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
2.5 kB · 46 lines
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647diff --git a/ios/RNUITextViewShadow.swift b/ios/RNUITextViewShadow.swiftindex c34ba712ca628ed8cf2db0f9fc332810ec86d34d..e86e9899b0bd8d6e2c9e7e1f5b676bca4f3afad9 100644--- a/ios/RNUITextViewShadow.swift+++ b/ios/RNUITextViewShadow.swift@@ -48,7 +48,10 @@ class RNUITextViewShadow: RCTShadowView { // We should only insert children that are UITextView shadows override func insertReactSubview(_ subview: RCTShadowView!, at atIndex: Int) { if subview.isKind(of: RNUITextViewChildShadow.self) {- super.insertReactSubview(subview, at: atIndex)+ // Clamp the index to the actual subview count. React sends sequential+ // indices assuming every child is inserted, but we filter out non-child+ // shadow views, so the real array can be shorter than the requested index.+ super.insertReactSubview(subview, at: min(atIndex, self.reactSubviews()?.count ?? 0)) } } @@ -159,13 +162,25 @@ class RNUITextViewShadow: RCTShadowView { let maxSize = CGSize(width: CGFloat(maxWidth), height: CGFloat(MAXFLOAT)) let textSize = self.attributedText.boundingRect(with: maxSize, options: .usesLineFragmentOrigin, context: nil) - var totalLines = self.lineHeight == 0.0 ? 0 : Int(ceil(textSize.height / self.lineHeight))+ var finalHeight: CGFloat - if self.numberOfLines != 0, totalLines > self.numberOfLines {- totalLines = self.numberOfLines+ if self.numberOfLines != 0 && self.lineHeight != 0.0 {+ // numberOfLines is set with custom line height - need to calculate lines and snap to lineHeight multiples+ // NOTE: this calculation can be inaccurate with fractional font sizes+ var totalLines = Int(ceil(textSize.height / self.lineHeight))+ if totalLines > self.numberOfLines {+ totalLines = self.numberOfLines+ }+ finalHeight = CGFloat(totalLines) * self.lineHeight+ } else {+ // Either no numberOfLines limit, or no custom lineHeight - use actual text height+ // (numberOfLines without custom lineHeight is handled by the UITextView's textContainer.maximumNumberOfLines)+ finalHeight = textSize.height } - self.frameSize = CGSize(width: CGFloat(maxWidth), height: CGFloat(CGFloat(totalLines) * self.lineHeight))+ finalHeight = ceil(finalHeight)++ self.frameSize = CGSize(width: CGFloat(maxWidth), height: finalHeight) return YGSize(width: Float(self.frameSize.width), height: Float(self.frameSize.height)) }