-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[iOS] Fix deselect item on CollectionView (#26315)
* Add sample for issue #26187 * [iOS] Fix deselecting an item * [testing] Add uitest for issue #26187 * [testing] Add android screenshot * [testing] Add missing image windows * [ios] Add foreach inside CollectionView.PerformBatchUpdates * Update SelectableItemsViewController.cs * [iOS] Don try to update empty if no items * Fix sample
- Loading branch information
Showing
7 changed files
with
141 additions
and
7 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
Binary file added
BIN
+12.4 KB
...tests/TestCases.Android.Tests/snapshots/android/SelectedItemVisualIsCleared.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,92 @@ | ||
using System.Collections.ObjectModel; | ||
|
||
namespace Maui.Controls.Sample.Issues | ||
{ | ||
[Issue(IssueTracker.Github, 26187, "[MAUI] Select items traces are preserved", PlatformAffected.iOS)] | ||
public class Issue26187 : NavigationPage | ||
{ | ||
public Issue26187() | ||
{ | ||
PushAsync(new CollectionViewSelectedItemNullPage()); | ||
} | ||
} | ||
|
||
public class CollectionViewSelectedItemNullPage : ContentPage | ||
{ | ||
public ObservableCollection<string> Items { get; set; } | ||
|
||
public string SelectedItem { get; set; } | ||
|
||
public CollectionViewSelectedItemNullPage() | ||
{ | ||
Items = new ObservableCollection<string> | ||
{ | ||
"Item 1", | ||
"Item 2", | ||
"Item 3", | ||
"Item 4", | ||
"Item 5" | ||
}; | ||
SelectedItem = Items.LastOrDefault(); | ||
var cv = new CollectionView | ||
{ | ||
SelectionMode = SelectionMode.Single, | ||
ItemTemplate = new DataTemplate(() => | ||
{ | ||
var label = new Label | ||
{ | ||
FontSize = 24, | ||
HorizontalOptions = LayoutOptions.FillAndExpand, | ||
VerticalOptions = LayoutOptions.Center, | ||
AutomationId ="lblItem" | ||
}; | ||
label.SetBinding(Label.TextProperty, "."); | ||
|
||
return new HorizontalStackLayout | ||
{ | ||
Children = { label } | ||
}; | ||
}) | ||
|
||
}; | ||
|
||
cv.SetBinding(CollectionView.ItemsSourceProperty, new Binding(nameof(Items))); | ||
// cv.SetBinding(CollectionView.SelectedItemProperty, new Binding(nameof(SelectedItem))); | ||
Content = cv; | ||
|
||
BindingContext = this; | ||
// cv.SelectedItem = SelectedItem; | ||
|
||
cv.SelectionChanged += CollectionView_SelectionChanged; | ||
} | ||
|
||
async void CollectionView_SelectionChanged(object sender, SelectionChangedEventArgs e) | ||
{ | ||
if (e.CurrentSelection.FirstOrDefault() is string issue) | ||
{ | ||
await Navigation.PushAsync(new NewPage(issue)); | ||
} | ||
|
||
// Clear Selection | ||
var cv = sender as CollectionView; | ||
if (cv is not null) | ||
{ | ||
cv.SelectedItem = null; | ||
} | ||
} | ||
|
||
class NewPage : ContentPage | ||
{ | ||
public NewPage(string item) | ||
{ | ||
Title = item; | ||
Content = new Button | ||
{ | ||
Text = $"Go Back Selected Item null from {item}", | ||
Command = new Command(() => Navigation.PopAsync()), | ||
AutomationId = "btnGoBack" | ||
}; | ||
} | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26187.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,27 @@ | ||
using NUnit.Framework; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.TestCases.Tests.Issues | ||
{ | ||
public class Issue26187 : _IssuesUITest | ||
{ | ||
public override string Issue => "[MAUI] Select items traces are preserved"; | ||
|
||
public Issue26187(TestDevice device) | ||
: base(device) | ||
{ } | ||
|
||
[Test] | ||
[Category(UITestCategories.CollectionView)] | ||
public void SelectedItemVisualIsCleared() | ||
{ | ||
App.WaitForElement("lblItem"); | ||
App.Tap("lblItem"); | ||
App.WaitForElement("btnGoBack"); | ||
App.Tap("btnGoBack"); | ||
App.WaitForElement("lblItem"); | ||
VerifyScreenshot(); | ||
} | ||
} | ||
} |
Binary file added
BIN
+8.88 KB
...s/tests/TestCases.WinUI.Tests/snapshots/windows/SelectedItemVisualIsCleared.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17 KB
...ontrols/tests/TestCases.iOS.Tests/snapshots/ios/SelectedItemVisualIsCleared.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.