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
21.87k stars 1.68k forks source link

[Android] Page appears to receive focus #14692

Open rachelkang opened 1 year ago

rachelkang commented 1 year ago

Description

Page appears to receive keyboard focus when it should not

Video demonstrates the outcome of repeatedly hitting the Tab Key. The highlighted area represents the object receiving keyboard focus, and can be seen toggling between the whole page and the button:

https://user-images.githubusercontent.com/21988533/233414540-a8ee40cf-232b-4787-a04f-4697f540954e.mp4

Steps to Reproduce

  1. Create a File > New > .NET MAUI app
  2. Deploy on Android
  3. Press Tab key to navigate

Link to public reproduction project repository

https://github.com/dotnet/maui

Version with bug

8.0 previews

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android API 33

Did you find any workaround?

No response

Relevant log output

No response

rachelkang commented 1 year ago

This only happens with Shell. Does not appear to be an issue when Shell is not being used Issue is present in as far back as .NET 6

XamlTest commented 8 months ago

Verified this on Visual Studio Enterprise 17.9.0 Preview 1(8.0.3). Repro on Android 14.0-API34 with Maui template: MauiApp1.zip

ghost commented 7 months ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

EssentialNRG commented 3 weeks ago

I can confirm this is still an issue with .NET 8.0.302. It's only happening when using Shell. It also happens on iOS when a bluetooth keyboard (or barcode scanner) is attached.

Ahmed-Hassan-GWS commented 3 weeks ago

I can confirm this is still an issue with .NET 8.0.302. It's only happening when using Shell. It also happens on iOS when a bluetooth keyboard (or barcode scanner) is attached.

This is inaccurate. I just upgraded to .NET 8.0.302 / 8.0.61 SR6.1 and, unfortunately, it still happens with NavigationPagein my org's project. I was able to reproduce in Android 8 and 11.

In fact, this issue appears to happen to any Layout -derived class too, including Gridand StackLayout.

For these layouts, I've tried using VisualStateManager to modify the behavior when "Focused", no dice. Also, I've tried using other approaches, like a custom handler, but no good - although the colors would change and merely "darkens/shades" the view a bit.

Further, was using a LayoutHandler.Mapper.AppendToMapping entry to modify the PlatformView.BackgroundTintList = Android.Content.Res.ColorStateList.ValueOf(_grid_.BackgroundColor.ToAndroid()), but no go.

Using the following properties was just as futile:

LayoutHandler.Mapper.AppendToMapping(... (h, v) =>
{
  ...
  h.PlatformView.Focusable = false;
  h.PlatformView.FocusedByDefault = false;
  h.PlatformView.FocusableInTouchMode = false;
});

@PureWeen, or anyone else, we could really use your valuable input on this one. If you have a workaround, it would be greatly appreciated if you can share it!

PureWeen commented 1 week ago

If you disable hot reload do you still see the same issue?