xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] Unable to unfocus entry #15420

Open woutermeuwis opened 2 years ago

woutermeuwis commented 2 years ago

Description

It seems impossible to unfocus an entry on certain devices with the latest Xamarin.Forms release. Whenever I try to unfocus an entry, either by tapping out of its bounds, or by calling Entry.Unfocus() from code, the application auto-focuses the first entry on the page.

My application has certain scenarios where an entry gaining focus has attached behaviors, and these get triggered all the time now. This prevents us from using the latest version of Xamarin.Forms.

Selecting a different entry still works for some reason, however, unfocussing completely fails.

Steps to Reproduce

  1. Select one of the entries.
  2. Either tap outside of the entry bounds, or use the button to trigger the .Unfocus() code

Expected Behavior

The application should release focus on the entries.

Actual Behavior

The first entry gains focus.

Basic Information

Environment

Show/Hide Visual Studio info ``` === Visual Studio Community 2019 for Mac === Version 8.10.23 (build 7) Installation UUID: 5fd5aae6-2b07-43d4-8696-f8975ecb9104 GTK+ 2.24.23 (Raleigh theme) Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638) Package version: 612000174 === Mono Framework MDK === Runtime: Mono 6.12.0.174 (2020-02/adf1bc4335d) (64-bit) Package version: 612000174 === Roslyn (Language Service) === 3.10.0-4.21269.26+029847714208ebe49668667c60ea5b0a294e0fcb === NuGet === Version: 5.9.0.7134 === .NET SDK (x64) === SDK: /usr/local/share/dotnet/sdk/6.0.105/Sdks SDK Versions: 6.0.105 6.0.103 6.0.102 6.0.101 6.0.100 5.0.408 5.0.406 5.0.405 5.0.404 5.0.403 5.0.402 5.0.400 5.0.302 5.0.301 5.0.203 5.0.202 5.0.201 5.0.103 5.0.102 3.1.419 3.1.417 3.1.416 3.1.415 3.1.414 3.1.412 3.1.411 3.1.410 3.1.409 3.1.408 3.1.407 3.1.406 3.1.405 MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks === .NET Core Runtime === Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 6.0.5 6.0.3 6.0.2 6.0.1 6.0.0 5.0.17 5.0.15 5.0.14 5.0.13 5.0.12 5.0.11 5.0.9 5.0.8 5.0.7 5.0.6 5.0.5 5.0.4 5.0.3 5.0.2 3.1.25 3.1.23 3.1.22 3.1.21 3.1.20 3.1.18 3.1.17 3.1.16 3.1.15 3.1.14 3.1.13 3.1.12 3.1.11 === .NET Core 3.1 SDK === SDK: 3.1.419 === .NET 5.0 SDK === SDK: 5.0.408 === Xamarin.Profiler === Version: 1.7.0.0 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler === Updater === Version: 11 === Apple Developer Tools === Xcode 13.3 (20102) Build 13E113 === Xamarin.Mac === Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version. === Xamarin.iOS === Version: 15.8.0.3 (Visual Studio Community) Hash: eb7f8ed35 Branch: xcode13.3 Build date: 2022-03-30 03:16:09-0400 === Xamarin Designer === Version: 16.11.0.60 Hash: 56f9b80b0 Branch: remotes/origin/d16-11 Build date: 2021-12-15 01:44:16 UTC === Xamarin.Android === Version: 12.2.4.3 (Visual Studio Community) Commit: xamarin-android/d17-1/fc1125e Android SDK: /Users/woutermeuwis/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: 4.4 (API level 19) 4.4.87 (API level 20) 5.0 (API level 21) 5.1 (API level 22) 6.0 (API level 23) 7.0 (API level 24) 7.1 (API level 25) 8.0 (API level 26) 8.1 (API level 27) SDK Tools Version: 26.1.1 SDK Platform Tools Version: 31.0.3 SDK Build Tools Version: 31.0.0 rc1 Build Information: Mono: adf1bc4 Java.Interop: xamarin/java.interop/d17-1@7ac33610 ProGuard: Guardsquare/proguard/v7.0.1@912d149 SQLite: xamarin/sqlite/3.37.1@0893b3b Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-1@db125a7 === Eclipse Temurin JDK === Java SDK: Not Found === Android SDK Manager === Version: 16.10.0.13 Hash: 1b81df5 Branch: remotes/origin/d16-10 Build date: 2021-11-12 00:17:32 UTC === Android Device Manager === Version: 16.10.0.15 Hash: 89dcc0b Branch: remotes/origin/d16-10 Build date: 2021-11-12 00:17:52 UTC === Build Information === Release ID: 810230007 Git revision: 7f00a2236acfde86feffbab606eefae32a9adbb3 Build date: 2022-05-05 09:46:09-04 Build branch: release-8.10 === Operating System === Mac OS X 12.3.1 Darwin 21.4.0 Darwin Kernel Version 21.4.0 Fri Mar 18 00:45:05 PDT 2022 root:xnu-8020.101.4~15/RELEASE_X86_64 x86_64 ```

Reproduction Link

EntryFocusReproduction.zip

RonnyBansemer commented 2 years ago

I can confirm this issue and also want to extend it. Not just the Entry element is affected. When changing a page the first focusable element is kept in focus the whole time what leads to horrible side effects. The app is slow and becomes unusable. I can reproduce the issue using our production apps using XF 5.0.0.2478 on all android versions below 9.0. XF 5.0.0.2401 works well.

jfversluis commented 2 years ago

Would you be able to look at bullet point number 2 here: https://github.com/xamarin/Xamarin.Forms/releases/tag/release-5.0.0-sr11

Add that to your code and let me know if that fixes it? Thanks!

malikberkane commented 2 years ago

Would you be able to look at bullet point number 2 here: https://github.com/xamarin/Xamarin.Forms/releases/tag/release-5.0.0-sr11

Add that to your code and let me know if that fixes it? Thanks!

Bullet point 2 didn't fix the issue, solution for me was to rollback to version 5.0.0.2401 !

stefandb1995 commented 2 years ago

Hi,

Any news on this/possible workaround someone has figured out? As stated before, bullet point 2 doesn't work, and only rolling back to 2401 solves this. I'm not able to replicate on Android 12 but can consistently replicate on Android 8. Below is an example stack trace if that helps with anything.

0x1 in App2.MainPage.Entry_Focused at source\repos\App2\App2\App2\MainPage.xaml.cs:20,13 C# 0x13 in Xamarin.Forms.VisualElement.OnFocused at D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:997,23 C# 0x14 in Xamarin.Forms.VisualElement.OnIsFocusedPropertyChanged at D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:1067,5 C# 0x12E in Xamarin.Forms.BindableObject.SetValueActual at D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:512,5 C# 0x17C in Xamarin.Forms.BindableObject.SetValueCore at D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:446,5 C# 0xA in Xamarin.Forms.BindableObject.SetValueCore at D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:379,7 C# 0x4 in Xamarin.Forms.Element.SetValueFromRenderer at D:\a\1\s\Xamarin.Forms.Core\Element.cs:254,4 C# 0xC4 in Xamarin.Forms.Platform.Android.ViewRenderer<Xamarin.Forms.Entry,Xamarin.Forms.Platform.Android.FormsEditText>.Android.Views.View.IOnFocusChangeListener.OnFocusChange at D:\a\1\s\Xamarin.Forms.Platform.Android\ViewRenderer.cs:127,4 C# 0x12 in Android.Views.View.IOnFocusChangeListenerInvoker.n_OnFocusChange_Landroid_view_View_Z at /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-31/mcw/Android.Views.View.cs:3020,5 C# 0x1D in Android.Runtime.DynamicMethodNameCounter.53 C# 0x1A in Java.Interop.NativeMethods.java_interop_jnienv_call_nonvirtual_boolean_method_a C# 0x79 in Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualBooleanMethod C# 0x65 in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualBooleanMethod C# 0x4B in Android.Views.View.RequestFocus at /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-31/mcw/Android.Views.View.cs:22716,5 C# 0x3 in Xamarin.Forms.Platform.Android.FormsEditTextBase.<>n__0 C# 0x12 in Xamarin.Forms.Platform.Android.FormsEditTextBase. at D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\FormsEditText.cs:71,70 C# 0x3F in Xamarin.Forms.Platform.Android.DescendantFocusToggler.RequestFocus at D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\DescendantFocusToggler.cs:31,4 C# 0x1D in Xamarin.Forms.Platform.Android.FormsEditTextBase.Xamarin.Forms.Platform.Android.IDescendantFocusToggler.RequestFocus at D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\FormsEditText.cs:65,4 C# 0x29 in Xamarin.Forms.Platform.Android.FormsEditTextBase.RequestFocus at D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\FormsEditText.cs:71,4 C# 0x14 in Android.Views.View.n_RequestFocus_ILandroid_graphicsRect at /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-31/mcw/Android.Views.View.cs:22699,4 C# 0x1D in Android.Runtime.DynamicMethodNameCounter.58 C# 0x19 in Java.Interop.NativeMethods.java_interop_jnienv_call_nonvirtual_void_method_a C# 0x79 in Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod C# 0x65 in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod C# 0x12 in Android.Views.View.ClearFocus at /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-31/mcw/Android.Views.View.cs:15448,5 C# 0x58 in Xamarin.Forms.Platform.Android.EntryRendererBase.Android.Widget.TextView.IOnEditorActionListener.OnEditorAction at D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\EntryRenderer.cs:113,6 C# 0x1E in Android.Widget.TextView.IOnEditorActionListenerInvoker.n_OnEditorAction_Landroid_widget_TextView_ILandroid_viewKeyEvent at /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-31/mcw/Android.Widget.TextView.cs:188,5 C# 0x23 in Android.Runtime.DynamicMethodNameCounter.57 C#

Transis-Felipe commented 2 years ago

I'm having this problem too. Only happens with older devices.

alex-rrb commented 2 years ago

Have the same issue on Stratus-C5 (Android 11), Custom tablet (Android 7.1.2), iPhone 12 mini (iOS 15.7)

PTancek commented 2 years ago

Same issue on our side. It happens on every device running android 8.1 or less. We don't see the problem with newer android versions.

Xamarin Forms : Latest stable 5.0.0.2515

The issue is also only present on the root navigation page. We are using flyout navigation and if the root detail page has an Entry, you can not remove it's foucs. Also the OnBackButtonPressed event does not get called in this case. If however you push another page on top of this one, the "unfocus" functionality and OnBackButtonPressed event work as expected.

phunkeler commented 1 year ago

We are also experiencing this issue with Xamarin.Forms 5.0.0.2515 using:

Apart from rolling-back versions, we have yet to find a suitable workaround.

jfversluis commented 1 year ago

If anyone is still watching this, could you try to call Forms.SetFlags("Disable_Accessibility_Experimental"); before Forms.Init(this, savedInstanceState); in your MainActivity.cs?

For me it seems to resolve the issue. That will help me track down in what area to look for the proper fix also.

WilliamWatterson86 commented 1 year ago

@jfversluis - I tried your suggestion and it does seem to fix my issue too. Are there any issues with disabling Accessibility like this?

dhayzen commented 1 year ago

@jfversluis - I also tried your suggestion and it has fixed my entry Unfocus issue too.

xPudda commented 1 year ago

I was having the same issue, but the problem was caused with having no entry in the page and first element was focused. Pressing enter was firing the click / press event on the element. Adding the @jfversluis suggestion fixed the problem.

Hackmodford commented 1 year ago

I am also experiencing this issue. I confirmed if I downgrade to 5.0.0.2401 it works again.

stefandb1995 commented 1 year ago

Have you tried @jfversluis fixed for this? Setting Forms.SetFlags("Disable_Accessibility_Experimental"); before Forms.Init() in MainActivity.cs solved our problem.

Hackmodford commented 1 year ago

@stefandb1995 I did on 5.0.0.2478 and it didn't work. I will be trying each new version to see if it works in a different one.

I didn't end up trying the other versions because they broke the CarouselView for me. I just reverted to the version that worked for Android and used the Sharpnado.CollectionView package.