This is a migrated thread and some comments may be shown as answers.

Custom Search Causing Control to Freeze

1 Answer 80 Views
AutoCompleteView
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 23 Jan 2019, 09:26 PM
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;
        }

1 Answer, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 28 Jan 2019, 12:44 PM
Hello Andrew,

I have tried to reproduce the observed by you freezing using the provided description and code-snippets, but without any luck - it seems everything is working as expected on my side. Attached you can find the sample I have used for my research. Could you please, check it and let me know if I haven't missed something? Modifying and sending me back the sample, so that the freezing you are experiencing could be reproduced will also be of great help for my further investigation.

I am looking forward to hearing from you.

Regards,
Nasko
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
AutoCompleteView
Asked by
Andrew
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Share this question
or