diff options
author | Jason Smith <jason.smith@xamarin.com> | 2017-01-18 11:02:14 -0800 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2017-01-31 10:02:07 -0800 |
commit | 2a019ed256cd3432c6840953d5e4624ebb2383f3 (patch) | |
tree | a2578fa8aa5b8c862b934984eeda08c3017edfe8 | |
parent | 8265645a8e7bbe5a8a26ccf93da2f4b2d5e972d6 (diff) | |
download | xamarin-forms-2a019ed256cd3432c6840953d5e4624ebb2383f3.tar.gz xamarin-forms-2a019ed256cd3432c6840953d5e4624ebb2383f3.tar.bz2 xamarin-forms-2a019ed256cd3432c6840953d5e4624ebb2383f3.zip |
[A]Fix potential crash when calling ClearFocus in SearchBarRenderer
-rw-r--r-- | Xamarin.Forms.Platform.Android/Renderers/SearchBarRenderer.cs | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/Xamarin.Forms.Platform.Android/Renderers/SearchBarRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/SearchBarRenderer.cs index 468710ca..48bcf576 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/SearchBarRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/SearchBarRenderer.cs @@ -33,7 +33,7 @@ namespace Xamarin.Forms.Platform.Android bool SearchView.IOnQueryTextListener.OnQueryTextSubmit(string query) { ((ISearchBarController)Element).OnSearchButtonPressed(); - Control.ClearFocus(); + ClearFocus(Control); return true; } @@ -67,7 +67,7 @@ namespace Xamarin.Forms.Platform.Android _inputType = InputTypes.ClassText | InputTypes.TextFlagAutoComplete | InputTypes.TextFlagNoSuggestions; } - searchView.ClearFocus(); + ClearFocus(searchView); UpdatePlaceholder(); UpdateText(); UpdateEnabled(); @@ -113,7 +113,7 @@ namespace Xamarin.Forms.Platform.Android internal override void OnNativeFocusChanged(bool hasFocus) { if (hasFocus && !Element.IsEnabled) - Control.ClearFocus(); + ClearFocus(Control); } void UpdateAlignment() @@ -148,7 +148,7 @@ namespace Xamarin.Forms.Platform.Android SearchView control = Control; if (!model.IsEnabled) { - control.ClearFocus(); + ClearFocus(control); // removes cursor in SearchView control.SetInputType(InputTypes.Null); } @@ -156,6 +156,18 @@ namespace Xamarin.Forms.Platform.Android control.SetInputType(_inputType); } + void ClearFocus(SearchView view) + { + try + { + view.ClearFocus(); + } + catch (Java.Lang.UnsupportedOperationException) + { + // silently catch these as they happen in the previewer due to some bugs in upstread android + } + } + void UpdateFont() { _editText = _editText ?? Control.GetChildrenOfType<EditText>().FirstOrDefault(); |