This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signal layout request when CollectionView is in a layout
Fixes #13551
- Loading branch information
Showing
4 changed files
with
140 additions
and
1 deletion.
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
136 changes: 136 additions & 0 deletions
136
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue13551.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,136 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Globalization; | ||
using System.Text; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
|
||
#if UITEST | ||
using Xamarin.UITest; | ||
using NUnit.Framework; | ||
using Xamarin.Forms.Core.UITests; | ||
#endif | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
[Issue(IssueTracker.Github, 13551, "[Bug] [iOS] CollectionView does not display items if `IsVisible` modified via a binding/trigger", PlatformAffected.iOS)] | ||
#if UITEST | ||
[NUnit.Framework.Category(UITestCategories.CollectionView)] | ||
#endif | ||
public class Issue13551 : TestContentPage | ||
{ | ||
const string Success1 = "Success1"; | ||
const string Success2 = "Success2"; | ||
|
||
public ObservableCollection<Item> Source1 { get; } = new ObservableCollection<Item>(); | ||
public ObservableCollection<Item> Source2 { get; } = new ObservableCollection<Item>(); | ||
|
||
CollectionView BindingWithConverter() | ||
{ | ||
var cv = new CollectionView | ||
{ | ||
IsVisible = true, | ||
|
||
ItemTemplate = new DataTemplate(() => | ||
{ | ||
var label = new Label(); | ||
label.SetBinding(Label.TextProperty, new Binding(nameof(Item.Text))); | ||
return label; | ||
}) | ||
}; | ||
|
||
cv.SetBinding(CollectionView.ItemsSourceProperty, new Binding("Source1")); | ||
cv.SetBinding(VisualElement.IsVisibleProperty, new Binding("Source1.Count", converter: new IntToBoolConverter())); | ||
|
||
return cv; | ||
} | ||
|
||
CollectionView WithTrigger() | ||
{ | ||
var cv = new CollectionView | ||
{ | ||
IsVisible = true, | ||
|
||
ItemTemplate = new DataTemplate(() => | ||
{ | ||
var label = new Label(); | ||
label.SetBinding(Label.TextProperty, new Binding(nameof(Item.Text))); | ||
return label; | ||
}) | ||
}; | ||
|
||
cv.SetBinding(CollectionView.ItemsSourceProperty, new Binding("Source2")); | ||
|
||
var trigger = new DataTrigger(typeof(CollectionView)); | ||
trigger.Value = 0; | ||
trigger.Setters.Add(new Setter() { Property = VisualElement.IsVisibleProperty, Value = false }); | ||
trigger.Binding = new Binding("Source2.Count"); | ||
|
||
cv.Triggers.Add(trigger); | ||
|
||
return cv; | ||
} | ||
|
||
protected override void Init() | ||
{ | ||
BindingContext = this; | ||
|
||
var cv1 = BindingWithConverter(); | ||
var cv2 = WithTrigger(); | ||
|
||
var grid = new Grid | ||
{ | ||
RowDefinitions = new RowDefinitionCollection | ||
{ | ||
new RowDefinition() { Height = GridLength.Star }, | ||
new RowDefinition() { Height = GridLength.Star }, | ||
} | ||
}; | ||
|
||
grid.Children.Add(cv1); | ||
grid.Children.Add(cv2); | ||
Grid.SetRow(cv2, 1); | ||
|
||
Content = grid; | ||
|
||
Device.StartTimer(TimeSpan.FromMilliseconds(300), () => | ||
{ | ||
Device.BeginInvokeOnMainThread(() => | ||
{ | ||
Source1.Add(new Item { Text = Success1 }); | ||
Source2.Add(new Item { Text = Success2 }); | ||
}); | ||
|
||
return false; | ||
}); | ||
} | ||
|
||
class IntToBoolConverter : IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
return value is int val && val > 0; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
|
||
public class Item | ||
{ | ||
public string Text { get; set; } | ||
} | ||
|
||
#if UITEST | ||
[Test] | ||
public void CollectionInLayoutShouldInvalidateOnVisibilityChange() | ||
{ | ||
RunningApp.WaitForElement(Success1); | ||
RunningApp.WaitForElement(Success2); | ||
} | ||
#endif | ||
} | ||
} |
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