Repository navigation
Description
Current behavior 🐛
On Android, typing the first character with the soft keyboard into a TextBox at the bottom of a page crashes the app with a LayoutCycleException. This happens when the page uses Uno Toolkit's SafeArea the usual way: VisibleBounds in Margin mode on the root, and SoftInput on the content above the keyboard.
android.runtime.JavaProxyThrowable: [Microsoft.UI.Xaml.LayoutCycleException]: Layout cycle detected. For more information, see https://aka.platform.uno/layout-cycle
at Microsoft.UI.Xaml.UIElement.InnerUpdateLayout
at Microsoft.UI.Xaml.UIElement.UpdateLayout
at Microsoft.UI.Xaml.Controls.TextBoxView.UpdateDisplayBlockText
at Microsoft.UI.Xaml.Controls.TextBoxView.SetTextNative
at Microsoft.UI.Xaml.Controls.TextBox.OnTextChanged
...
at Microsoft.UI.Xaml.Controls.TextBox.set_Text
at Microsoft.UI.Xaml.Controls.TextBox.ProcessTextInput
at Uno.UI.Runtime.Skia.Android.TextInputConnection.EndBatchEdit
at Android.Views.InputMethods.BaseInputConnection.n_EndBatchEdit
...
at com.android.internal.view.IInputConnectionWrapper.executeMessage
It is a regression from the input pane root viewport, #24947 on master and #25032 in servicing/6.8:
| Uno.Sdk | Uno.WinUI | Uno.Toolkit.WinUI | Result |
|---|---|---|---|
| 6.8.0-dev.60 | 6.8.0-dev.212 | 10.0.0-dev.5 | Works |
| 6.8.0-dev.66 | 6.8.0-dev.222 | 10.0.0-dev.7 | Crashes on the first keystroke |
| 7.0.0-dev.81 | 7.0.0-dev.2347 (master 9e17b827bf) |
11.0.0-dev.143 | Crashes on the first keystroke (the stack goes through TextBoxCore.ITextBoxViewHost.UpdateLayout) |
What loops. With the layout cycle tracing on, the element invalidated on every pass is the root Grid with SafeArea.Insets="VisibleBounds" in Margin mode. The invalidation comes from SafeArea, which reapplies the margin from its LayoutUpdated handler:
at Microsoft.UI.Xaml.FrameworkElement.set_Margin(Thickness value)
at Uno.Toolkit.UI.SafeArea.SafeAreaDetails.ApplyInsets(Thickness insets)
at Uno.Toolkit.UI.SafeArea.SafeAreaDetails.UpdateInsets(Boolean forceUpdate)
at Uno.Toolkit.UI.SafeArea.SafeAreaDetails.OnOwnerLayoutUpdated(Object sender, Object e)
at Uno.UI.Xaml.Core.EventManager.RaiseLayoutUpdated()
at Microsoft.UI.Xaml.UIElement.UpdateLayout()
at Microsoft.UI.Xaml.Controls.TextBoxView.UpdateDisplayBlockText(String text)
The margins SafeArea applies on successive passes, from its debug log in one run (the navigation bar inset is 48):
ApplyInsets=[Thickness: 0-52.727272033691406-0-38.1768798828125], Mode=Margin
ApplyInsets=[Thickness: 0-52.727272033691406-0-38.17681884765625], Mode=Margin
ApplyInsets=[Thickness: 0-52.727272033691406-0-38.1767578125], Mode=Margin
ApplyInsets=[Thickness: 0-52.727272033691406-0-38.17669677734375], Mode=Margin
...
My reading of it:
- Once
SoftInputhas padded the composer above the keyboard, the root viewport still shifts the window content up by the bring-into-view margin that is left. In this run that was 9.818px, a fraction of a pixel, and it shows asXamlIslandRootarrangingWindowChromeaty = -9.818181991577148. - The root
SafeAreasees its element extend that far into the navigation bar inset and reduces the bottom margin to 48 - 9.818. It measures the element withTransformToVisual(null), whose float precision rounds the result differently on every pass: each value above differs from the previous one by one float ulp at that magnitude, about 6e-5. SafeAreaapplies the margin whenever it isn't exactly equal to the current one (ApplyInsets:!owner.Margin.Equals(insets)), so every pass invalidates the measure again and the layout never settles.TextBoxView.UpdateDisplayBlockTextcallsUpdateLayout()on each text change, so the first keystroke runs into the 250-pass limit.
Without the shift, the computed bottom inset is at least the window inset, and it is clamped to that exact value, so the rounding noise never reaches the margin. That is why 6.8.0-dev.212 is fine.
Expected behavior 🎯
Typing works, and the composer stays above the keyboard as it does on 6.8.0-dev.212.
How to reproduce it (as minimally and precisely as possible) 🔬
-
Create an app from the template, Android only, with the Skia renderer and the Toolkit (
dotnet new unoapp -preset blank -platforms android -renderer skia -toolkit), on Uno.Sdk 6.8.0-dev.66 or 7.0.0-dev.81. For 7.0, the AndroidApplicationneeds the newCreateHost()override. -
Use this as
MainPage:<Page x:Class="SafeAreaRepro.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:utu="using:Uno.Toolkit.UI"> <Grid utu:SafeArea.Insets="VisibleBounds" utu:SafeArea.Mode="Margin"> <Grid RowDefinitions="*,Auto" utu:SafeArea.Insets="SoftInput"> <ScrollViewer> <StackPanel x:Name="Messages" Spacing="8" Padding="16" /> </ScrollViewer> <Border Grid.Row="1" Padding="12,10"> <TextBox PlaceholderText="Type a message" /> </Border> </Grid> </Grid> </Page>
The code-behind fills
Messageswith 30TextBlocks. The composer's padding matters, because it is what leaves a fractional shift afterSoftInputhas done its part. -
Run it on an Android emulator (Pixel 5, API 31, Gboard) or a device. Tap the TextBox, then tap a letter on the on-screen keyboard: the app crashes.
Tapping a key on the soft keyboard goes through the IME's input connection (EndBatchEdit, sometimes via SetComposingText). adb shell input text sends plain key events and doesn't crash.
Workaround 🛠️
When the app keeps focused fields above the keyboard itself (with SafeArea SoftInput), tell the input pane, so that the root viewport doesn't shift the content as well:
var inputPane = InputPane.GetForCurrentView();
inputPane.Showing += (_, e) => e.EnsuredFocusedElementInView = true;
inputPane.Hiding += (_, e) => e.EnsuredFocusedElementInView = true;This removes the crash on both 6.8.0-dev.222 and 7.0.0-dev.2347.
Affected platforms 📱💻🖥️
Android (Skia renderer). The same shift and the same SafeArea code are there on iOS and WebAssembly, but I could only make it loop on Android: a WebAssembly build with a simulated keyboard occlusion didn't.
Uno.Sdk version (and other relevant versions) 📦
- Regressed: Uno.Sdk 6.8.0-dev.66 (Uno.WinUI 6.8.0-dev.222, Uno.Toolkit.WinUI 10.0.0-dev.7) and Uno.Sdk 7.0.0-dev.81 (Uno.WinUI 7.0.0-dev.2347, Uno.Toolkit.WinUI 11.0.0-dev.143)
- Last good: Uno.Sdk 6.8.0-dev.60 (Uno.WinUI 6.8.0-dev.212)
net10.0-android, Skia renderer- Reproduced with the repro above on an Android emulator (Pixel 5, API 31)
- Also crashes on a physical device with Android 13 (API 33), in an app with the same layout
IDE version 🧑💻
dotnet CLI
Anything else we need to know? 💬
The two sides could each fix it; filing here since the shift is what started it.
- Toolkit:
SafeAreacould ignore inset changes below a small tolerance (or round the insets) before applying them. They come from transformed bounds and are applied fromLayoutUpdated, so an exact comparison can keep relayouting on any fractional offset. When it handlesSoftInput, it could also setEnsuredFocusedElementInView, since the occlusion is then taken care of. - Uno: maybe the root viewport shouldn't add a sub-pixel shift on top of a layout that already reacts to the occlusion.
SafeAreais the documented way to handle the soft keyboard, so the two meet in most apps that use the Toolkit.
Activity
agneszitte commentedon Oct 19, 2026
@mikernet thank you so much for the issue!
@Xiaoy312 made a PR for it unoplatform/uno.toolkit.ui#1679 that is currently in review
fix(safearea): claim the input pane occlusion that SoftInput handles