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; }
internal RouteResultCard(MapViewModel viewModel) { _viewModel = viewModel; _stopsTable = new SelfSizedTableView { TranslatesAutoresizingMaskIntoConstraints = false, ScrollEnabled = false, BackgroundColor = UIColor.Clear, AllowsSelection = false }; // Future - consider supporting more travel modes? var travelModeImageView = new UIImageView(UIImage.FromBundle("walking")) { TranslatesAutoresizingMaskIntoConstraints = false, TintColor = ApplicationTheme.PrimaryLabelColor, ContentMode = UIViewContentMode.ScaleAspectFit }; _routeDurationLabel = new UILabel { TranslatesAutoresizingMaskIntoConstraints = false }; UIButton closeButton = new CloseButton { TranslatesAutoresizingMaskIntoConstraints = false }; var headerLabel = new UILabel { TranslatesAutoresizingMaskIntoConstraints = false, Text = "RouteResultHeader".Localize(), Font = ApplicationTheme.HeaderFont, TextColor = ApplicationTheme.ForegroundColor }; AddSubviews(_stopsTable, travelModeImageView, _routeDurationLabel, closeButton, headerLabel); NSLayoutConstraint.ActivateConstraints(new[] { // result header headerLabel.TopAnchor.ConstraintEqualTo(TopAnchor, ApplicationTheme.Margin), headerLabel.LeadingAnchor.ConstraintEqualTo(LeadingAnchor, ApplicationTheme.Margin), headerLabel.TrailingAnchor.ConstraintEqualTo(closeButton.LeadingAnchor, -ApplicationTheme.Margin), // close button closeButton.TrailingAnchor.ConstraintEqualTo(TrailingAnchor, -ApplicationTheme.Margin), closeButton.CenterYAnchor.ConstraintEqualTo(headerLabel.CenterYAnchor), closeButton.WidthAnchor.ConstraintEqualTo(32), closeButton.HeightAnchor.ConstraintEqualTo(32), // stops view _stopsTable.LeadingAnchor.ConstraintEqualTo(LeadingAnchor), _stopsTable.TopAnchor.ConstraintEqualTo(_routeDurationLabel.BottomAnchor, ApplicationTheme.Margin), _stopsTable.TrailingAnchor.ConstraintEqualTo(TrailingAnchor, -ApplicationTheme.Margin), // image travelModeImageView.LeadingAnchor.ConstraintEqualTo(LeadingAnchor, ApplicationTheme.Margin), travelModeImageView.TopAnchor.ConstraintEqualTo(_routeDurationLabel.TopAnchor), travelModeImageView.BottomAnchor.ConstraintEqualTo(_routeDurationLabel.BottomAnchor), travelModeImageView.WidthAnchor.ConstraintEqualTo(32), // walk time label _routeDurationLabel.TopAnchor.ConstraintEqualTo(headerLabel.BottomAnchor, ApplicationTheme.Margin), _routeDurationLabel.LeadingAnchor.ConstraintEqualTo(travelModeImageView.TrailingAnchor, ApplicationTheme.Margin), // constrains view bottom to bottom of last element BottomAnchor.ConstraintEqualTo(_stopsTable.BottomAnchor, ApplicationTheme.Margin) }); closeButton.TouchUpInside += Close_Clicked; _viewModel.PropertyChanged += ViewModel_PropertyChanged; }