We are experiencing an issue implementing a custom search on the control. We use MVVM, and have had to adapt the control to get everything wired up. However, on iOS devices only (no emulators) we frequently see the control lock the app up. It doesn'tcrash, just freezes and is unresponsive (I've let it wait for over an hour and it does not unfreeze). Below is the XAML, the code-behind and the method on the ViewModel for the search. Any help would be appreciated, as if we cannot solve the freezing we will have to make use of entry controls instead.
The XAML:
<
telerikInput:RadAutoCompleteView
x:Name
=
"radACV"
BackgroundColor
=
"White"
CornerRadius
=
"5"
HeightRequest
=
"30"
TextChanged
=
"radACV_TextChanged"
SuggestionItemSelected
=
"radACV_SuggestionItemSelected"
TextSearchPath
=
"Name"
SearchThreshold
=
"3"
SuggestMode
=
"Suggest"
CompletionMode
=
"Contains"
DisplayMode
=
"Plain"
ShowSuggestionView
=
"True"
SuggestionViewHeight
=
"200"
>
<
telerikInput:RadAutoCompleteView.LoadingTemplate
>
<
DataTemplate
>
<
StackLayout
Orientation
=
"Horizontal"
HorizontalOptions
=
"Center"
Margin
=
"0, 20, 0, 20"
>
<
Label
Text
=
"Searching ... "
FontSize
=
"16"
TextColor
=
"#8E8E93"
/>
<
telerikPrimitives:RadBusyIndicator
HeightRequest
=
"24"
WidthRequest
=
"24"
IsBusy
=
"True"
VerticalOptions
=
"Start"
AnimationContentColor
=
"Accent"
AnimationType
=
"Animation9"
>
</
telerikPrimitives:RadBusyIndicator
>
</
StackLayout
>
</
DataTemplate
>
</
telerikInput:RadAutoCompleteView.LoadingTemplate
>
</
telerikInput:RadAutoCompleteView
>
The code-behind:
private
string
currentSearchText;
private
string
previousSearchText;
private
bool
isRemoteSearchRunning;
private
bool
isSelected =
false
;
private
async
void
radACV_TextChanged(
object
sender, TextChangedEventArgs e)
{
if
(!isSelected)
{
var autoCompleteView = (RadAutoCompleteView)sender;
var vm = (DocSearchViewModel)BindingContext;
currentSearchText = e.NewTextValue ??
string
.Empty;
previousSearchText = e.OldTextValue ??
string
.Empty;
if
(currentSearchText.Length >= autoCompleteView.SearchThreshold && !isRemoteSearchRunning)
{
isRemoteSearchRunning =
true
;
if
(autoCompleteView.ItemsSource ==
null
)
//if the item source is null, get new
{
autoCompleteView.ItemsSource = await vm.LoadItems(currentSearchText);
}
else
if
(!currentSearchText.Contains(previousSearchText))
//if the new search text is not a narrowing of the previous text, get new
{
autoCompleteView.ItemsSource = await vm.LoadItems(currentSearchText);
}
isRemoteSearchRunning =
false
;
}
else
if
(e.NewTextValue.Length == 0)
{
autoCompleteView.ItemsSource =
null
;
vm.Selected =
null
;
}
else
{
autoCompleteView.ItemsSource =
null
;
}
}
else
{
isSelected =
false
;
}
}
private
void
radACV_SuggestionItemSelected(
object
sender, SuggestionItemSelectedEventArgs e)
{
var autoCompleteView = (RadAutoCompleteView)sender;
isSelected =
true
;
var selectedItem = (ItemModel)e.DataItem;
var vm = (ViewModel)BindingContext;
vm.Selected = selectedItem;
}
The ViewModel Search function:
public
async Task<List<ItemModel>> LoadItems(
string
search)
{
var items =
new
List<ItemModel>();
try
{
IsBusy =
true
;
items = await _dataService.GetItems(search);
}
catch
(Exception e)
{
ReportingService.LogAppError(e);
}
finally
{
IsBusy =
false
;
}
return
items;
}