AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.29k stars 2.19k forks source link

Textboxes Receive Focus During Scroll on Touch Devices in ScrollViewer #16991

Open JanSkvaril opened 1 week ago

JanSkvaril commented 1 week ago

Describe the bug

While working on an Android app, we discovered an issue with the ScrollViewer and input controls (e.g., textboxes). The input controls are being focused when dragging the screen to scroll. In larger forms, this is especially unpleasant, as users often accidentally press other textboxes/inputs while scrolling.

To Reproduce

A simple way to reproduce this issue is to add a large number of textboxes to the ScrollViewer:

<ScrollViewer>
      <StackPanel Name="TextboxContainer">
          <!--  Textboxes  -->
      </StackPanel>
 </ScrollViewer>
public MainView()
{
    InitializeComponent();

    for (int i = 0; i < 100; i++)
    {
        TextboxContainer.Children.Add(new TextBox() { Text="Textbox" + i});
    }
}

I am also attaching a minimal reproduction project and a video demonstrating the issue. In this project, it is impossible to scroll down without activating the textbox. AvaloniaScrollInputs.zip

https://github.com/user-attachments/assets/4e74bd13-d8ec-4f4c-8553-ca10143c8e5d

Expected behavior

The textboxes should not be focused while scrolling on a touch device.

Avalonia version

11.1.3

OS

Android

Additional context

No response

emmauss commented 3 days ago

We switch focus to an input element on pointer pressed. This is expected behavior on desktop, but on mobile it causes focus to change on any gesture start. There are few controls/widgets that are actually focusable by touch on mobile, and focus is expected to change only when a gesture is complete(like the hold gesture) or when the pointer is released.

JanSkvaril commented 20 hours ago

Thank you for the clarification. Is there a possible solution or workaround? Are there any plans to improve this behavior in the future?