Skip to content

fix(safearea): claim the input pane occlusion that SoftInput handles - #1679

Merged
Xiaoy312 merged 2 commits into
mainfrom
dev/xygu/20261019/fix-safearea-layout-cycle
Oct 20, 2026
Merged

Xiaoy312 merged 2 commits into
mainfrom
dev/xygu/20261019/fix-safearea-layout-cycle

Conversation

@Xiaoy312

Copy link
Copy Markdown
Contributor

GitHub Issue (If applicable): closes unoplatform/uno#25529

PR Type

  • Bugfix

What is the current behavior?

On Android, typing the first character with the soft keyboard into a TextBox at the bottom of a page throws a LayoutCycleException when the page uses SafeArea the usual way: VisibleBounds in Margin mode on the root, and SoftInput on the content above the keyboard. It regressed with the input pane root viewport in Uno (unoplatform/uno#24947, backported in unoplatform/uno#25032).

Both sides handle the same keyboard occlusion:

  1. The SoftInput SafeArea pads the focused TextBox above the keyboard.
  2. Uno doesn't know it, so it also scrolls the root content up, to keep the TextBox plus WinUI's 20px margin above the keyboard (about 10px here).
  3. The root VisibleBounds SafeArea measures its element shifted into the navigation bar inset (TransformToVisual(null) includes the shift), and reduces its bottom margin. That value comes from float32 transforms, and ApplyInsets compares exactly, so every layout pass applies a margin one float ulp off the previous one, and the layout never settles. TextBoxView calls UpdateLayout() on each text change, so the first keystroke hits the layout cycle limit.

Even without the crash, the shift pushes the top of the page under the status bar while the keyboard is up.

What is the new behavior?

  • A SoftInput SafeArea claims the occlusion it handles: when the focused element is within it, it sets InputPaneVisibilityEventArgs.EnsuredFocusedElementInView from its existing Showing/Hiding handler (the InputPane reads the flag after raising them), so Uno doesn't also shift the root. Since that flag also skips Uno's bring-into-view of the focused element, which inner scrollers still need, SafeArea makes the same request (with the 20px margin) once its padding is laid out. Focused elements outside any SoftInput SafeArea (e.g. in a flyout) are left to Uno, as before.
  • The insets are snapped to physical pixels (XamlRoot.RasterizationScale) before they are compared and applied, so sub-pixel noise from transformed bounds can no longer relayout on every pass.

PR Checklist

Please check if your PR fulfills the following requirements:

Other information

Testing

  • Desktop (Windows, Skia): the SafeAreaTests runtime tests pass, including the new ones (claiming only for a focused descendant of a SoftInput SafeArea, the issue's drifting margin values being applied once, and the pixel snapping).

  • Android (Pixel 8, Gboard, Skia renderer): the same two commits, cherry-picked onto servicing/10.0 (10.0.0-dev.7) and used through a package override on Uno.Sdk 6.8.0-dev.66, compared with the stock 10.0.0-dev.7:

    Layout 10.0.0-dev.7 With this PR
    The issue's layout (composer TextBox) Crashes on the first keystroke Works, no shift
    Same, with an AutoSuggestBox composer Crashes on the first keystroke Works, suggestions shown above the box
    TextBox in a ScrollViewer inside the SoftInput area Works Works, scrolled above the keyboard with the 20px margin

    It wasn't run on Uno 7 itself; the change has the same effect there, as the root viewport is the same on master.

  • Not covered: iOS and WebAssembly, where the same root viewport shift and SafeArea code exist (the issue couldn't make it loop there).

Backport: servicing/10.0 needs a small conflict resolution in the snapping commit, as OnInsetsApplied takes the owner there.

Separately (Uno, not addressed here): a TextBox in a flyout anchored near the bottom of the page stays behind the keyboard on 6.8.0-dev.66, with or without this change: the root viewport only brings the page content into view, not the popups.

🤖 Generated with Claude Code

A SoftInput SafeArea pads the focused element above the input pane, but
the framework didn't know it, and also scrolled the root content above
the pane. SafeArea then measured its content shifted into the window
insets, and the two adjustments never settled: typing in a TextBox at
the bottom of the page threw a LayoutCycleException on Android
(unoplatform/uno#25529).

Set EnsuredFocusedElementInView when the focused element is within a
SoftInput SafeArea, and bring it into view within the inner scrollers
once the padding is laid out, as the framework would have.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Xiaoy312
Xiaoy312 requested review from ajpinedam and kazo0 October 19, 2026 21:50
@github-actions

Copy link
Copy Markdown

@Xiaoy312

Xiaoy312 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

@Mergifyio backport servicing/10.0
edit: this is for the [email protected] lineage which the uno inducing PR was also backported to

@mergify

mergify Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

backport servicing/10.0

✅ Backports have been created

Details

Cherry-pick of 6496c40 has failed:

On branch mergify/bp/servicing/10.0/pr-1679
Your branch is ahead of 'origin/servicing/10.0' by 1 commit.
  (use "git push" to publish your local commits)

You are currently cherry-picking commit 6496c40.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   src/Uno.Toolkit.RuntimeTests/Tests/SafeAreaTests.cs

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   src/Uno.Toolkit.UI/Controls/SafeArea/SafeArea.cs

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

The insets are computed from transformed bounds, in float precision, and
applied from LayoutUpdated whenever they differ from the current ones.
A fractional offset of the content can then make them differ by a float
ulp on every pass, and the layout never settles.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions

Copy link
Copy Markdown

1 similar comment
@github-actions

Copy link
Copy Markdown

@mergify

mergify Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@Xiaoy312
Xiaoy312 merged commit 0b4bd3c into main Oct 20, 2026
26 checks passed
@Xiaoy312
Xiaoy312 deleted the dev/xygu/20261019/fix-safearea-layout-cycle branch October 20, 2026 16:51
Xiaoy312 added a commit that referenced this pull request Oct 28, 2026
- SafeArea.cs: drop the conflict markers the cherry-pick of the
  pixel-snapping commit left in; keep SnapToPhysicalPixels and
  servicing's OnInsetsApplied(FrameworkElement owner, ...) signature,
  which ApplyInsets already calls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Xiaoy312 added a commit that referenced this pull request Oct 28, 2026
…r-1679

fix(safearea): claim the input pane occlusion that SoftInput handles (backport #1679)
kazo0 added a commit that referenced this pull request Oct 28, 2026
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Xiaotian Gu <[email protected]>
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.

[Android] LayoutCycleException on the first keystroke with Uno Toolkit's SafeArea since the input pane root viewport

2 participants