Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Expander on ListView + Enable Expander CollectionView GridLayout 1557 #1567

Merged
merged 21 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9875454
Expander CollectionView GridLayout 1557
VladislavAntonyuk Nov 26, 2023
dc060d6
Merge branch 'main' into 1557-fix-collectiobview
VladislavAntonyuk Dec 4, 2023
f8ecbb7
Update expander macos
VladislavAntonyuk Dec 4, 2023
8ebc4ed
Merge branch 'main' into 1557-fix-collectiobview
TheCodeTraveler Dec 7, 2023
e992b81
Merge branch 'main' into 1557-fix-collectiobview
VladislavAntonyuk Jan 26, 2024
467fa8c
Merge branch 'main' into 1557-fix-collectiobview
VladislavAntonyuk Feb 1, 2024
754e762
Merge branch 'main' into 1557-fix-collectiobview
TheCodeTraveler Feb 15, 2024
ae6e678
Merge branch 'main' into 1557-fix-collectiobview
vhugogarcia Feb 27, 2024
bd32e21
Merge branch 'main' into 1557-fix-collectiobview
TheCodeTraveler Mar 26, 2024
32ac568
Merge branch 'main' into 1557-fix-collectiobview
TheCodeTraveler Jul 24, 2024
9c50ac0
Merge branch 'main' into 1557-fix-collectiobview
TheCodeTraveler Dec 18, 2024
4471407
Merge branch 'main' into 1557-fix-collectiobview
ne0rrmatrix Jan 28, 2025
4634298
Merge branch 'main' into 1557-fix-collectiobview
TheCodeTraveler Jan 29, 2025
f309244
Merge branch 'main' into 1557-fix-collectiobview
VladislavAntonyuk Feb 4, 2025
199f10d
Fix sample, remove expander macios
VladislavAntonyuk Feb 4, 2025
cb0195c
Add more contributors
VladislavAntonyuk Feb 4, 2025
08cd9fe
Merge branch 'main' into 1557-fix-collectiobview
ne0rrmatrix Feb 4, 2025
f09062e
Merge branch 'main' into 1557-fix-collectiobview
VladislavAntonyuk Feb 4, 2025
1fb7ded
Fix expander ios list view
VladislavAntonyuk Feb 4, 2025
9751b8f
update sample
VladislavAntonyuk Feb 4, 2025
afc0d06
Merge branch 'main' into 1557-fix-collectiobview
ne0rrmatrix Feb 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
</ListView.ItemTemplate>
</ListView>

<Label Text="Expander in CollectionView" FontSize="24" FontAttributes="Bold"/>
<Label Text="Expander in CollectionView with LinearItemsLayout" FontSize="24" FontAttributes="Bold"/>

<CollectionView ItemsSource="{Binding ContentCreators}">
<CollectionView.ItemTemplate>
Expand All @@ -96,6 +96,35 @@
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>

<Label Text="Expander in CollectionView with GridItemsLayout" FontSize="24" FontAttributes="Bold"/>

<CollectionView ItemsSource="{Binding ContentCreators}">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical"
Span="4"
HorizontalItemSpacing="5"
VerticalItemSpacing="5" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<mct:Expander x:DataType="sample:ContentCreator"
ExpandedChanged="Expander_ExpandedChanged">
<mct:Expander.Header>
<Label Text="{Binding Name}"/>
</mct:Expander.Header>
<mct:Expander.Content>
<VerticalStackLayout>
<Label Text="{Binding Resource}" HorizontalOptions="Center"/>
<Image Source="{Binding Image}"
WidthRequest="100"
HeightRequest="100"/>
</VerticalStackLayout>
</mct:Expander.Content>
</mct:Expander>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout>
</ScrollView>
</pages:BasePage>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ public static IEnumerable<ContentCreator> GetContentCreators() =>
new("Kym Phillpotts", "https://kymphillpotts.com", "https://avatars.githubusercontent.com/u/1327346"),
new("Pedro Jesus", "https://github.com/pictos", "https://avatars.githubusercontent.com/u/20712372"),
new("Shaun Lawrence", "https://github.com/bijington", "https://avatars.githubusercontent.com/u/17139988"),
new("Vladislav Antonyuk", "https://vladislavantonyuk.azurewebsites.net", "https://avatars.githubusercontent.com/u/33021114"),
new("Vladislav Antonyuk", "https://vladislavantonyuk.github.io", "https://avatars.githubusercontent.com/u/33021114"),
new("Víctor Hugo García Hernández", "", "https://avatars.githubusercontent.com/u/1047398"),
new("James Crutchley", "", "https://avatars.githubusercontent.com/u/4167863"),
new("Clifford Agius", "https://cliffordagius.co.uk/", "https://avatars.githubusercontent.com/u/5613809"),
];
}
}
54 changes: 0 additions & 54 deletions src/CommunityToolkit.Maui/Views/Expander/Expander.macios.cs

This file was deleted.

24 changes: 11 additions & 13 deletions src/CommunityToolkit.Maui/Views/Expander/Expander.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,33 +169,31 @@ void ResizeExpanderInItemsView(TappedEventArgs tappedEventArgs)
}

Element element = this;
#if WINDOWS
var size = IsExpanded
? Measure(double.PositiveInfinity, double.PositiveInfinity)
: Header.Measure(double.PositiveInfinity, double.PositiveInfinity);

#endif
while (element is not null)
{
if (element.Parent is ListView && element is Cell cell)
{
#if IOS || MACCATALYST
throw new NotSupportedException($"{nameof(Expander)} is not yet supported in {nameof(ListView)}");
#else
cell.ForceUpdateSize();
if (element is ListView listView)
{
(listView.Handler?.PlatformView as UIKit.UITableView)?.ReloadData();
}
#endif

#if WINDOWS
if (element.Parent is ListView listView && element is Cell cell)
{
cell.ForceUpdateSize();
}
#if IOS || MACCATALYST || WINDOWS
else if (element is CollectionView collectionView)
{
var tapLocation = tappedEventArgs.GetPosition(collectionView);
ForceUpdateCellSize(collectionView, size, tapLocation);
}
#endif
#if IOS || MACCATALYST
else if (element is ScrollView scrollView)
{
((IView)scrollView).InvalidateMeasure();
}
#endif

element = element.Parent;
}
Expand Down
44 changes: 43 additions & 1 deletion src/CommunityToolkit.Maui/Views/Expander/Expander.windows.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using CommunityToolkit.Maui.Core.Extensions;
using Microsoft.Maui.Controls.Platform;
using Microsoft.UI.Xaml.Controls;

Expand Down Expand Up @@ -30,5 +29,48 @@ static void ForceUpdateCellSize(CollectionView collectionView, Size size, Point?
}
}
}
else if (collectionView.Handler?.PlatformView is FormsGridView gridView)
{
var numberOfColumns = gridView.Span;
if (numberOfColumns == 0)
{
return;
}

for (var i = 0; i < gridView.Items.Count; i++)
{
if (gridView.ContainerFromIndex(i) is GridViewItem gridViewItem)
{
var itemTransform = gridViewItem.TransformToVisual(gridView);
var itemPosition = itemTransform.TransformPoint(new Windows.Foundation.Point(0, 0));
var itemBounds = new Rect(itemPosition.X, itemPosition.Y, gridViewItem.ActualWidth, gridViewItem.ActualHeight);

if (itemBounds.Contains(tapLocation.Value))
{
IterateItemsInRow(gridView, i, numberOfColumns, size.Height);
break;
}
}
}
}
}

static void IterateItemsInRow(ItemsControl gridView, int itemIndex, int totalColumns, double height)
{
var rowToIterate = itemIndex / totalColumns;
var startIndex = rowToIterate * totalColumns;

for (var i = startIndex; i < startIndex + totalColumns; i++)
{
if (i >= gridView.Items.Count)
{
break;
}

if (gridView.ContainerFromIndex(i) is GridViewItem cell)
{
cell.Height = height + Random.Shared.NextDouble();
}
}
}
}
Loading