fix: re-layout the inner UITextView on host bounds change#47
Draft
haileyok wants to merge 1 commit into
Draft
Conversation
The inner UITextView's frame is assigned inside drawRect, which is only invalidated by updateState (state change). Bounds changes from rotation or parent relayout therefore left the text view sized to its previous frame and content overflowed the host. Override layoutSubviews to call setNeedsDisplay when the host frame and the inner text view frame have diverged, which lets drawRect resize the text view and refire onTextLayout with the new line wrapping. Co-Authored-By: Claude Opus 4.7 (1M context) <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.
Summary
Fixes #21.
The inner
UITextView's frame is assigned insidedrawRect:, which is only invalidated byupdateState:(i.e. only on state change, not on frame change). When the device rotates or any ancestor re-lays out, RN re-runs Yoga,measureContentrecomputes, and the host'sframe/_view.frameupdate — butdrawRect:never re-fires, so_textView.framestays at the old orientation's value and the text overflows the host. The user'skey={orientation}workaround in the issue thread papers over this by forcing a full unmount→remount.The fix is a
layoutSubviewsoverride that callssetNeedsDisplaywhenever the host frame and the inner text view's frame have diverged. That re-runsdrawRect:, which resizes the text view, refiresonTextLayoutwith the new line wrapping, and lets the text wrap to the new container width.Test plan
selectableanduiTextViewprops are set #21:<UITextView selectable uiTextView>{longText}</UITextView>, rotate portrait → landscape → portrait. Text reflows correctly each time and stays inside the container.onTextLayoutafter rotation with a newlines.lengthmatching the new wrapping.<UITextView>in a non-rotating screen has no extra redraws (theCGRectEqualToRectguard skips the case where nothing changed).🤖 Generated with Claude Code