-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from rh-mitre-ten/android_fix_suggestions_not_…
…showing_when_search_string_empty Android - display suggestions empty search text
- Loading branch information
Showing
4 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
SampleApp/SampleApp/Samples/AutoSuggestBoxSamples/PreviousAndSuggested.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage | ||
x:Class="SampleApp.Samples.AutoSuggestBoxSamples.PreviousAndSuggested" | ||
xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:dm="clr-namespace:dotMorten.Xamarin.Forms;assembly=dotMorten.Xamarin.Forms.AutoSuggestBox" | ||
Padding="20"> | ||
<ContentPage.Content> | ||
<StackLayout> | ||
<dm:AutoSuggestBox | ||
x:Name="SuggestBox1" | ||
Focused="SuggestBox1_OnFocused" | ||
PlaceholderText="Scan or type" | ||
QuerySubmitted="SuggestBox_QuerySubmitted" | ||
TextChanged="SuggestBox_TextChanged" /> | ||
</StackLayout> | ||
</ContentPage.Content> | ||
</ContentPage> |
80 changes: 80 additions & 0 deletions
80
SampleApp/SampleApp/Samples/AutoSuggestBoxSamples/PreviousAndSuggested.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using dotMorten.Xamarin.Forms; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using Xamarin.Forms; | ||
using Xamarin.Forms.Xaml; | ||
|
||
namespace SampleApp.Samples.AutoSuggestBoxSamples | ||
{ | ||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
[Description("Previous search and suggested")] | ||
[SamplePriority(4)] | ||
public partial class PreviousAndSuggested : ContentPage | ||
{ | ||
public PreviousAndSuggested() | ||
{ | ||
InitializeComponent (); | ||
Initialize(); | ||
} | ||
|
||
private List<string> _suggestedSearches; | ||
private List<string> _previousSearches; | ||
|
||
private void Initialize() | ||
{ | ||
// suggested searches based on what was typed - normally loaded from some api | ||
_suggestedSearches = new List<string> | ||
{ | ||
"suggestion 1", | ||
"suggestion 2", | ||
"suggestion 3" | ||
}; | ||
|
||
// a history of searches the user has previous executed | ||
_previousSearches = new List<string> | ||
{ | ||
"previous search 1", | ||
"previous search 2", | ||
"previous search 3", | ||
}; | ||
} | ||
|
||
private void SuggestBox_TextChanged(object sender, AutoSuggestBoxTextChangedEventArgs e) | ||
{ | ||
var box = (AutoSuggestBox)sender; | ||
UpdateSuggestionItemSource(box); | ||
} | ||
|
||
private void SuggestBox1_OnFocused(object sender, FocusEventArgs e) | ||
{ | ||
var box = (AutoSuggestBox)sender; | ||
UpdateSuggestionItemSource(box); | ||
} | ||
|
||
private void UpdateSuggestionItemSource(AutoSuggestBox box) | ||
{ | ||
if (box.Text.Length >= 3) | ||
{ | ||
// show suggested searches, presumably loaded from an API | ||
box.ItemsSource = _suggestedSearches; | ||
box.IsSuggestionListOpen = true; | ||
} | ||
else if (box.Text.Length == 0) | ||
{ | ||
// show the user's previous searches when they haven't typed anything yet | ||
box.ItemsSource = _previousSearches; | ||
box.IsSuggestionListOpen = true; | ||
} | ||
else | ||
{ | ||
box.IsSuggestionListOpen = false; | ||
box.ItemsSource = null; | ||
} | ||
} | ||
|
||
private void SuggestBox_QuerySubmitted(object sender, AutoSuggestBoxQuerySubmittedEventArgs e) | ||
{ | ||
SuggestBox1.Unfocus(); | ||
} | ||
} | ||
} |