-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Make CollectionView on iOS measure to content size #14951
Conversation
Thank you for your pull request. We are auto-formatting your source code to follow our code guidelines. |
src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs
Outdated
Show resolved
Hide resolved
Please get it merged! 🙈 |
Co-authored-by: Pedro Jesus <pedrojesus.cefet@gmail.com>
@hartez what about .NET 7? I see there is no backport label. |
I'll consider that a request that we consider it for backporting. :) |
Super :) |
I have been wrecked by this update. Each and every CollectionView in my project began to work in an odd way on iOS (everything on Android works like a charm). Here's the detail of the packages I have installed: Visual Studio Community 2022 for Mac Runtime Roslyn (Language Service) NuGet .NET SDK (Arm64) .NET SDK (x64) .NET Runtime (Arm64) .NET Runtime (x64) Xamarin.Profiler Updater Apple Developer Tools Xamarin.Android SDK Command-line Tools Version: 7.0 Build Information: Microsoft Build of OpenJDK Eclipse Temurin JDK Android SDK Manager Android Device Manager Xamarin Designer Xamarin.Mac Xamarin.iOS Build Information Operating System Is there anything I can do to downgrade to a working package? (I have been using Xamarin.iOS 16.4.0.3 and .NET SDK (Arm64) 7.0.203 before I got to the current releases. |
Please :) |
Can we backport this and release in next .NET 7 SR please? @hartez ? |
Could this be worked around in a similar fashion to the "FixedScrollViewHandler" from this thread: #9209 - I'm a bit out of my depth on this, but it seems that a handler could be created (for example, FixedCollectionViewHandler) ? I can, of course, create a FixedCollectionViewHandler class, and override CreatePlatformView, but I'll admit I'm clueless after that. - Can anyone chime in with some input if 1. this could be a way to fix the issue and 2. what the implementation might look like? |
It might be awkward because of the inheritance chain (i.e., you might have to create a custom StructuredItemsViewController along with a custom ItemsViewController), but at first glance it looks possible. |
It is not recommended to place a CollectionView inside a ScrollView because the CollectionView is designed to automatically scroll when its contents exceed its size. Instead, We need to ensure that the MaximumHeightRequest/MaximumWidthRequest of the CollectionView does not exceed the height/width of its container, whether it is directly placed on the page or inside a Grid cell, for example. If the CollectionView is placed inside a container without a specific height (such as a StackLayout), then the height should be limited to the content height. In any case, the CollectionView's height should not be larger than its content. However, it should also not exceed the height of the container it is placed inside, as doing so would cause it to hide or overlap any items placed after it. |
@hartez Do we know if this will be backported yet? |
It may be, but that will be contingent on working out the rotation issues mentioned above. |
@hartez If it isn't backported for whatever reason, what are our options on .Net 7? Our UI is totally broken on iOS since 7.0.86 Service Release 6, so we've had to roll back to 7.0.81 to continue working on our app. Are we just stuck on that version now? We can't wait for Net 8 release in November because that is way too close to our deadline to do a big update. |
@WebGoose how did you revert? |
@Syed-RI We had to roll back VS 2022 to the previous version. That installed the older MAUI workloads |
That sucks! But thanks for letting me know! |
<MauiVersion>7.0.59</MauiVersion> The Grid layout hasn't worked correctly for my application since v7.0.59. I use the above property in my |
The bug fixed by this PR (#9135) pre-dates 7.0.86 by several months (it was opened in August 2022).
There's another service release in the works for next month which contains several fixes for Grid layout issues; that might be what you're looking for. |
/backport to net7.0 |
Started backporting to net7.0: https://github.com/dotnet/maui/actions/runs/5270887634 |
@hartez backporting to net7.0 failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Make CollectionView on iOS measure to content size Fixes #9135
.git/rebase-apply/patch:90: trailing whitespace.
void InvalidateMeasureIfContentSizeChanged()
.git/rebase-apply/patch:103: trailing whitespace.
// than the screen size, then we know that we're already maxed out and the
.git/rebase-apply/patch:107: trailing whitespace.
// If either size is smaller than that, we need to invalidate to ensure that the
.git/rebase-apply/patch:114: trailing whitespace.
.git/rebase-apply/patch:129: trailing whitespace.
internal Size? GetSize()
warning: squelched 2 whitespace errors
warning: 7 lines add whitespace errors.
Using index info to reconstruct a base tree...
M src/Controls/src/Core/Handlers/Items/ItemsViewHandler.iOS.cs
M src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs
M src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt
M src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt
M src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.cs
Auto-merging src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt
CONFLICT (content): Merge conflict in src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt
Auto-merging src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt
CONFLICT (content): Merge conflict in src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt
Auto-merging src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs
CONFLICT (content): Merge conflict in src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs
Auto-merging src/Controls/src/Core/Handlers/Items/ItemsViewHandler.iOS.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Make CollectionView on iOS measure to content size Fixes #9135
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
@hartez an error occurred while backporting to net7.0, please check the run log for details! Error: git am failed, most likely due to a merge conflict. |
* Make CollectionView on iOS measure to content size Fixes #9135 * Make tests work when device is in landscape * Auto-format source code * Removed extra local variable * Update src/Controls/src/Core/Handlers/Items/ItemsViewHandler.iOS.cs Co-authored-by: Pedro Jesus <pedrojesus.cefet@gmail.com> * Handle height/width invalidation checks independently --------- Co-authored-by: GitHub Actions Autoformatter <autoformat@example.com> Co-authored-by: Pedro Jesus <pedrojesus.cefet@gmail.com>
* Make CollectionView on iOS measure to content size (#14951) * Make CollectionView on iOS measure to content size Fixes #9135 * Make tests work when device is in landscape * Auto-format source code * Removed extra local variable * Update src/Controls/src/Core/Handlers/Items/ItemsViewHandler.iOS.cs Co-authored-by: Pedro Jesus <pedrojesus.cefet@gmail.com> * Handle height/width invalidation checks independently --------- Co-authored-by: GitHub Actions Autoformatter <autoformat@example.com> Co-authored-by: Pedro Jesus <pedrojesus.cefet@gmail.com> * Remove unused member * Fix alignment check --------- Co-authored-by: GitHub Actions Autoformatter <autoformat@example.com> Co-authored-by: Pedro Jesus <pedrojesus.cefet@gmail.com> Co-authored-by: Javier Suárez <javiersuarezruiz@hotmail.com>
I tested this with an ItemsLayout of HorizontalList and it fails completely on IOS. The height of the collection view is not sizing correctly. When the CollectionView is set to a vertical list or anything vertical, it works correctly. I guess this wasn't tested well before marking it as complete in the release notes for 8.0.3 I really hoped this issue would ACTUALLY be fixed. |
Not sizing correctly in what way? Too big, too small, something weird in the middle? Please open an issue with a repro (or at least the markup/layout you're using) and we will take a look. |
First, I'll put it here then I'll open the issue since I'm a bit pressed for time. I have two way scrolling in place. I use a vertical stacklayout with BindableLayout. This vertical stack layout has a template that is a ContentView (This content view is composited in its own XAML)... This is wrapped in a ScrollView. Here is the code: <StackLayout
Spacing="0"
x:Name="CategoriesCollectionView"
VerticalOptions="StartAndExpand">
<BindableLayout.ItemTemplate>
<DataTemplate>
<views:CategorySectionView BindingContext="{Binding .}" />
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout> Inside this CategorySectionView is a CollectionView that has an ItemsLayout of HorizontalList. <VerticalStackLayout
Spacing="0"
VerticalOptions="Start">
<Grid
BackgroundColor="#EEF0F1"
HorizontalOptions="Fill"
Margin="0"
Padding="15, 12">
<Label
Text="{Binding Name}"
FontFamily="PhilosopherBold"
FontSize="24"
TextColor="#39302D"/>
<Grid.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" />
</Grid.GestureRecognizers>
</Grid>
<Grid
VerticalOptions="Start"
Padding="0, 0, 0, 0">
<CollectionView
VerticalOptions="Start"
x:Name="CategoryItemsCollectionView"
ItemsSource="{Binding Businesses}"
VerticalScrollBarVisibility="Never"
HorizontalScrollBarVisibility="Never">
<CollectionView.ItemsLayout>
<LinearItemsLayout Orientation="Horizontal" ItemSpacing="0" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid
VerticalOptions="Start"
Padding="12, 16">
<cards:BusinessCard BindingContext="{Binding .}"/>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</Grid>
</VerticalStackLayout> The CollectionView in this second snippet is stretching to match the screen height and not the content height. If I manually set the HeightRequest to the height of the content as they're added, it works correctly. On Android, this is not an issue at all. One last note is that the original stacklayout is being populated after the page has been loaded. ~2 seconds after loading the page. I have an activity indicator to show progress. Once data is loaded, it populates the bindable layout on the UI Thread. I tested on physical devices: iPhone, iPad and Samsung Phone |
Description of Change
Modifies the CollectionView on iOS to use its ContentSize as the value for GetDesiredSize; this forces the CollectionView to size to its content rather than attempting to fill the whole screen.
Issues Fixed
Fixes #9135
Fixes #14966