Repository navigation
Conversation
The multiline field sized its TextEditor from an invisible Text copy of the typed text. Text and UITextView lay out a custom font's lines at different heights, so the max-lines cap was never a whole number of the editor's lines. Past the cap the editor scrolls the caret line to the bottom of the frame, and the top line showed cut part way through. The editor is now sized from the UITextView behind it: its content height, in whole lines of its typing font's line height, between min-lines and max-lines. Its text container insets are set to zero on the text view itself instead of being pulled back with negative padding, so no part of a scrolled-off line is drawn outside the field. The field's height now follows its text a moment later than before, so when a focused field gets shorter (a smaller text size, say) it scrolls the caret's line back into view. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…drawn A multiline text input is as tall as its lines. With h-full (or fill) it now takes the height its parent gives it and scrolls its own text, never shorter than min-lines. flex-1 alone doesn't do it, because in a row it means width and a chat bar's field should keep growing a line at a time. @caretChange reports the caret's rectangle in the field's own points (dp on Android), from the top-left of its visible area with its scrolling taken off, plus the visual line it's on and the field's visible size. A handler typed Caret gets it decoded, through the binding the component invoker already gives UrlRoutable parameters, so core needs no change. It's sent after the caret moves, the text is laid out again or the field scrolls, coalesced over the selection window and only while focused. iOS reads it from the UITextView the sizer from the previous commit already finds. Android's BasicTextField keeps its scroll to itself, so the bare renderer follows it: the cursor-driven scroll is mirrored from Compose's own rule and drags reach it as nested scroll. Outlined and filled fields send it on iOS only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 task
Compose's BasicTextField only scrolls to the caret when the caret moves, not when the field's height shrinks. A composer that shrinks to make room for something under the caret left the caret's line below its new bottom edge until the next keystroke. iOS already scrolls it back. The bare renderer now puts a BringIntoViewRequester on a box placed at the caret reporter's mirrored scroll offset, inside the field's own scroller. When a focused multiline field gets shorter and the caret is out of view, the reporter asks it to show the caret's rectangle. That scroll comes back through nested scroll like a drag, so the mirror and @caretChange follow it. This runs for every multiline bare field, with or without a callback. The mirror also re-coerces on the caret's left or top edge moving, as Compose does, instead of top or bottom, and handles a caret taller than the field the same way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two things for multiline text inputs, both needed by the devnull composer sheet (NativePHP/dev-null-app#198), which currently has to guess how tall the sheet is and where the caret is drawn.
This branch has #218's commit under mine, because the iOS caret reporting uses the
UITextViewthat #218's sizer already finds. Merge #218 first, or this one with it.A multiline field that fills its height
A multiline field is as tall as its lines (
min-linestomax-lines). Withh-full(orfill) it now takes the height its parent gives it and scrolls its own text inside. It's never shorter thanmin-lines, andmax-linesdoesn't cap it.I didn't make
flex-1do this. In a rowflex-1means width, and a chat bar'sflex-1field should keep growing a line at a time. Put theh-fullfield in aflex-1column instead.h-fullon a multiline field did nothing useful before, so nothing that works today changes.When a focused multiline field gets shorter, it scrolls so the caret stays in view. iOS already did that. On Android, Compose's
BasicTextFieldonly scrolls to the caret when the caret moves, so the devnull composer shrinking to make room for the mention list left the caret's line below the field until the next keystroke. The bare renderer now puts aBringIntoViewRequesteron a box that sits where the scrolled text is (at the reporter's mirrored scroll offset, inside the field's own scroller). When the field shrinks and the caret is out of view, it asks that box to show the caret. This runs for every multiline bare field, with or without@caretChange. Outlined and filled don't get it on Android.The element sends
fills_heightfor a multiline field whose layout height isfill..frame(minHeight: <min-lines>, maxHeight: .infinity)in place of Size the iOS multiline input in whole lines of its own text view #218's line-based height.fillMaxHeight()and nomaxLinescap, on all three variants. Compose scrolls the text inside the height it's given.@caretChangeReports where a multiline field draws its caret. Type the handler's parameter as
Native\Mobile\UI\Caretand it's decoded:x,y,width,heightare points on iOS and dp on Android, from the top-left of the part of the field you can see, with its scrolling taken off. Soyis 0 on the top visible line and goes negative, or pastfieldHeight, once the caret scrolls out of view ($caret->visible()).lineis the visual line from the top of the text.fieldWidthandfieldHeightare the field's visible size. To place an overlay you add where the field sits in the overlay's parent.It's sent after the caret moves, after the text is laid out again and after the field scrolls. It's coalesced over the same window as
@selectionChange(selection-debounce-ms), dropped when nothing changed, and only sent while the field has focus. Never for single-line orsecurefields.The payload rides the text-change event as
x,y,width,height,line,fieldWidth,fieldHeight.CaretimplementsUrlRoutable, so the component invoker's existing implicit binding (the one that binds backed enums and models) decodes it. That keeps core out of it. A handler typedstringgets the raw payload.caretRect(for: selectedTextRange.end)minuscontentOffset, from the text view the sizer finds. It's scheduled on selection and text changes,contentSizeandcontentOffsetKVO, and the field's size changing. Binding the selection is now also switched on by@caretChange, and like before that is decided by props that hold still, so the field isn't rebuilt between renders. All three text inputs send it on iOS, since they share the core.TextLayoutResult.getCursorRect(selection.end), px to dp, in the bare renderer only. BasicTextField (theTextFieldValueone) keeps its scroll position private, so the reporter follows it. The scroll that keeps the caret in view is mirrored from Compose's ownTextFieldScrollerPositionrule (it re-checks when the caret's left or top edge moves), and a drag or fling of the text, or the shrink scroll above, reaches it as nested scroll, where the consumed distance is taken off. Outlined and filled don't send it on Android: M3'sTextFieldgives no text layout to read.In tests,
->moveCaretTo('body', new Caret(y: 48, height: 24))fires it as a device would.Watch for
BasicTextFieldscrolls to the caret,ydrifts, and so would the shrink scroll, since its anchor box is placed at the mirrored offset. The Robolectric tests below would catch the common case.Testing
BaseTextInputCaretTest(serialization, the payload, aCarethandler getting the decoded caret after its literal arguments, astringhandler getting the raw payload) andBaseTextInputFillTest(h-fullandfillfill,flex-1and single-line don't). Size the iOS multiline input in whole lines of its own text view #218's sizing test needed two strings updated.swiftc -typecheck -wmoover mobile-airmain'sNativeRenderplusresources/ios: the same 156 error lines as Size the iOS multiline input in whole lines of its own text view #218's commit alone, none inNativeUITextInputCore.swift. Canaries planted in the reporter and in the view body were both reported.tests/android(Robolectric, JDK 23,-PmobileRootan app'svendor/nativephp/mobile): 114 passed. That compiles all three text input renderers. NewTextInputCaretRectTestchecks the caret's line and position, that a field capped at three lines reports the caret on its last visible line once it scrolls, that nothing is sent unchanged, unfocused or from a single-line field, and thatfills_heightmakes the field as tall as its parent and scrolls past what fits. NewTextInputCaretShrinkTesttypes twelve lines into a field filling a 400dp column and shrinks the column to 120dp. The caret's line ends up as the last one the field shows, with or without@caretChange, and the reportedymatches where the text is really drawn (read from the field's layout nodes). Two of its three cases fail with the shrink scroll switched off. A field whose caret is still in view doesn't scroll.🤖 Generated with Claude Code