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.
[iOS] Fix missing partial columns in horizontal grid layout (#6241)
* Create repro * Work around UICollectionViewFlowLayout bug to display partial columns; fixes #6077 Fix content inset behaviors when dealing with safe area on newer iOS versions * Add check for case where there is only a single partial column * Works better if I don't forget the return statement * Split up tests to make it easier to determine what failed * Fix bounds exception when changing to a smaller ItemsSource * Add preserve attributes so the linker won't ruin my UI test * Fix missing using after rebase
- Loading branch information
Showing
6 changed files
with
278 additions
and
14 deletions.
There are no files selected for viewing
139 changes: 139 additions & 0 deletions
139
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue6077.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,139 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.ComponentModel; | ||
using System.Runtime.CompilerServices; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
using Xamarin.Forms.PlatformConfiguration; | ||
using Xamarin.Forms.PlatformConfiguration.iOSSpecific; | ||
|
||
#if UITEST | ||
using Xamarin.Forms.Core.UITests; | ||
using Xamarin.UITest; | ||
using NUnit.Framework; | ||
#endif | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
#if UITEST | ||
[NUnit.Framework.Category(UITestCategories.CollectionView)] | ||
#endif | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Github, 6077, "CollectionView (iOS) using horizontal grid does not display last column of uneven item count", PlatformAffected.iOS)] | ||
public class Issue6077 : TestNavigationPage | ||
{ | ||
[Preserve(AllMembers = true)] | ||
public class MainViewModel : INotifyPropertyChanged | ||
{ | ||
readonly IList<ItemModel> _items; | ||
public ObservableCollection<ItemModel> Items { get; private set; } | ||
|
||
public MainViewModel() | ||
{ | ||
_items = new List<ItemModel>(); | ||
CreateItemsCollection(); | ||
} | ||
|
||
void CreateItemsCollection(int items = 5) | ||
{ | ||
for (int n = 0; n < items; n++) | ||
{ | ||
_items.Add(new ItemModel | ||
{ | ||
Title = $"Item {n + 1}", | ||
}); | ||
} | ||
|
||
Items = new ObservableCollection<ItemModel>(_items); | ||
} | ||
|
||
protected bool SetProperty<T>(ref T backingStore, T value, | ||
[CallerMemberName]string propertyName = "", | ||
Action onChanged = null) | ||
{ | ||
if (EqualityComparer<T>.Default.Equals(backingStore, value)) | ||
return false; | ||
|
||
backingStore = value; | ||
onChanged?.Invoke(); | ||
OnPropertyChanged(propertyName); | ||
return true; | ||
} | ||
|
||
#region INotifyPropertyChanged | ||
public event PropertyChangedEventHandler PropertyChanged; | ||
protected void OnPropertyChanged([CallerMemberName] string propertyName = "") | ||
{ | ||
var changed = PropertyChanged; | ||
if (changed == null) | ||
return; | ||
|
||
changed.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
#endregion | ||
} | ||
|
||
[Preserve(AllMembers = true)] | ||
public class ItemModel | ||
{ | ||
public string Title { get; set; } | ||
} | ||
|
||
ContentPage CreateRoot() | ||
{ | ||
var page = new ContentPage { Title = "Issue6077" }; | ||
|
||
var cv = new CollectionView { ItemSizingStrategy = ItemSizingStrategy.MeasureAllItems }; | ||
|
||
var itemsLayout = new GridItemsLayout(3, ItemsLayoutOrientation.Horizontal); | ||
|
||
|
||
cv.ItemsLayout = itemsLayout; | ||
|
||
var template = new DataTemplate(() => { | ||
var grid = new Grid { HeightRequest = 100, WidthRequest = 50, BackgroundColor = Color.AliceBlue }; | ||
grid.RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = new GridLength(100) } }; | ||
grid.ColumnDefinitions = new ColumnDefinitionCollection { new ColumnDefinition { Width = new GridLength(50) } }; | ||
var label = new Label { }; | ||
label.SetBinding(Label.TextProperty, new Binding("Title")); | ||
var content = new ContentView { Content = label }; | ||
grid.Children.Add(content); | ||
return grid; | ||
}); | ||
|
||
cv.ItemTemplate = template; | ||
cv.SetBinding(ItemsView.ItemsSourceProperty, new Binding("Items")); | ||
|
||
page.Content = cv; | ||
|
||
BindingContext = new MainViewModel(); | ||
|
||
return page; | ||
} | ||
|
||
protected override void Init() | ||
{ | ||
#if APP | ||
Device.SetFlags(new List<string>(Device.Flags ?? new List<string>()) { "CollectionView_Experimental" }); | ||
|
||
PushAsync(CreateRoot()); | ||
#endif | ||
} | ||
|
||
#if UITEST | ||
[Test] | ||
public void LastColumnShouldBeVisible() | ||
{ | ||
// If the partial column shows up, then Item 5 will be in it | ||
RunningApp.WaitForElement("Item 5"); | ||
} | ||
#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
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
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