Xamarin.Forms icon indicating copy to clipboard operation
Xamarin.Forms copied to clipboard

[Bug] Keyboard not hiding while focusing the entry programmatically.

Open SanthiyaArulsamy opened this issue 1 year ago • 3 comments

Description

Keyboard not hiding while focusing the entry programmatically even ShowSoftInputOnFocus as false.

I want to hide the keyboard when attaching the hard keyboard so I tried to disable the soft keyboard always when the hard keyboard attached.

Steps to Reproduce

  1. Create a CustomEntry.
  2. In the custom entry renderer, set the SetSoftInputMode as StateAlwaysHidden and disable the ShowSoftInputOnFocus
  3. In the button click, call the entry.Focus method

Expected Behavior

Soft keyboard should not show while focusing the entry control.

Actual Behavior

Keyboard showing while focusing the entry control. If I manually focus the entry I am

Basic Information

  • Version with issue: Xamarin forms : 5.0.0.0.2196
    • Android: Target Framework 13
  • NuGet Packages: Xamarin forms : 5.0.0.0.2196
  • Affected Devices:

Environment

Visual Studio Enterprise 2022 for Mac Version 17.6.6 (build 408) Installation UUID: 9c46f919-7695-4fee-86e5-0429a28b92df

Xamarin Designer Version: 17.6.3.9 Hash: 2648399ae8 Branch: remotes/origin/d17-6 Build date: 2023-10-23 17:41:00 UTC

Xamarin.Android Version: 13.2.2.0 (Visual Studio Enterprise) Commit: xamarin-android/d17-5/45b0e14 Android SDK: /Users/localuser/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: 12.1 (API level 32) 10.0 (API level 29) 13.0 (API level 33)

Android SDK Manager Version: 17.6.0.50 Hash: a715dca Branch: HEAD Build date: 2023-10-23 17:41:04 UTC

Operating System Mac OS X 12.5.0 Darwin 21.6.0 Darwin Kernel Version 21.6.0 Sat Jun 18 17:07:22 PDT 2022 root:xnu-8020.140.41~1/RELEASE_ARM64_T6000 arm64

protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);

            if (this.Resources.Configuration.HardKeyboardHidden == HardKeyboardHidden.No)
            {
                var window = ((Activity)currentcontext).Window;
                window.SetSoftInputMode(SoftInput.StateAlwaysHidden);
                if (Control != null)
                {
                    Control.ShowSoftInputOnFocus = false;
                }
            }
            else
            {
                var window = ((Activity)currentcontext).Window;
                window.SetSoftInputMode(SoftInput.StateVisible);
            }
        }

 void Button_Clicked(System.Object sender, System.EventArgs e)
        {
            entry.Focus();
        }


Screenshots

  1. Screenshot 2023-11-29 at 4 27 37 PM
  2. Screenshot 2023-11-29 at 4 28 10 PM
  3. Screenshot 2023-11-29 at 4 45 16 PM

Workaround

I couldn't find any workaround

Please suggest me how to hide the soft keyboard while focusing the entry programmatically.

SanthiyaArulsamy avatar Nov 29 '23 11:11 SanthiyaArulsamy

Please check in the latest available Xamarin.Forms version if this issue still persists, 2196 is a few versions back.

jfversluis avatar Nov 29 '23 13:11 jfversluis

Hi @jfversluis In the latest version also I am facing the same issue

SanthiyaArulsamy avatar Nov 30 '23 08:11 SanthiyaArulsamy

@jfversluis Can you please provide any suggestion on this?

SanthiyaArulsamy avatar Dec 11 '23 11:12 SanthiyaArulsamy