summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2017-01-21 04:52:26 -0800
committerRui Marinho <me@ruimarinho.net>2017-01-21 12:52:26 +0000
commit0282aae3992bacc8ecfe41cefae921dab0493201 (patch)
tree3ee93e63e49b11dd1a8fc709ed1a2cd28a4e2b2b /Xamarin.Forms.Platform.Android
parent5f9e5e56bba9535d9fa9bba5d8c37041405acba8 (diff)
downloadxamarin-forms-0282aae3992bacc8ecfe41cefae921dab0493201.tar.gz
xamarin-forms-0282aae3992bacc8ecfe41cefae921dab0493201.tar.bz2
xamarin-forms-0282aae3992bacc8ecfe41cefae921dab0493201.zip
[A]Fix potential crash when calling ClearFocus in SearchBarRenderer (#700)
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r--Xamarin.Forms.Platform.Android/Renderers/SearchBarRenderer.cs20
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();