/// <summary> /// Retrieves the suggestions from locator and displays them in a tableview below the search field. /// </summary> private async Task GetSuggestionsFromLocatorAsync() { // Get the suggestions var suggestions = await _viewModel.GetLocationSuggestionsAsync(_homeLocationSearchBar.Text); // Only show the floors tableview if the buildings in view have more than one floor if (suggestions?.Any() ?? false) { // Show the tableview with autosuggestions and populate it _autosuggestionsTableView.Hidden = false; // Unsubscribe from events to prevent memory leak if (_suggestionSource != null) { _suggestionSource.TableRowSelected -= TableSource_TableRowSelected; } // Create new table source and use it _suggestionSource = new AutosuggestionsTableSource(suggestions, false); _suggestionSource.TableRowSelected += TableSource_TableRowSelected; _autosuggestionsTableView.Source = _suggestionSource; _autosuggestionsTableView.ReloadData(); } else { _autosuggestionsTableView.Hidden = true; } }
internal LocationSearchCard(MapViewModel viewModel) { _viewModel = viewModel; _suggestionSource = new AutosuggestionsTableSource(null, true); _autoSuggestionsTableView = new SelfSizedTableView { TranslatesAutoresizingMaskIntoConstraints = false, Hidden = true, // must be hidden by default for voiceover BackgroundColor = UIColor.Clear, SeparatorColor = UIColor.SystemGrayColor, Source = _suggestionSource, RowHeight = UITableView.AutomaticDimension, EstimatedRowHeight = 50 }; _searchBar = new UISearchBar { TranslatesAutoresizingMaskIntoConstraints = false, BackgroundImage = new UIImage(), Placeholder = "LocationSearchBarPlaceholder".Localize(), SearchBarStyle = UISearchBarStyle.Minimal, ShowsCancelButton = false, TintColor = ApplicationTheme.ActionBackgroundColor }; _headerLabel = new UILabel { TranslatesAutoresizingMaskIntoConstraints = false, TextColor = ApplicationTheme.ForegroundColor, Font = ApplicationTheme.HeaderFont }; AddSubviews(_headerLabel, _searchBar, _autoSuggestionsTableView); _headerHeightConstraint = _headerLabel.HeightAnchor.ConstraintGreaterThanOrEqualTo(40); _tableviewBottomConstraint = _autoSuggestionsTableView.BottomAnchor.ConstraintLessThanOrEqualTo(BottomAnchor, -ApplicationTheme.Margin * 2); NSLayoutConstraint.ActivateConstraints(new[] { _headerLabel.LeadingAnchor.ConstraintEqualTo(LeadingAnchor, ApplicationTheme.Margin), _headerLabel.TrailingAnchor.ConstraintEqualTo(TrailingAnchor, -ApplicationTheme.Margin), _headerLabel.TopAnchor.ConstraintEqualTo(TopAnchor, ApplicationTheme.Margin), _searchBar.LeadingAnchor.ConstraintEqualTo(_headerLabel.LeadingAnchor), _searchBar.TrailingAnchor.ConstraintEqualTo(_headerLabel.TrailingAnchor), _searchBar.TopAnchor.ConstraintEqualTo(_headerLabel.BottomAnchor), _searchBar.HeightAnchor.ConstraintEqualTo(56), _autoSuggestionsTableView.TopAnchor.ConstraintEqualTo(_searchBar.BottomAnchor), _autoSuggestionsTableView.LeadingAnchor.ConstraintEqualTo(_headerLabel.LeadingAnchor), _autoSuggestionsTableView.TrailingAnchor.ConstraintEqualTo(_headerLabel.TrailingAnchor), BottomAnchor.ConstraintGreaterThanOrEqualTo(_searchBar.BottomAnchor, ApplicationTheme.Margin), }); _searchBar.TextChanged += Search_textChanged; _searchBar.SearchButtonClicked += Search_buttonClicked; _searchBar.OnEditingStarted += Search_EditingStarted; _searchBar.CancelButtonClicked += Search_CancelClicked; _suggestionSource.TableRowSelected += SuggestionSource_RowSelected; _viewModel.PropertyChanged += ViewModel_PropertyChanged; }