Skip to content

fix(Android): Measurement jumps - #864

Merged
szydlovsky merged 41 commits into
mainfrom
@szydlovsky/fix-android-measurement-jumps
Nov 25, 2026
Merged

szydlovsky merged 41 commits into
mainfrom
@szydlovsky/fix-android-measurement-jumps

Conversation

@szydlovsky

@szydlovsky szydlovsky commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

While testing new onScroll prop I found out that we've had issues with Android measurement jumps pretty much since auto-growth was added.

It can be seen here:

Screen.Recording.2026-11-12.at.18.28.38.mov

Basically, strange scrolls and Input component offsets whenever:

  • adding characters to an empty line
  • removing characters from a line, resulting in emptying it
  • adding new lines before reaching input's maxHeight

1. Empty lines measured too short

For apps targeting SDK 35+, EditText uses a locale-preferred minimum line height (setLocalePreferredLineHeightForMinimumUsed), which keeps empty lines as tall as lines with text. MeasurementStore's StaticLayout didn't apply it, so empty and code block lines were measured a few px shorter than drawn. The view came out too short and EditText scrolled by the difference (the 0.76 offset).

Fix: MeasurementStore applies the same setMinimumFontMetrics(paint.getFontMetricsForLocale(...)) when the view uses it.

2. One-line jump while growing

The height update goes through an async Fabric state update. Before the view grows, the new line is already laid out, and EditText scrolls it into view, then back after the resize (0 → 24.76 → 0).

Fix: while a height update is pending, scrollTo caps the scroll at the value it will have after the resize. It works that out from the height limit Yoga passes to measure(): 0 if the text fits under it, or the final offset if the text crosses it. Once the input is at maxHeight, behaviour is unchanged.

Test Plan

On Android 15+ (tested on Pixel 9, API 36), with an input that has maxHeight and logs onScroll:

  • type into or empty a line, and press Enter with the component below maxHeight: no scroll events
  • press Enter so that the content crosses maxHeight: one event with the final offset

Android screenshot baselines were updated too for affected tests.

Screenshots / Videos

You can see offsets are now properly returned. The only edge case is the first returned offset when we exceed the maxHeight content height, but it just double-emits two very similar values which (according to Claude) is expected and not a big deal. It's not like 0 -> 24 -> 0 jump, which was happening before.

Screen.Recording.2026-11-13.at.15.21.50.mov

Compatibility

OS Implemented
iOS ❌
Android ✅
Web ❌

Checklist

  • E2E tests are passing
  • Required E2E tests have been added (if applicable)

Mateusz Kiełb and others added 30 commits October 26, 2026 12:42
@szydlovsky
szydlovsky requested review from exploIF and a balanced review from Copilot November 13, 2026 16:22
@szydlovsky
szydlovsky changed the base branch from main to @relextm19/scroll-position November 13, 2026 16:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Android scroll-cap races and stale limits can cause visual jumps or prevent scrolling needed to keep the cursor visible, while iOS offset caching can suppress valid scroll events after a listener is reattached.

2 open issues
What changed in this PR

This PR addresses Android input measurement and scrolling jumps during auto-growth. It also adds cross-platform onScroll events, documentation, and example coverage.

Changes:

  • Align Android measurements with locale-preferred line heights and cap scrolling while height updates are pending.
  • Expose scroll offsets on Android, iOS, and web, and avoid scroll-triggered iOS relayouts.
  • Add scroll-event tests and example instrumentation.
File Description
src/​web/​EnrichedTextInput.tsx Forward web scroll offsets to the callback.
src/​types.ts Define public scroll event types and prop.
src/​spec/​EnrichedTextInputNativeComponent.ts Declare native scroll events and emission flag.
src/​native/​EnrichedTextInput.tsx Connect the public callback to native props.
src/​index.tsx Export the scroll payload type.
src/​index.native.tsx Export the native scroll payload type.
ios/​EnrichedTextInputView.mm Emit iOS scroll offset events.
ios/​enrichedInputTextView/​EnrichedInputTextView.mm Limit relayout scheduling to size changes.
docs/​docs/​api-reference/​enriched-text-input.md Document onScroll and its payload.
apps/​example/​src/​screens/​TestScreen.tsx Display settled scroll offsets for tests.
apps/​example/​src/​screens/​DevScreen.tsx Log input scroll events.
apps/​example/​src/​hooks/​useEditorState.ts Add a shared scroll logger.
apps/​example/​src/​components/​ModalShell.tsx Use padding-based keyboard avoidance.
apps/​example/​src/​App.tsx Pass the scroll-display launch option.
apps/​example/​ios/​EnrichedTextInputExample/​SceneDelegate.swift Forward the iOS test launch argument.
apps/​example/​android/​app/​src/​main/​java/​swmansion/​enriched/​example/​MainActivity.kt Forward the Android test launch argument.
apps/​example-web/​src/​testScreens/​TestScroll.tsx Add a scroll-event test screen.
apps/​example-web/​src/​RouteSelector.tsx Register the scroll test route.
apps/​example-web/​src/​App.tsx Log web scroll events.
android/​src/​main/​java/​com/​swmansion/​enriched/​textinput/​MeasurementStore.kt Match line metrics and cache growth limits.
android/​src/​main/​java/​com/​swmansion/​enriched/​textinput/​events/​OnInputScrollEvent.kt Define the Android scroll event payload.
android/​src/​main/​java/​com/​swmansion/​enriched/​textinput/​EnrichedTextInputViewManager.kt Register scroll events and acknowledge state mounts.
android/​src/​main/​java/​com/​swmansion/​enriched/​textinput/​EnrichedTextInputViewLayoutManager.kt Mark height recalculations as pending.
android/​src/​main/​java/​com/​swmansion/​enriched/​textinput/​EnrichedTextInputView.kt Cap pending-resize scrolling and emit offsets.
.playwright/​tests/​scroll.spec.ts Test web scroll events and offset direction.
.maestro/​enrichedInput/​flows/​on_scroll_event.yaml Test native scroll offset changes.
.maestro/​enrichedInput/​flows/​image_inside_list_parsing.yaml Use a repository-hosted test image.

Review effort: Balanced

@szydlovsky
szydlovsky force-pushed the @szydlovsky/fix-android-measurement-jumps branch from b654cda to 06d8dd9 Compare November 20, 2026 14:35
@exploIF

exploIF commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

How does it work in React Native TextInput? Visually, layout jumping is the same

@exploIF exploIF left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had many issues in the past if it comes to input layout. There are no recent errors reported, so I'm not sure if it really makes sense to introduce potential regressions. What are the pros of this changes?

@exploIF

exploIF commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

In the description there is a note

The PR also fixes some annoying test script issues I ran into when testing the changes (keyboard coming back to autocorrect + autocapitalize and script not detecting running emulator port properly).

Unfortunately, I don't see any such changes

@szydlovsky

Copy link
Copy Markdown
Collaborator Author

@exploIF About the note with test script cases; I moved it to a different, already merged PR and removed from this one - forgot to change the description here 🙏

@szydlovsky

szydlovsky commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator Author

How does it work in React Native TextInput? Visually, layout jumping is the same

RN TextInput has the same issue so we're essentially improving over it. Here's onScroll offset values recorded in identically set up inputs:

Step RN TextInput Ours (with fix)
Enter on line 1 0.76 → 24.76 → 0.76 none
Backspace in a line until empty 0 → 0.76 none
Enter before maxHeight 0 → 25.90 → 0.76, every time none
Further Enters beyond maxHeight 45.33, 70.48 45.33, 70.48

We had many issues in the past if it comes to input layout. There are no recent errors reported, so I'm not sure if it really makes sense to introduce potential regressions. What are the pros of this changes?

The main motivation is the new onScroll event - with these layout jumps in place, any UI whose layout or dimensions depend on the scroll offset will erratically jump/resize too.

If it comes to any potential regressions; all the Android E2E tests pass + I made a few manual sweeps + I made Argent go over the app and seek any abnormalities for quite some time - I'm pretty confident we're not risking much.

About the benefits; except for the onScroll working as intended:

  • we get rid of the visual flickers that accompanied the measurement jumps
  • we're now perfectly synced with EditText in terms of sizing; before, empty lines had some fake offset (the magic 0.76 number) due to differences between our measurement and the actual native component height.

On which SDKs have you tested those changes?

I've just had Argent run pre- and post- fix apps built on APIs 34 and 36 and both work as expected - the tiny discrepancies in offsets are caused by changes the API35 brought when measuring lines:

Case API 36 before fix API 36 with fix API 34 before fix API 34 with fix
Enter below maxHeight 25.90 → 0.76, every time none 24.76 → 0, every time none
Typing into an empty line 0.76 → 0 none 0.76 → 0 none
Further Enters 45.33, 70.48 45.33, 70.48 44.19, 69.33 44.19, 69.33

Base automatically changed from @relextm19/scroll-position to main November 25, 2026 16:42
@szydlovsky
szydlovsky merged commit d9b93f7 into main Nov 25, 2026
8 checks passed
@szydlovsky
szydlovsky deleted the @szydlovsky/fix-android-measurement-jumps branch November 25, 2026 16:52
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.

4 participants