Skip to content

Commit 5f359cd

Browse files
committed
ScrollView's Background on iOS
1 parent 083ffa8 commit 5f359cd

File tree

11 files changed

+125
-0
lines changed

11 files changed

+125
-0
lines changed
23.6 KB
Loading
12.4 KB
Loading
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Maui.Controls.Sample.Issues.Issue24061"
5+
xmlns:ns="clr-namespace:Maui.Controls.Sample.Issues">
6+
<VerticalStackLayout>
7+
<ScrollView Orientation="Horizontal"
8+
x:Name="scrollView"
9+
HeightRequest="120">
10+
11+
<ScrollView.Background>
12+
<LinearGradientBrush StartPoint="0,0.5"
13+
EndPoint="1,0.5">
14+
<LinearGradientBrush.GradientStops>
15+
<GradientStop Color="White"
16+
Offset="0.75"/>
17+
<GradientStop Color="Green"
18+
Offset="1"/>
19+
</LinearGradientBrush.GradientStops>
20+
</LinearGradientBrush>
21+
</ScrollView.Background>
22+
<StackLayout Orientation="Horizontal">
23+
<BindableLayout.ItemsSource>
24+
<x:Array Type="{x:Type x:String}">
25+
<x:String>Item1</x:String>
26+
<x:String>Item2</x:String>
27+
<x:String>Item3</x:String>
28+
<x:String>Item4</x:String>
29+
<x:String>Item5</x:String>
30+
</x:Array>
31+
</BindableLayout.ItemsSource>
32+
<BindableLayout.ItemTemplate>
33+
<DataTemplate>
34+
<BoxView WidthRequest="100"
35+
HeightRequest="100"
36+
AutomationId="{Binding .}"
37+
BackgroundColor="Black"
38+
Margin="10"/>
39+
</DataTemplate>
40+
</BindableLayout.ItemTemplate>
41+
</StackLayout>
42+
</ScrollView>
43+
<Button AutomationId="button"
44+
Clicked="Button_Clicked"
45+
Text="Remove/Add scroll view background"/>
46+
</VerticalStackLayout>
47+
</ContentPage>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace Maui.Controls.Sample.Issues
2+
{
3+
[Issue(IssueTracker.Github, 24061, "ScrollView's gradient background doesn't work with ScrollView", PlatformAffected.iOS)]
4+
public partial class Issue24061 : ContentPage
5+
{
6+
LinearGradientBrush _linearGradientBrush;
7+
8+
public Issue24061()
9+
{
10+
InitializeComponent();
11+
_linearGradientBrush = new LinearGradientBrush
12+
{
13+
StartPoint = new Point(0, 0.5),
14+
EndPoint = new Point(1, 0.5),
15+
GradientStops = new GradientStopCollection
16+
{
17+
new GradientStop { Color = Colors.White, Offset = 0.75f },
18+
new GradientStop { Color = Colors.Green, Offset = 1 }
19+
}
20+
};
21+
scrollView.Background = _linearGradientBrush;
22+
}
23+
24+
private void Button_Clicked(object sender, EventArgs e)
25+
{
26+
if (scrollView.Background != null)
27+
scrollView.Background = Colors.Transparent;
28+
else
29+
scrollView.Background = _linearGradientBrush;
30+
}
31+
}
32+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues
6+
{
7+
public class Issue24061 : _IssuesUITest
8+
{
9+
public Issue24061(TestDevice testDevice) : base(testDevice)
10+
{
11+
}
12+
13+
public override string Issue => "ScrollView's gradient background doesn't work with ScrollView";
14+
15+
[Test]
16+
[Category(UITestCategories.ScrollView)]
17+
public void ScrollViewGradientBackgroundShouldWorkWithScrollView()
18+
{
19+
App.WaitForElement("Item2");
20+
App.SwipeRightToLeft("Item2", 0.99);
21+
22+
VerifyScreenshot("ScrollViewGradientBackground");
23+
App.Click("button");
24+
VerifyScreenshot("ScrollViewWithoutGradientBackground");
25+
App.Click("button");
26+
VerifyScreenshot("ScrollViewGradientBackground");
27+
}
28+
}
29+
}
53.8 KB
Loading
11.3 KB
Loading

src/Core/src/Handlers/ScrollView/ScrollViewHandler.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public partial class ScrollViewHandler : IScrollViewHandler
2222
[nameof(IScrollView.HorizontalScrollBarVisibility)] = MapHorizontalScrollBarVisibility,
2323
[nameof(IScrollView.VerticalScrollBarVisibility)] = MapVerticalScrollBarVisibility,
2424
[nameof(IScrollView.Orientation)] = MapOrientation,
25+
#if __IOS__ || MACCATALYST
26+
[nameof(IScrollView.Background)] = MapBackground,
27+
#endif
2528
#if __IOS__
2629
[nameof(IScrollView.IsEnabled)] = MapIsEnabled,
2730
#endif

src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ public override bool NeedsContainer
2323
{
2424
return true;
2525
}
26+
27+
if(VirtualView?.Background is not null)
28+
{
29+
return true;
30+
}
31+
2632
return base.NeedsContainer;
2733
}
2834
}
@@ -75,6 +81,12 @@ public static void MapIsEnabled(IScrollViewHandler handler, IScrollView scrollVi
7581
handler.PlatformView?.UpdateIsEnabled(scrollView);
7682
}
7783

84+
public static void MapBackground(IScrollViewHandler handler, IScrollView scrollView)
85+
{
86+
handler.UpdateValue(nameof(IViewHandler.ContainerView));
87+
handler.ToPlatform().UpdateBackground(scrollView);
88+
}
89+
7890
public static void MapHorizontalScrollBarVisibility(IScrollViewHandler handler, IScrollView scrollView)
7991
{
8092
handler.PlatformView?.UpdateHorizontalScrollBarVisibility(scrollView.HorizontalScrollBarVisibility);

src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static Microsoft.Maui.Handlers.HybridWebViewHandler.MapInvokeJavaScriptAsync(Mic
6666
static Microsoft.Maui.Handlers.HybridWebViewHandler.Mapper -> Microsoft.Maui.IPropertyMapper<Microsoft.Maui.IHybridWebView!, Microsoft.Maui.Handlers.IHybridWebViewHandler!>!
6767
static Microsoft.Maui.Handlers.HybridWebViewHandler.MapSendRawMessage(Microsoft.Maui.Handlers.IHybridWebViewHandler! handler, Microsoft.Maui.IHybridWebView! hybridWebView, object? arg) -> void
6868
static Microsoft.Maui.Hosting.HybridWebViewServiceCollectionExtensions.AddHybridWebViewDeveloperTools(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
69+
static Microsoft.Maui.Handlers.ScrollViewHandler.MapBackground(Microsoft.Maui.Handlers.IScrollViewHandler! handler, Microsoft.Maui.IScrollView! scrollView) -> void
6970
static Microsoft.Maui.Keyboard.Date.get -> Microsoft.Maui.Keyboard!
7071
static Microsoft.Maui.Keyboard.Password.get -> Microsoft.Maui.Keyboard!
7172
static Microsoft.Maui.Keyboard.Time.get -> Microsoft.Maui.Keyboard!

0 commit comments

Comments
 (0)