Skip to content

fix(wasm): iPad soft-keyboard focus (dismiss, LostFocus, bring-into-view) - #23890

Merged
ajpinedam merged 8 commits into
unoplatform:masterfrom
ajpinedam:dev/anpi/fix.wasm.softkeyboard.focus
Aug 10, 2026
Merged

ajpinedam merged 8 commits into
unoplatform:masterfrom
ajpinedam:dev/anpi/fix.wasm.softkeyboard.focus

Conversation

@ajpinedam

@ajpinedam ajpinedam commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: Associated with an internal tracking issue (customer-reported).

PR Type:

🐞 Bugfix

What changed? 🚀

Fixes focus-related bugs specific to the Skia WebAssembly head on touch devices (iPad Safari/Chrome). They stem from the single shared, invisible <input id="uno-input"> that is positioned over the one <canvas> used for all text entry. None of them affect WinUI or the native (non-Skia) heads.

1. Soft keyboard opens on a TextBox tap, then immediately dismisses itself.
Touch browsers synthesize a trailing compatibility mousedown after a tap's focus change; it lands on the non-focusable canvas and its default action blurs the just-focused #uno-input, closing the keyboard. Uno already preventDefaults pointer events, but per the Pointer Events spec that does not suppress the synthesized mouse-compatibility events. Fix: a one-shot, touch/pen-scoped guard that swallows the single trailing canvas mousedown/click following the input's focusin (armed on focus, disarmed on the next pointerdown). Desktop mouse is unaffected — there mousedown precedes focus, so the guard never arms.

2. LostFocus never fires when the keyboard is dismissed this way.
Focus was driven one-way (managed → native): nothing listened for the browser blurring #uno-input on its own, so FocusManager stayed out of sync and LostFocus never fired. Fix: a blur listener on the input reports genuine, browser-initiated blurs to a new OnNativeBlur export, which calls TextBox.Unfocus() — the same terminal focus-clearing path the iOS and native WASM heads already use. Managed-initiated blurs are suppressed so a focus switch never clears the wrong control.

3. A focused field near the bottom is not scrolled above the keyboard.
The Skia WASM head had no InputPane producer — nothing ever set InputPane.OccludedRect, so the shared bring-into-view path never ran. Fix: a visualViewport listener computes the keyboard occlusion (gated on the invisible input being focused, so browser-chrome resizes don't count) and feeds InputPane.OccludedRect, mirroring the iOS/Android heads. This also makes InputPane.Showing/Hiding fire on this head, matching the other platforms.

Follow-up fixes from on-device testing feedback

4. Bring-into-view could leave the focused field partially (or fully) behind the keyboard — e.g. inside a side panel with its own ScrollViewer.
Three compounding defects in the shared occlusion-padding path (__SKIA__; the consuming code, not the new producer):

  • ScrollContentPresenter.Pad reduced the padding by the space below the focused element inside the viewport, so the minimal BringIntoView landed the element exactly that gap below the keyboard top. It now pads the full occluded overlap — which is what the Android head has always done (it passed Rect.Empty), so the parameter is gone and both platforms share one behavior.
  • The OnBringIntoViewRequested path subtracted _occludedRectPadding.Bottom from the viewport on __SKIA__ as well as __ANDROID__. On Skia the padding flows through ScrollViewer.Padding → presenter Margin, which ViewportHeight already reflects — subtracting again double-counted. Now Android-only (there the padding goes to the native view, invisible to managed layout).
  • On WASM the occlusion streams per animation frame, and the old restore-then-re-pad cycle measured a viewport whose layout still reflected the previous pad — converging to roughly half the needed padding. InputPane.skia.cs now keeps the pad applied across re-pads of the same presenter (Pad compensates internally), settles layout before measuring and before StartBringIntoView, and only restores when the target presenter changes or the pane hides. Restoring now puts back the app's original Padding instead of resetting it to zero.

5. Tapping another TextBox while the keyboard is up dismissed it.
Moving focus A→B destroyed the shared input (EndEntry(A) blurred + removed it) before StartEntry(B) recreated it — a "nothing editable focused" gap that commits the soft-keyboard dismissal on iPadOS. Reworked lifecycle:

  • focus() now retargets the existing input in place (value, inputmode, enterkeyhint) when the element kind matches — it never blurs, so the keyboard stays up.
  • When the kind must change (input ↔ textarea ↔ password, or an IME composition is active), the new element is focused before the old one is removed — an editable-to-editable handoff with no gap.
  • A managed blur (EndEntry) defers the real detach by one microtask; the focus() of a TextBox-to-TextBox move supersedes it. Genuine dismissals (tap outside, Done key) detach as before.
  • Blur now carries the owning TextBox's handle so a stale blur can never tear down a successor's entry session, and the retarget path re-arms the fix-1 guard (it fires no focusin).

Drive-by: updateSize() set the invisible input's width/height without px units, so the styles were ignored; the input rect is what Safari uses as its scroll-reveal target, so it now gets real dimensions.

Validation

  • Compiles clean: the runtime head and the full SamplesApp.Skia.WebAssembly.Browser app (TS + C#).
  • Fix 4 is device-independent and covered by runtime tests on Skia Desktop, verified fail-before/pass-after by running them against the pre-fix code:
    • Given_InputPane.When_Focused_TextBox_Has_Content_Below_Then_Scrolled_Above_Occlusion — the reported side-panel geometry distilled: old code left the field ~38 px under the keyboard; now asserts the field rect ends fully above the occlusion.
    • Given_InputPane.When_OccludedRect_Cleared_Then_ScrollViewer_Padding_Restored — app-set ScrollViewer.Padding survives an occlusion cycle (additive pad, restore on clear).
    • Given_InputPane.When_OccludedRect_Set_Then_Focused_TextBox_Scrolled_Into_View strengthened with the same geometric assertion.
    • Regression sweep: all 55 Given_ScrollViewer/Given_ScrollViewer_Zoom runtime tests pass (outside keyboard scenarios the removed subtraction was always zero).
  • Fix 5: full Given_TextBox runtime suite executed on Skia WASM in a browser — 148 passed / 27 skipped, and the only 2 failures are sub-pixel rounding assertions that fail byte-identically on a baseline build without these changes (pre-existing, environment-specific).
  • Manual on-device sample SoftKeyboardFocusTests (GotFocus/LostFocus counters, live OccludedRect readout, bottom field). Fixes 1, 2, and 5, and the on-device occlusion math, reproduce only on a real iPad, so final device validation there is still required — this PR is a draft pending that.
  • Android note: Pad keeps Android's existing full-intersection behavior; the additive padding and restore-on-clear are shared improvements validated by code review + the Skia runtime tests (no Android runtime run here).

Known remaining item from the same feedback (tracked for a follow-up): Safari auto-pans its visual viewport to reveal the DOM input when it sits below the keyboard, which can fight the XAML-level scroll (most visible with the taller multi-tab Safari header) and let the whole page pan instead of inner ScrollViewers.

PR Checklist ✅

@github-actions github-actions Bot added platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform area/automation Categorizes an issue or PR as relevant to project automation labels Jul 27, 2026
@unodevops

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot added platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform area/skia ✏️ Categorizes an issue or PR as relevant to Skia labels Aug 3, 2026
@ajpinedam
ajpinedam marked this pull request as ready for review August 3, 2026 17:52
Copilot AI lite review requested due to automatic review settings August 3, 2026 17:52

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.

Pull request overview

This PR addresses iPad (touch) soft-keyboard focus issues in the Skia WebAssembly (browser) head by (1) preventing touch-synthesized compatibility mouse events from blurring the shared invisible input, (2) syncing browser-initiated native blurs back to managed focus to ensure LostFocus fires, and (3) producing InputPane.OccludedRect from visualViewport changes so the existing Skia bring-into-view consumer path activates on WASM.

Changes:

  • Reworked Skia/Android occlusion padding so it composes with app padding and avoids double-counting in bring-into-view calculations.
  • Added a visualViewport-based occlusion producer in the browser head and a blur → managed unfocus bridge for browser-initiated blurs.
  • Added Skia runtime tests for occlusion-driven bring-into-view + padding restoration, plus a manual SamplesApp page for on-device iPad validation.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.OccludedPadding.cs Changes Pad to base calculations on the unpadded viewport and to restore/apply padding without wiping app-set padding.
src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.mux.cs Limits occlusion-height viewport adjustment to Android to avoid double-counting on Skia where padding flows into Margin.
src/Uno.UI/UI/ViewManagement/InputPane/InputPane.skia.cs Refines padding lifecycle so it’s restored only when the target presenter changes and avoids restore/re-pad during keyboard animation.
src/Uno.UI/UI/ViewManagement/InputPane/InputPane.Android.cs Updates call site for the new ScrollContentPresenter.Pad(Rect) signature.
src/Uno.UI.RuntimeTests/Tests/Windows_UI_ViewManagement/Given_InputPane.cs Adds Skia runtime coverage for occlusion-driven bring-into-view and padding restoration behavior.
src/Uno.UI.Runtime.Skia.WebAssembly.Browser/UI/Xaml/Window/WebAssemblyWindowWrapper.cs Adds a JS-fed occlusion callback that sets InputPane.OccludedRect in managed code.
src/Uno.UI.Runtime.Skia.WebAssembly.Browser/UI/Xaml/Controls/TextBox/BrowserInvisibleTextBoxViewExtension.cs Adds a native blur callback to resync managed focus and updates blur interop to carry a handle.
src/Uno.UI.Runtime.Skia.WebAssembly.Browser/ts/Runtime/WebAssemblyWindowWrapper.ts Hooks visualViewport to compute/report keyboard occlusion and switches canvas id to a shared constant.
src/Uno.UI.Runtime.Skia.WebAssembly.Browser/ts/Runtime/UnoDomIds.ts Introduces a single source of truth for well-known DOM ids used by the browser head.
src/Uno.UI.Runtime.Skia.WebAssembly.Browser/ts/Runtime/BrowserInvisibleTextBoxViewExtension.ts Implements trailing click guard, browser-initiated blur reporting, and safer shared-input retargeting/detach sequencing.
src/SamplesApp/SamplesApp.Samples/Windows_UI_ViewManagement/SoftKeyboardFocusTests.xaml.cs Adds a manual on-device validation page wiring focus counters and InputPane events.
src/SamplesApp/SamplesApp.Samples/Windows_UI_ViewManagement/SoftKeyboardFocusTests.xaml Adds the XAML UI for the manual validation page.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@unodevops

Copy link
Copy Markdown
Contributor

Copilot AI review requested due to automatic review settings August 3, 2026 18:57

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.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.

Suppressed comments (3)

src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.OccludedPadding.cs:49

  • Pad currently returns a new disposable on every call, which becomes per-frame garbage while the occlusion changes. If this call is not starting a new padding session, return Disposable.Empty so callers can keep/dispose only the first restore token for the session.
		return Disposable.Create(RestoreOccludedRectPadding);

src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.OccludedPadding.cs:23

  • Pad may be called repeatedly while keyboard occlusion animates. To avoid allocating a new Disposable.Create(...) each time, capture whether this call is starting a new padding session (i.e., no prior occluded padding applied) so later you can return Disposable.Empty on subsequent updates.

This issue also appears on line 49 of the same file.

#endif
		// A previous Pad can still be applied (the keyboard occlusion changes while it animates);
		// it shrinks this presenter, so always reason on the unpadded viewport.
		var viewPortSize = new Size(ActualWidth, ActualHeight + _occludedRectPadding.Bottom);
		var viewPortRect = new Rect(viewPortPoint, viewPortSize);

src/Uno.UI/UI/ViewManagement/InputPane/InputPane.skia.cs:85

  • With Pad potentially returning Disposable.Empty on repeated occlusion updates (to avoid per-frame allocations), this assignment should not overwrite the original restore token. Otherwise, disposing on focus move/pane hide may not restore padding.
			scp.UpdateLayout();
			_padScrollContentPresenter = scp.Pad(OccludedRect);
			_paddedScrollContentPresenter = scp;

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 225557 found UI Test snapshots differences: skia-linux-screenshots: 57, skia-windows-screenshots: 2348, wasm: 11

Details
  • skia-linux-screenshots: 57 changed over 2348

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • Examples.png-dark
    • Examples.png
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • Focus_FocusVisual_Properties.png-dark
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • ContextRequested.png-dark
    • ContextRequested.png
    • ClipboardTests.png-dark
    • Buttons.png-dark
    • Buttons.png
    • ImageIconPage.png-dark
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
  • skia-windows-screenshots: 2348 changed over 2394

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AppBar_KeyBoard.png
    • Accessibility_ScreenReader.png
    • AndroidWindowInsets.png-dark
    • AppBarToggleButtonTest.png-dark
    • AppBar_KeyBoard.png-dark
    • AndroidWindowInsets.png
    • AppBarButtonWithIconTest.png
    • AppWindowFeatures.png-dark
    • ArcSegment.png-dark
    • Attributed_text_FontSize_Changing.png-dark
    • AppXamlDefinedResources.png-dark
    • ApplicationViewSpanningRectsPage.png
    • AppWindowClosing.png-dark
    • Attributed_text_Supserscript.png
    • Arrange_Performance01.png
    • AutoBorderStretchwithtopmargin.png-dark
    • AutoBorderStretchwithleftmargin.png
    • AuthenticationBroker_Demo.png
    • AppWindowPresenters.png
    • AppWindowPositionAndSize.png
  • wasm: 11 changed over 1076

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Minimal
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Ogg_Extension
    • UITests.Windows_UI_Xaml_Media_Animation.ColorAnimation_Background
    • UITests.Uno_Web.Http.CookieManagerTests
    • UITests.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_NavigationProperties
    • UITests.Windows_UI_Xaml_Controls.CalendarView.CalendarView_Theming
    • SamplesApp.Wasm.Windows_UI_Xaml_Controls.ListView.ListView_IsSelected
    • UITests.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests.WinUIExpanderPage
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListViewSelectedItems
    • Uno.UI.Samples.Content.UITests.WebView.WebView_AnchorNavigation
    • SamplesApp.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_EnableDevTools

Copilot AI review requested due to automatic review settings August 4, 2026 19:04

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.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/Uno.UI/UI/ViewManagement/InputPane/InputPane.skia.cs:85

  • EnsureFocusedElementInViewPartial can be invoked frequently while the on-screen keyboard animates (OccludedRect changes per visualViewport frame on WASM). Calling scp.UpdateLayout() here forces a synchronous layout pass on every update and may cause jank on low-power/touch devices. Consider avoiding UpdateLayout() on the hot path (e.g., rely on the existing dispatcher hop before StartBringIntoView, or gate UpdateLayout() behind a condition/throttle so it only runs when the presenter’s layout is known stale).
			// Deliberately no restore-then-re-pad for the same presenter: the occlusion is reported
			// continuously while the keyboard animates, and restoring first would make Pad measure a
			// viewport whose layout still reflects the previous padding. Pad compensates internally.
			scp.UpdateLayout();
			_padScrollContentPresenter = scp.Pad(OccludedRect);
			_paddedScrollContentPresenter = scp;

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 225789 found UI Test snapshots differences: skia-linux-screenshots: 57, skia-windows-screenshots: 2348, wasm: 11

Details
  • skia-linux-screenshots: 57 changed over 2348

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
    • Gamepad_Enumeration.png
    • ContextRequested.png-dark
    • ContextRequested.png
    • Examples.png-dark
    • Examples.png
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • ClipboardTests.png-dark
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • Focus_FocusVisual_Properties.png-dark
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • DisplayInformation.png-dark
    • DropDownButtonPage.png-dark
  • skia-windows-screenshots: 2348 changed over 2394

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedIconPage.png
    • ApplicationViewSizing.png-dark
    • AppWindowPresenters.png-dark
    • Attributed_text_FontSize_Changing.png
    • AutomationPropertiesExtensions_Role.png
    • AutoSuggestBox_Reason.png-dark
    • Basics.png-dark
    • BezierSegment.png-dark
    • BitmapImage_vs_SvgImageSource.png-dark
    • BitmapImage_vs_SvgImageSource.png
    • Border_CornerRadius_Alignments.png
    • Border_CornerRadius_Binding.png-dark
    • Border_Simple.png-dark
    • Border_Simple.png
    • Border_With_ScaleTransform.png-dark
    • Border_With_ScaleTransform.png
    • Button_UseUWPDefaultStyles.png-dark
    • Button_UseUWPDefaultStyles.png
    • Capture.png-dark
    • Capture.png
  • wasm: 11 changed over 1076

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • UITests.Windows_UI_Xaml_Controls.CalendarView.CalendarView_Theming
    • UITests.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests.WinUIExpanderPage
    • UITests.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_NavigationProperties
    • UITests.Windows_UI_Xaml_Media_Animation.ColorAnimation_Background
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Ogg_Extension
    • SamplesApp.Wasm.Windows_UI_Xaml_Controls.ListView.ListView_IsSelected
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Minimal
    • Uno.UI.Samples.Content.UITests.WebView.WebView_AnchorNavigation
    • SamplesApp.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_EnableDevTools
    • UITests.Uno_Web.Http.CookieManagerTests
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListViewSelectedItems

@mergify

mergify Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@ajpinedam
ajpinedam merged commit 83effab into unoplatform:master Aug 10, 2026
49 checks passed
@ajpinedam
ajpinedam deleted the dev/anpi/fix.wasm.softkeyboard.focus branch August 10, 2026 16:13
@ajpinedam

Copy link
Copy Markdown
Contributor Author

@Mergifyio backport release/stable/6.7

@mergify

mergify Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

backport release/stable/6.7

✅ Backports have been created

Details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation area/skia ✏️ Categorizes an issue or PR as relevant to Skia platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants