-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[iOS] CollectionView2 - empty view - improvements #28119
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -469,6 +469,7 @@ void UpdateEmptyViewVisibility(bool isEmpty) | |
|
|
||
| if (isEmpty) | ||
| { | ||
| CollectionView.LayoutIfNeeded(); | ||
| ShowEmptyView(); | ||
| } | ||
| else | ||
|
|
@@ -544,6 +545,7 @@ void HideEmptyView() | |
| } | ||
|
|
||
| _emptyUIView.RemoveFromSuperview(); | ||
| CollectionView.ContentInset = UIEdgeInsets.Zero; | ||
|
|
||
| _emptyViewDisplayed = false; | ||
| } | ||
|
|
@@ -559,6 +561,24 @@ void TearDownEmptyView() | |
| _emptyViewFormsElement = null; | ||
| } | ||
|
|
||
| void RemeasureLayout(VisualElement formsElement) | ||
| { | ||
| if (IsHorizontal) | ||
| { | ||
| MeasureAndArrange(formsElement, double.PositiveInfinity, CollectionView.Frame.Height); | ||
| } | ||
| else | ||
| { | ||
| MeasureAndArrange(formsElement, CollectionView.Frame.Width, double.PositiveInfinity); | ||
| } | ||
| } | ||
|
|
||
| void MeasureAndArrange(VisualElement element, double widthConstraint, double heightConstraint) | ||
| { | ||
| var request = element.Measure(widthConstraint, heightConstraint); | ||
| element.Arrange(new Rect(0, 0, request.Width, request.Height)); | ||
| } | ||
|
|
||
| void LayoutEmptyView() | ||
| { | ||
| if (!_initialized || _emptyUIView == null || _emptyUIView.Superview == null) | ||
|
|
@@ -568,7 +588,10 @@ void LayoutEmptyView() | |
|
|
||
| var frame = DetermineEmptyViewFrame(); | ||
|
|
||
| RemeasureLayout(_emptyViewFormsElement); | ||
| frame = new CGRect(frame.X, frame.Y, frame.Width, Math.Max(frame.Height, _emptyViewFormsElement.Height)); | ||
| _emptyUIView.Frame = frame; | ||
| CollectionView.ContentInset = new UIEdgeInsets(0, 0, frame.Height, 0); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IS this the best way to do it ? Why do we need to inset?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without it, a CollectionView with an empty view whose height exceeds the frame won't scroll. |
||
|
|
||
| if (_emptyViewFormsElement != null && ((IElementController)ItemsView).LogicalChildren.IndexOf(_emptyViewFormsElement) != -1) | ||
| _emptyViewFormsElement.Layout(frame.ToRectangle()); | ||
|
|
||
20 changes: 20 additions & 0 deletions
20
src/Controls/tests/TestCases.HostApp/Issues/Issue28118.xaml
This file contains hidden or 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,20 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <ContentPage xmlns:controls="clr-namespace:Maui.Controls.Sample.Issues" | ||
| xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| x:Class="Maui.Controls.Sample.Issues.Issue28118"> | ||
| <Grid RowDefinitions="*"> | ||
| <CollectionView AutomationId="CollectionView"> | ||
| <CollectionView.EmptyView> | ||
| <VerticalStackLayout> | ||
| <ContentView HeightRequest="500" | ||
| BackgroundColor="Red"/> | ||
| <ContentView HeightRequest="500" | ||
| BackgroundColor="Blue"/> | ||
| <Label Text="Success" | ||
| AutomationId="SuccessLabel"/> | ||
| </VerticalStackLayout> | ||
| </CollectionView.EmptyView> | ||
| </CollectionView> | ||
| </Grid> | ||
| </ContentPage> |
9 changes: 9 additions & 0 deletions
9
src/Controls/tests/TestCases.HostApp/Issues/issue28118.xaml.cs
This file contains hidden or 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,9 @@ | ||
| namespace Maui.Controls.Sample.Issues; | ||
| [Issue(IssueTracker.Github, 28118, "CollectionView - empty view issues", PlatformAffected.iOS)] | ||
| public partial class Issue28118 : ContentPage | ||
| { | ||
| public Issue28118() | ||
| { | ||
| InitializeComponent(); | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28118.cs
This file contains hidden or 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,22 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
| public class Issue28118 : _IssuesUITest | ||
| { | ||
| public Issue28118(TestDevice testDevice) : base(testDevice) | ||
| { | ||
| } | ||
|
|
||
| public override string Issue => "CollectionView - empty view issues"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.CollectionView)] | ||
| public void EmptyViewShouldScroll() | ||
| { | ||
| App.WaitForElement("CollectionView"); | ||
| App.ScrollDown("CollectionView", ScrollStrategy.Gesture, 0.5); | ||
| App.WaitForElement("SuccessLabel"); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to call this if we setting the ContentInset wouldn't t that call layout?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out it doesn't. I tried without it on the latest main and it doesn't work