Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[A]Fix potential crash when calling ClearFocus in SearchBarRenderer #700

Merged
merged 1 commit into from Jan 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 16 additions & 4 deletions Xamarin.Forms.Platform.Android/Renderers/SearchBarRenderer.cs
Expand Up @@ -33,7 +33,7 @@ bool SearchView.IOnQueryTextListener.OnQueryTextChange(string newText)
bool SearchView.IOnQueryTextListener.OnQueryTextSubmit(string query)
{
((ISearchBarController)Element).OnSearchButtonPressed();
Control.ClearFocus();
ClearFocus(Control);
return true;
}

Expand Down Expand Up @@ -67,7 +67,7 @@ protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
_inputType = InputTypes.ClassText | InputTypes.TextFlagAutoComplete | InputTypes.TextFlagNoSuggestions;
}

searchView.ClearFocus();
ClearFocus(searchView);
UpdatePlaceholder();
UpdateText();
UpdateEnabled();
Expand Down Expand Up @@ -113,7 +113,7 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
internal override void OnNativeFocusChanged(bool hasFocus)
{
if (hasFocus && !Element.IsEnabled)
Control.ClearFocus();
ClearFocus(Control);
}

void UpdateAlignment()
Expand Down Expand Up @@ -148,14 +148,26 @@ void UpdateEnabled()
SearchView control = Control;
if (!model.IsEnabled)
{
control.ClearFocus();
ClearFocus(control);
// removes cursor in SearchView
control.SetInputType(InputTypes.Null);
}
else
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upstream

}
}

void UpdateFont()
{
_editText = _editText ?? Control.GetChildrenOfType<EditText>().FirstOrDefault();
Expand Down