java.lang.IllegalStateException: focus search returned a view that wasn’t able to take focus!
Man has this error been a thorn in my side for a few days. My new Android app Adventure Sheet was getting errors when clicking next/done in editors for text or numeric keyboards.
I tried a bunch of different suggestions, including adding a hidden editor field that would just immediately remove focus (this still caused an error on some devices). I looked into a override for the renderer but thought it was a little overkill, and also something that should be fixed in the Xamarin Forms source not by an override I write. Finally I got a small amount of progress by setting the TabIndex property on editors in the xaml to prevent the crash, but not all my screens had a final editor and the app would still crash if done/next was clicked on the last editor.
At last after stumbling upon some Microsoft documentation I discovered that at least for now using tab index and this simple line added to any visual element that should not take focus will prevent the error and allow for a loop back to the start of the tab index:
IsTabStop=”False”
Eg:
<Switch IsTabStop=”False” IsToggled=”False”></Switch>
It would appear that the not regarding supported controls not being tab focusable on every platform should be taken more seriously and IsTabStop should probably be set to false more often than not. However, since I do not use a lot of different visual elements in my app and I don’t have a ton of free time to test every control listed in the documentation, but here is what I have so far:
Visual Elements that currently should have IsTabStop set to false for the broadest support:
- Button
- Switch
- Adbanner (my custom renderer for AdMob ads)
Visual Elements that support IsTabStop set to true (default value):
- Editor
- Label (automatically skipped)
- Picker