Skip to content

fix: re-layout the inner UITextView on host bounds change#47

Draft
haileyok wants to merge 1 commit into
mainfrom
worktree-fix-rotation-relayout
Draft

fix: re-layout the inner UITextView on host bounds change#47
haileyok wants to merge 1 commit into
mainfrom
worktree-fix-rotation-relayout

Conversation

@haileyok
Copy link
Copy Markdown
Member

@haileyok haileyok commented May 9, 2026

Summary

Fixes #21.

The inner UITextView's frame is assigned inside drawRect:, which is only invalidated by updateState: (i.e. only on state change, not on frame change). When the device rotates or any ancestor re-lays out, RN re-runs Yoga, measureContent recomputes, and the host's frame/_view.frame update — but drawRect: never re-fires, so _textView.frame stays at the old orientation's value and the text overflows the host. The user's key={orientation} workaround in the issue thread papers over this by forcing a full unmount→remount.

The fix is a layoutSubviews override that calls setNeedsDisplay whenever the host frame and the inner text view's frame have diverged. That re-runs drawRect:, which resizes the text view, refires onTextLayout with the new line wrapping, and lets the text wrap to the new container width.

Test plan

  • Verify the repro from Layout does not update on screen orientation change when both selectable and uiTextView props are set #21: <UITextView selectable uiTextView>{longText}</UITextView>, rotate portrait → landscape → portrait. Text reflows correctly each time and stays inside the container.
  • Verify the same component re-fires onTextLayout after rotation with a new lines.length matching the new wrapping.
  • Verify normal selection / press / long-press flows still work unchanged.
  • Verify a static-size <UITextView> in a non-rotating screen has no extra redraws (the CGRectEqualToRect guard skips the case where nothing changed).

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Layout does not update on screen orientation change when both selectable and uiTextView props are set

1 participant