@@ -467,7 +467,8 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
467467 public required init ( appContext: AppContext ? = nil ) {
468468 super. init ( appContext: appContext)
469469
470- clipsToBounds = false
470+ clipsToBounds = true
471+ textView. clipsToBounds = true
471472 textView. delegate = self
472473 textView. textDropDelegate = self
473474 textView. backgroundColor = . clear
@@ -1215,28 +1216,16 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
12151216 }
12161217
12171218 private func emitContentSizeIfNeeded( ) {
1218- // The laid-out text without insets. A one-line draft reports its natural width, so
1219- // JS can tell whether it fits a narrower row than the one it is laid out in; past
1220- // one line only the height matters, so layout stops at the second line. The width
1221- // comes from the line fragment because usedRect spans the container once the view
1222- // scrolls. A trailing newline's empty line only exists as the extra fragment.
1223- let layout = textView. layoutManager
1224- let container = textView. textContainer
1225- var lines = 0
1226- var width : CGFloat = 0
1227- var height : CGFloat = 0
1228- let glyphs = NSRange ( location: 0 , length: layout. numberOfGlyphs)
1229- layout. enumerateLineFragments ( forGlyphRange: glyphs) { _, used, _, _, stop in
1230- lines += 1
1231- width = used. width
1232- height = used. maxY
1233- if lines > 1 { stop. pointee = true }
1234- }
1235- if lines < 2 , layout. extraLineFragmentTextContainer === container {
1236- lines += 1
1237- height = max ( height, layout. extraLineFragmentUsedRect. maxY)
1238- }
1239- let nextSize = CGSize ( width: lines == 1 ? ceil ( width) : 0 , height: ceil ( height) )
1219+ guard bounds. width > 0 else { return }
1220+ // Fit independently of the animated viewport: when scrolling is disabled,
1221+ // its current height can clip TextKit's laid-out line fragments.
1222+ let fittedHeight = textView. sizeThatFits ( CGSize ( width: bounds. width, height: . greatestFiniteMagnitude) ) . height
1223+ - textView. textContainerInset. top - textView. textContainerInset. bottom
1224+ let measuredHeight = min ( lineHeight * 4 , fittedHeight)
1225+ let width = fittedHeight <= lineHeight + 0.5
1226+ ? textView. layoutManager. usedRect ( for: textView. textContainer) . width
1227+ : 0
1228+ let nextSize = CGSize ( width: ceil ( width) , height: ceil ( measuredHeight) )
12401229 guard abs ( nextSize. width - lastContentSize. width) > 0.5 ||
12411230 abs ( nextSize. height - lastContentSize. height) > 0.5 else {
12421231 return
0 commit comments