dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.21k stars 1.75k forks source link

[MAUI] D17 page when click on some empty space, the editor 2 is still focused #17953

Open Ying-6 opened 1 year ago

Ying-6 commented 1 year ago

Description

D17 page when click on some empty space, the editor 2 is still focused on ios, maccatalyst and android target.

Steps to Reproduce

  1. Deploy https://devdiv.visualstudio.com/Pkgs/_git/VS.TestAssets.Xaml?path=/Assets/Projects/ManualMauiTests to iOS simulator or device.
  2. Click or tap on test ‘D17’.
  3. Focus editor 2 below and then click on some empty space.

Actual result: The editor is still focused after clicking the empty space. UIElement

Expected results: The editor should unfocus.

Link to public reproduction project repository

https://github.com/rachelkang/recipeSearch

Microsoft.Maui.Controls 8.0.0-nightly.9331+sha.6aac924e89-azdo.8456294 .NET SDK: 8.0.100-rc.1.23463.5

Version with bug

8.0.0-nightly.9331

Is this a regression from previous behavior?

Not a regression, The issue also repro on 8.0.0-rc.1.9171

Affected platforms

iOS, Android, macOS

PureWeen commented 1 year ago

@japarson @rachelkang @jsuarezruiz this test needs to be rewritten slightly to account for this behavior change

https://github.com/dotnet/maui/pull/16530

Almis90 commented 9 months ago

Any news on this?

ninachen03 commented 8 months ago

Verified this issue with Visual Studio 17.10.0 Preview 1. Can repro Android & iOS platform with 8.0.10-nightly.10196

MattePozzy commented 5 months ago

Hi, any news about this? I can reproduce it with Visual Studio 17.9.7 and MAUI 8.0.40 on real Android and iOS device.

Here a repo.

kubaflo commented 2 weeks ago

On Android you can override DispatchTouchEvent in the MainActivity like this

public override bool DispatchTouchEvent(Android.Views.MotionEvent e)
{
    if(e.Action == Android.Views.MotionEventActions.Down)
    {
        var v = CurrentFocus;
        if(v is EditText || v is TextView)
        {
            Rect outRect = new Rect();
            v.GetGlobalVisibleRect(outRect);
            if(!outRect.Contains((int)e.RawX, (int)e.RawY))
            {
                v.ClearFocus();
            }
        }
    }
    return base.DispatchTouchEvent(e);
}