-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[iOS] Fix wrong scrolling options using the ScrollView Orientation property #30131
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
Open
jsuarezruiz
wants to merge
13
commits into
main
Choose a base branch
from
fix-30070
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0f01981
Initial changes
jsuarezruiz b8321c5
More changes
jsuarezruiz f94d4f3
More changes
jsuarezruiz 7c6c088
Fixed test
jsuarezruiz 362b160
Added pending snapshot
jsuarezruiz c098209
Added pending snapshot
jsuarezruiz 2f5b5f0
Updated test
jsuarezruiz f6514d5
Merge branch 'main' into fix-30070
jsuarezruiz 5b0fcc8
Merge branch 'main' into fix-30070
jsuarezruiz 624c2fa
Merge branch 'main' into fix-30070
jsuarezruiz 9d71b6c
Merge branch 'main' into fix-30070
jsuarezruiz 00b325b
Fixed broken iOS test
jsuarezruiz b39e0ea
Merge branch 'main' into fix-30070
jsuarezruiz 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
46 changes: 46 additions & 0 deletions
46
src/Controls/tests/TestCases.HostApp/Issues/Issue30070.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,46 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<local:TestContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:d="http://schemas.microsoft.com/dotnet/2021/maui/design" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
xmlns:local="using:Maui.Controls.Sample.Issues" | ||
xmlns:issues="using:Maui.Controls.Sample.Issues" | ||
x:Class="Maui.Controls.Sample.Issues.Issue30070"> | ||
<Grid RowDefinitions="*,Auto,Auto,Auto" | ||
Padding="0,10"> | ||
<ScrollView | ||
Grid.Row="0" | ||
x:Name="MyScrollView" | ||
Orientation="Horizontal" | ||
AutomationId="TestScrollView"> | ||
<ContentView x:Name="ScrollViewContent" | ||
Content="{Binding Content}" | ||
AutomationId="ScrollViewContent"/> | ||
</ScrollView> | ||
<HorizontalStackLayout Grid.Row="1"> | ||
<Button Text="Label" | ||
Clicked="OnContentTypeButtonClicked" | ||
WidthRequest="100" | ||
AutomationId="LabelContentBtn"/> | ||
<Button Text="Image" | ||
Clicked="OnContentTypeButtonClicked" | ||
WidthRequest="100" | ||
AutomationId="ImageContentBtn"/> | ||
<Button Text="Editor" | ||
Clicked="OnContentTypeButtonClicked" | ||
WidthRequest="100" | ||
AutomationId="GridContentBtn"/> | ||
</HorizontalStackLayout> | ||
<HorizontalStackLayout Grid.Row="2"> | ||
<Button Text="Grid" | ||
Clicked="OnContentTypeButtonClicked" | ||
WidthRequest="100" | ||
AutomationId="GridContentBtn"/> | ||
<Button Text="AbsoluteLayout" | ||
Clicked="OnContentTypeButtonClicked" | ||
WidthRequest="150" | ||
AutomationId="AbsoluteLayoutContentBtn"/> | ||
</HorizontalStackLayout> | ||
</Grid> | ||
</local:TestContentPage> |
189 changes: 189 additions & 0 deletions
189
src/Controls/tests/TestCases.HostApp/Issues/Issue30070.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,189 @@ | ||
using System.ComponentModel; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Maui.Controls.Sample.Issues | ||
{ | ||
[Issue(IssueTracker.Github, 30070, | ||
"ScrollView Orientation set to Horizontal allows both horizontal and vertical scrolling", | ||
PlatformAffected.iOS)] | ||
[XamlCompilation(XamlCompilationOptions.Skip)] | ||
public partial class Issue30070 : TestContentPage | ||
{ | ||
Issue30070ViewModel _viewModel; | ||
|
||
public Issue30070() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
protected override void Init() | ||
{ | ||
_viewModel = new Issue30070ViewModel(); | ||
BindingContext = _viewModel; | ||
} | ||
|
||
void OnContentTypeButtonClicked(object sender, EventArgs e) | ||
{ | ||
if (sender is not Button btn) | ||
{ | ||
return; | ||
} | ||
|
||
if (BindingContext is not Issue30070ViewModel vm) | ||
{ | ||
return; | ||
} | ||
|
||
switch (btn.Text) | ||
{ | ||
case "Label": | ||
vm.Content = new Label | ||
{ | ||
Text = string.Join(Environment.NewLine, | ||
Enumerable.Range(1, 100).Select(i => | ||
$"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, urna eu tincidunt consectetur, nisi nisl aliquam enim, eget facilisis enim nisl nec elit . Sed euismod, urna eu tincidunt consectetur, nisi nisl aliquam enim Eget facilisis enim nisl nec elit Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae. Nullam ac erat at dui laoreet aliquet. Praesent euismod, justo at dictum facilisis, urna erat dictum enim. {i}")), | ||
FontSize = 16, | ||
Padding = 10 | ||
}; | ||
break; | ||
case "Image": | ||
vm.Content = new Image | ||
{ | ||
Source = "dotnet_bot.png", | ||
HeightRequest = 2000, | ||
WidthRequest = 2000, | ||
Aspect = Aspect.AspectFit | ||
}; | ||
break; | ||
case "Editor": | ||
vm.Content = new Editor | ||
{ | ||
Text = string.Join(Environment.NewLine, | ||
Enumerable.Range(1, 100).Select(i => | ||
$"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, urna eu tincidunt consectetur, nisi nisl aliquam enim, eget facilisis enim nisl nec elit . Sed euismod, urna eu tincidunt consectetur, nisi nisl aliquam enim Eget facilisis enim nisl nec elit Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae. Nullam ac erat at dui laoreet aliquet. Praesent euismod, justo at dictum facilisis, urna erat dictum enim. {i}")), | ||
AutoSize = EditorAutoSizeOption.TextChanges | ||
}; | ||
break; | ||
case "Grid": | ||
var grid = new Grid(); | ||
for (int row = 0; row < 30; row++) | ||
{ | ||
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); | ||
} | ||
|
||
for (int col = 0; col < 20; col++) | ||
{ | ||
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star }); | ||
} | ||
|
||
string[] names = | ||
[ | ||
"Apple", "Banana", "Tomato", "Potato", "Orange", "Cucumber", "Broccoli", "Pineapple", | ||
"Strawberry", "Onion", "Lettuce", "Pear", "Kiwi", "Radish", "Cabbage", "Melon", "Plum", | ||
"Garlic", "Corn", "Blueberry", "Zucchini", "Bell Pepper", "Beetroot", "Avocado", | ||
"Asparagus", "Pomegranate", "Cauliflower", "Fennel", "Chili Pepper", "Mushroom", "Turnip", | ||
"Tangerine", "Radicchio", "Passion Fruit", "Endive", "Starfruit", "Kale", "Guava", "Chard", | ||
"Persimmon", "Arugula", "Coconut", "Celery", "Lychee", "Okra", "Dragon Fruit", "Squash", | ||
"Mulberry", "Artichoke", "Cranberry", "Parsnip", "Raspberry", "Pumpkin", "Blackberry", | ||
"Sweet Potato", "Grapefruit", "Eggplant", "Tamarind", "Nectarine" | ||
]; | ||
|
||
for (int row = 0; row < 30; row++) | ||
for (int col = 0; col < 20; col++) | ||
{ | ||
int index = (row * 20 + col) % names.Length; | ||
var cell = new Label | ||
{ | ||
Text = names[index], | ||
FontSize = 16, | ||
HorizontalOptions = LayoutOptions.Center, | ||
Padding = new Thickness(8) | ||
}; | ||
grid.Add(cell, col, row); | ||
} | ||
|
||
vm.Content = grid; | ||
break; | ||
|
||
case "AbsoluteLayout": | ||
var absolute = new AbsoluteLayout { HeightRequest = 800, WidthRequest = 800 }; | ||
|
||
for (int i = 0; i < 10; i++) | ||
{ | ||
var box = new BoxView | ||
{ | ||
Color = i % 2 == 0 ? Colors.CornflowerBlue : Colors.Orange, | ||
WidthRequest = 80, | ||
HeightRequest = 80 | ||
}; | ||
AbsoluteLayout.SetLayoutBounds(box, new Rect(30 + i * 70, 30 + i * 70, 80, 80)); | ||
absolute.Children.Add(box); | ||
} | ||
|
||
for (int i = 0; i < 10; i++) | ||
{ | ||
var box = new BoxView | ||
{ | ||
Color = i % 2 == 0 ? Colors.MediumPurple : Colors.ForestGreen, | ||
WidthRequest = 80, | ||
HeightRequest = 80 | ||
}; | ||
AbsoluteLayout.SetLayoutBounds(box, new Rect(30 + (9 - i) * 70, 30 + i * 70, 80, 80)); | ||
absolute.Children.Add(box); | ||
} | ||
|
||
vm.Content = absolute; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
public class Issue30070ViewModel : INotifyPropertyChanged | ||
{ | ||
string _contentText; | ||
View _content; | ||
|
||
public Issue30070ViewModel() | ||
{ | ||
Content = new Label | ||
{ | ||
Text = string.Join(Environment.NewLine, Enumerable.Range(1, 100).Select(i => $"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, urna eu tincidunt consectetur, nisi nisl aliquam enim, eget facilisis enim nisl nec elit . Sed euismod, urna eu tincidunt consectetur, nisi nisl aliquam enim Eget facilisis enim nisl nec elit Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae. Nullam ac erat at dui laoreet aliquet. Praesent euismod, justo at dictum facilisis, urna erat dictum enim. {i}")), | ||
FontSize = 18, | ||
Padding = 10 | ||
}; | ||
} | ||
|
||
public string ContentText | ||
{ | ||
get => _contentText; | ||
set | ||
{ | ||
if (_contentText != value) | ||
{ | ||
_contentText = value; | ||
Content = new Label { Text = _contentText }; // Update Content when ContentText changes | ||
OnPropertyChanged(); | ||
} | ||
} | ||
} | ||
|
||
|
||
public View Content | ||
{ | ||
get => _content; | ||
set | ||
{ | ||
if (_content != value) | ||
{ | ||
_content = value; | ||
OnPropertyChanged(); | ||
} | ||
} | ||
} | ||
|
||
public event PropertyChangedEventHandler PropertyChanged; | ||
|
||
protected void OnPropertyChanged([CallerMemberName] string propertyName = "") => | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
} |
Binary file added
BIN
+453 KB
src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ScrollViewOrientationTest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions
30
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30070.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,30 @@ | ||
#if IOS || MACCATALYST | ||
using NUnit.Framework; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
||
public class Issue30070 : _IssuesUITest | ||
{ | ||
public Issue30070(TestDevice device) : base(device) | ||
{ | ||
} | ||
|
||
public override string Issue => "ScrollView Orientation set to Horizontal allows both horizontal and vertical scrolling"; | ||
|
||
[Test] | ||
[Category(UITestCategories.ScrollView)] | ||
public void ScrollViewOrientationTest() | ||
{ | ||
App.WaitForElement("TestScrollView"); | ||
App.ScrollDown("TestScrollView"); | ||
|
||
// Wait to allow any temporary scroll indicators to disappear, | ||
// ensuring a clean screenshot for visual validation. | ||
Thread.Sleep(1000); | ||
|
||
VerifyScreenshot(); | ||
} | ||
} | ||
#endif |
Binary file added
BIN
+280 KB
src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ScrollViewOrientationTest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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 |
---|---|---|
|
@@ -61,5 +61,36 @@ public static void UpdateIsEnabled(this UIScrollView nativeScrollView, IScrollVi | |
nativeScrollView.ScrollEnabled = scrollView.IsEnabled; | ||
} | ||
} | ||
|
||
public static void UpdateOrientation(this UIScrollView nativeScrollView, IScrollView scrollView) | ||
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. A new public extension method Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
{ | ||
switch (scrollView.Orientation) | ||
{ | ||
case ScrollOrientation.Horizontal: | ||
nativeScrollView.AlwaysBounceHorizontal = true; | ||
nativeScrollView.AlwaysBounceVertical = false; | ||
nativeScrollView.ShowsHorizontalScrollIndicator = true; | ||
nativeScrollView.ShowsVerticalScrollIndicator = false; | ||
break; | ||
case ScrollOrientation.Vertical: | ||
nativeScrollView.AlwaysBounceHorizontal = false; | ||
nativeScrollView.AlwaysBounceVertical = true; | ||
nativeScrollView.ShowsHorizontalScrollIndicator = false; | ||
nativeScrollView.ShowsVerticalScrollIndicator = true; | ||
break; | ||
case ScrollOrientation.Both: | ||
nativeScrollView.AlwaysBounceHorizontal = true; | ||
nativeScrollView.AlwaysBounceVertical = true; | ||
nativeScrollView.ShowsHorizontalScrollIndicator = true; | ||
nativeScrollView.ShowsVerticalScrollIndicator = true; | ||
break; | ||
case ScrollOrientation.Neither: | ||
nativeScrollView.AlwaysBounceHorizontal = false; | ||
nativeScrollView.AlwaysBounceVertical = false; | ||
nativeScrollView.ShowsHorizontalScrollIndicator = false; | ||
nativeScrollView.ShowsVerticalScrollIndicator = false; | ||
break; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
The Editor button reuses the "GridContentBtn" AutomationId, causing a duplicate; assign a unique AutomationId (e.g. "EditorContentBtn") to ensure UI tests can target each control correctly.
Copilot uses AI. Check for mistakes.