Skip to content

Commit 4b9074c

Browse files
Revert "Fixed CollectionViewHandler2 null reference exception if ItemsLayout is set for Tablet but not on mobile devices (dotnet#26152)"
This reverts commit 0ddc794.
1 parent d45ee3e commit 4b9074c

File tree

5 files changed

+16
-159
lines changed

5 files changed

+16
-159
lines changed

src/Controls/src/Core/Handlers/Items2/CollectionViewHandler2.iOS.cs

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,21 @@ protected override UICollectionViewLayout SelectLayout()
155155

156156
var itemSizingStrategy = ItemsView.ItemSizingStrategy;
157157
var itemsLayout = ItemsView.ItemsLayout;
158-
159-
SubscribeToItemsLayoutPropertyChanged(itemsLayout);
158+
159+
//TODO: Find a better way to do this
160+
itemsLayout.PropertyChanged += (sender, args) =>
161+
{
162+
if (args.PropertyName == nameof(ItemsLayout.SnapPointsAlignment) ||
163+
args.PropertyName == nameof(ItemsLayout.SnapPointsType) ||
164+
args.PropertyName == nameof(GridItemsLayout.VerticalItemSpacing) ||
165+
args.PropertyName == nameof(GridItemsLayout.HorizontalItemSpacing) ||
166+
args.PropertyName == nameof(GridItemsLayout.Span) ||
167+
args.PropertyName == nameof(LinearItemsLayout.ItemSpacing))
168+
169+
{
170+
UpdateLayout();
171+
}
172+
};
160173

161174
if (itemsLayout is GridItemsLayout gridItemsLayout)
162175
{
@@ -169,10 +182,7 @@ protected override UICollectionViewLayout SelectLayout()
169182
}
170183

171184
// Fall back to vertical list
172-
var fallbackItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Vertical);
173-
// Manually setting the value to ensure the property changed event is properly wired..
174-
ItemsView.ItemsLayout = fallbackItemsLayout;
175-
return LayoutFactory2.CreateList(fallbackItemsLayout, groupInfo, headerFooterInfo);
185+
return LayoutFactory2.CreateList(new LinearItemsLayout(ItemsLayoutOrientation.Vertical), groupInfo, headerFooterInfo);
176186
}
177187

178188
public static void MapHeaderTemplate(CollectionViewHandler2 handler, StructuredItemsView itemsView)
@@ -196,25 +206,5 @@ public static void MapItemSizingStrategy(CollectionViewHandler2 handler, Structu
196206
{
197207
handler.UpdateLayout();
198208
}
199-
200-
void SubscribeToItemsLayoutPropertyChanged(IItemsLayout itemsLayout)
201-
{
202-
if(itemsLayout is not null)
203-
{
204-
itemsLayout.PropertyChanged += (sender, args) =>
205-
{
206-
if (args.PropertyName == nameof(ItemsLayout.SnapPointsAlignment) ||
207-
args.PropertyName == nameof(ItemsLayout.SnapPointsType) ||
208-
args.PropertyName == nameof(GridItemsLayout.VerticalItemSpacing) ||
209-
args.PropertyName == nameof(GridItemsLayout.HorizontalItemSpacing) ||
210-
args.PropertyName == nameof(GridItemsLayout.Span) ||
211-
args.PropertyName == nameof(LinearItemsLayout.ItemSpacing))
212-
213-
{
214-
UpdateLayout();
215-
}
216-
};
217-
}
218-
}
219209
}
220210
}

src/Controls/tests/TestCases.HostApp/Issues/Issue26065.xaml

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/Controls/tests/TestCases.HostApp/Issues/Issue26065.xaml.cs

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26065.cs

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)