-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Windows, Android] Fix ScrollView Content Not Removed When Set to Null #33069
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
Changes from all commits
586f247
ff92c07
a6a14b5
b8e794a
e05af7b
6de1a1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,80 @@ | ||||||||||||
| using System.Collections.ObjectModel; | ||||||||||||
|
|
||||||||||||
| namespace Maui.Controls.Sample.Issues; | ||||||||||||
|
|
||||||||||||
| [Issue(IssueTracker.Github, 33067, "[Windows, Android] ScrollView Content Not Removed When Set to Null", PlatformAffected.Android | PlatformAffected.UWP)] | ||||||||||||
|
|
||||||||||||
| public class Issue33067 : ContentPage | ||||||||||||
| { | ||||||||||||
| ScrollView _scrollView = null!; | ||||||||||||
| Label _originalContent = null!; | ||||||||||||
| Button _setNullButton = null!; | ||||||||||||
| Button _addContentButton = null!; | ||||||||||||
|
|
||||||||||||
| public Issue33067() | ||||||||||||
| { | ||||||||||||
| CreateUI(); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| void CreateUI() | ||||||||||||
| { | ||||||||||||
| // Create the original content label | ||||||||||||
| _originalContent = new Label | ||||||||||||
| { | ||||||||||||
| Text = "This is a sample label inside the ScrollView that can be set to null and added back.", | ||||||||||||
| Padding = new Thickness(20), | ||||||||||||
| AutomationId = "ContentLabel", | ||||||||||||
| FontSize = 16 | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| // Create the ScrollView | ||||||||||||
| _scrollView = new ScrollView | ||||||||||||
| { | ||||||||||||
| BackgroundColor = Colors.LightGray, | ||||||||||||
| HeightRequest = 300, | ||||||||||||
| Content = null | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| // Create the "Set Content to Null" button | ||||||||||||
| _setNullButton = new Button | ||||||||||||
| { | ||||||||||||
| Text = "Set Content to Null", | ||||||||||||
| AutomationId = "SetNullButton" | ||||||||||||
| }; | ||||||||||||
| _setNullButton.Clicked += OnSetContentNullClicked; | ||||||||||||
|
|
||||||||||||
| // Create the "Add Content" button | ||||||||||||
| _addContentButton = new Button | ||||||||||||
| { | ||||||||||||
| Text = "Add Content", | ||||||||||||
| AutomationId = "AddContentButton" | ||||||||||||
| }; | ||||||||||||
| _addContentButton.Clicked += OnAddContentClicked; | ||||||||||||
|
|
||||||||||||
| // Create the main layout | ||||||||||||
| var layout = new VerticalStackLayout | ||||||||||||
| { | ||||||||||||
| Spacing = 20, | ||||||||||||
| Padding = new Thickness(30), | ||||||||||||
| Children = { _setNullButton, _addContentButton, _scrollView } | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| // Set the content of the page | ||||||||||||
| Content = layout; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| void OnSetContentNullClicked(object sender, EventArgs e) | ||||||||||||
| { | ||||||||||||
| // Set ScrollView content to null | ||||||||||||
| _scrollView.Content = null; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| void OnAddContentClicked(object sender, EventArgs e) | ||||||||||||
| { | ||||||||||||
| // Restore the original content | ||||||||||||
| if (_originalContent != null) | ||||||||||||
| { | ||||||||||||
| _scrollView.Content = _originalContent; | ||||||||||||
| } | ||||||||||||
|
Comment on lines
+75
to
+78
|
||||||||||||
| if (_originalContent != null) | |
| { | |
| _scrollView.Content = _originalContent; | |
| } | |
| _scrollView.Content = _originalContent; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
| public class Issue33067 : _IssuesUITest | ||
| { | ||
| public Issue33067(TestDevice device) : base(device) { } | ||
|
|
||
| public override string Issue => "[Windows, Android] ScrollView Content Not Removed When Set to Null"; | ||
|
|
||
| [Test, Order(1)] | ||
| [Category(UITestCategories.ScrollView)] | ||
| public void VerifyScrollViewContentShouldNull() | ||
| { | ||
| App.WaitForElement("SetNullButton"); | ||
| App.WaitForNoElement("ContentLabel"); | ||
| } | ||
|
|
||
| [Test, Order(2)] | ||
| [Category(UITestCategories.ScrollView)] | ||
| public void VerifyScrollViewContentWhenSetToNull() | ||
| { | ||
| App.WaitForElement("SetNullButton"); | ||
| App.Tap("AddContentButton"); | ||
| App.WaitForElement("ContentLabel"); | ||
| App.Tap("SetNullButton"); | ||
| App.WaitForNoElement("ContentLabel"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -125,21 +125,34 @@ The methods below exist to support inserting/updating the padding/margin panel. | |||
|
|
||||
| static void UpdateContentPanel(IScrollView scrollView, IScrollViewHandler handler, ICrossPlatformLayout crossPlatformLayout) | ||||
| { | ||||
| if (scrollView.PresentedContent == null || handler.MauiContext == null) | ||||
| if (handler.MauiContext is null) | ||||
| { | ||||
| return; | ||||
| } | ||||
|
|
||||
| var scrollViewer = handler.PlatformView; | ||||
| var currentPaddingLayer = GetContentPanel(scrollViewer); | ||||
|
|
||||
| // If PresentedContent is null, clean up any existing content and return | ||||
| if (scrollView.PresentedContent is null) | ||||
| { | ||||
| if (currentPaddingLayer is not null) | ||||
| { | ||||
| currentPaddingLayer.CachedChildren.Clear(); | ||||
| } | ||||
|
|
||||
|
||||
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.
The
System.Collections.ObjectModelnamespace is not used in this file and should be removed.