dismissing keyboard problems

I have an app that takes all input from a laser barcode scanner.
Therefore I always want to hide the keyboard popup.

I use an EntryRenderer that seems to do the trick.
I also used a DependencyService to dismiss the keyboard.

However since upgrading Xamarin Forms from 3.4 to 4.2 things are a bit wierd.

The EntryRenderer seems to work perfectly find on my login screen Entry. I set focus OnAppearing and it dismisses the keyboard no problems.

However, on a screen about 3 levels down into my app, I use the exact same Entry control and the keyboard will not dismiss via the renderer.
I set the focus, and it calls the renderer code to dismiss, but then when the screen loads it shows the keyboard.
Using DependencyService seems to no longer work as an override.

1) why does the renderer fail on one screen but not the other?
2) why does my DependencyService fail to work at all? Code:
var imm = InputMethodManager.FromContext(MainActivity.Instance);
imm.HideSoftInputFromWindow(MainActivity.Instance.Window.DecorView.WindowToken, HideSoftInputFlags.NotAlways);

Posts

  • mytrilifemytrilife Member ✭✭

    Ok, I think I know the problem and I fixed it with a hack... but wondering if there is a better way.

    The Entry box on my login screen is on the first Page in my app.
    The focus is set, EntryRenderer OnPropertyChanging code calls the hide keyboard, done.

    The Entry boxes on my other screen are 3 pages deep in the navigation stack.
    The focus is set, EntryRenderer OnPropertyChangingcode calls the hide keyboard, but then.... it focuses again and the keyboard pops.
    I created a hack where I call the MessagingCenter with a call to my HideKeyboard method.
    My service that subscribes to this does:

    await Task.Delay(50)
    var imm = InputMethodManager.FromContext(MainActivity.Instance);
    imm.HideSoftInputFromWindow(MainActivity.Instance.Window.DecorView.WindowToken, HideSoftInputFlags.NotAlways);

    waiting the 50ms is enough for the page to be done loading (?) and dismissing keyboard the last thing to be called.

    It works, but not sure why I have to deploy this hack... I should be able to call the dismiss keyboard as the very last thing on my page load.

Sign In or Register to comment.