From 8b04a8a6da462e37ed3dcb91d9642e6f7fe37b11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Sua=CC=81rez?= Date: Tue, 29 Nov 2022 10:54:35 +0100 Subject: [PATCH 1/4] Added samples --- .../ContentPageBackgroundGallery.xaml | 24 ++++++++++++++ .../ContentPageBackgroundGallery.xaml.cs | 10 ++++++ .../ContentPageBackgroundImageGallery.xaml | 16 +++++++++ .../ContentPageBackgroundImageGallery.xaml.cs | 10 ++++++ .../ContentPageGallery.cs | 33 +++++++++++++++++++ 5 files changed, 93 insertions(+) create mode 100644 src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGalleries/ContentPageBackgroundGallery.xaml create mode 100644 src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGalleries/ContentPageBackgroundGallery.xaml.cs create mode 100644 src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGalleries/ContentPageBackgroundImageGallery.xaml create mode 100644 src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGalleries/ContentPageBackgroundImageGallery.xaml.cs create mode 100644 src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGalleries/ContentPageGallery.cs diff --git a/src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGalleries/ContentPageBackgroundGallery.xaml b/src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGalleries/ContentPageBackgroundGallery.xaml new file mode 100644 index 000000000000..e6fae7a347e7 --- /dev/null +++ b/src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGalleries/ContentPageBackgroundGallery.xaml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGalleries/ContentPageBackgroundGallery.xaml.cs b/src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGalleries/ContentPageBackgroundGallery.xaml.cs new file mode 100644 index 000000000000..072195b56e0c --- /dev/null +++ b/src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGalleries/ContentPageBackgroundGallery.xaml.cs @@ -0,0 +1,10 @@ +namespace Maui.Controls.Sample.Pages +{ + public partial class ContentPageBackgroundGallery + { + public ContentPageBackgroundGallery() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGalleries/ContentPageBackgroundImageGallery.xaml b/src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGalleries/ContentPageBackgroundImageGallery.xaml new file mode 100644 index 000000000000..aade48a9b4f6 --- /dev/null +++ b/src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGalleries/ContentPageBackgroundImageGallery.xaml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGalleries/ContentPageBackgroundImageGallery.xaml.cs b/src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGalleries/ContentPageBackgroundImageGallery.xaml.cs new file mode 100644 index 000000000000..a9708b358262 --- /dev/null +++ b/src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGalleries/ContentPageBackgroundImageGallery.xaml.cs @@ -0,0 +1,10 @@ +namespace Maui.Controls.Sample.Pages +{ + public partial class ContentPageBackgroundImageGallery + { + public ContentPageBackgroundImageGallery() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGalleries/ContentPageGallery.cs b/src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGalleries/ContentPageGallery.cs new file mode 100644 index 000000000000..a7842ac01fad --- /dev/null +++ b/src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGalleries/ContentPageGallery.cs @@ -0,0 +1,33 @@ +using Microsoft.Maui; +using Microsoft.Maui.Controls; +using Microsoft.Maui.Controls.Internals; + +namespace Maui.Controls.Sample.Pages +{ + [Preserve(AllMembers = true)] + public class ContentPageGallery : ContentPage + { + public ContentPageGallery() + { + var descriptionLabel = + new Label { Text = "ContentPage Galleries", Margin = new Thickness(2, 2, 2, 2) }; + + Title = "ContentPage Galleries"; + + Content = new ScrollView + { + Content = new StackLayout + { + Children = + { + descriptionLabel, + GalleryBuilder.NavButton("ContentPage BackgroundImage", () => + new ContentPageBackgroundImageGallery(), Navigation), + GalleryBuilder.NavButton("ContentPage Background", () => + new ContentPageBackgroundGallery(), Navigation), + } + } + }; + } + } +} \ No newline at end of file From bf70419a0934f6960a4762c79f66fbb900673099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Sua=CC=81rez?= Date: Tue, 29 Nov 2022 10:54:45 +0100 Subject: [PATCH 2/4] Fix the bug --- .../Pages/Core/ContentPageGallery.xaml | 16 ---------------- .../Pages/Core/ContentPageGallery.xaml.cs | 10 ---------- src/Core/src/Platform/iOS/ViewExtensions.cs | 15 +++++++++++++-- 3 files changed, 13 insertions(+), 28 deletions(-) delete mode 100644 src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGallery.xaml delete mode 100644 src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGallery.xaml.cs diff --git a/src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGallery.xaml b/src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGallery.xaml deleted file mode 100644 index edb658224e59..000000000000 --- a/src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGallery.xaml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGallery.xaml.cs b/src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGallery.xaml.cs deleted file mode 100644 index affb63b96b1c..000000000000 --- a/src/Controls/samples/Controls.Sample/Pages/Core/ContentPageGallery.xaml.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Maui.Controls.Sample.Pages -{ - public partial class ContentPageGallery - { - public ContentPageGallery() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/src/Core/src/Platform/iOS/ViewExtensions.cs b/src/Core/src/Platform/iOS/ViewExtensions.cs index 0874ea676d9b..74f9fb56474c 100644 --- a/src/Core/src/Platform/iOS/ViewExtensions.cs +++ b/src/Core/src/Platform/iOS/ViewExtensions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Numerics; using System.Threading.Tasks; +using CoreAnimation; using CoreGraphics; using Foundation; using Microsoft.Maui.Devices; @@ -264,14 +265,24 @@ public static void UpdateBackgroundLayerFrame(this UIView view) var layer = view.Layer; + UpdateBackgroundLayerFrame(layer, view.Bounds); + } + + static void UpdateBackgroundLayerFrame(CALayer layer, CGRect bounds) + { if (layer == null || layer.Sublayers == null || layer.Sublayers.Length == 0) return; foreach (var sublayer in layer.Sublayers) { - if (sublayer.Name == BackgroundLayerName && sublayer.Frame != view.Bounds) + UpdateBackgroundLayerFrame(sublayer, bounds); + } + + foreach (var sublayer in layer.Sublayers) + { + if (sublayer.Name == BackgroundLayerName && sublayer.Frame != bounds) { - sublayer.Frame = view.Bounds; + sublayer.Frame = bounds; break; } } From 5cf46b53230c29b5407d2b96bf20d77af19aa720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Sua=CC=81rez?= Date: Tue, 29 Nov 2022 10:55:00 +0100 Subject: [PATCH 3/4] Added device tests --- .../ContentView/ContentViewTests.iOS.cs | 38 +++++++++++++++---- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/src/Core/tests/DeviceTests/Handlers/ContentView/ContentViewTests.iOS.cs b/src/Core/tests/DeviceTests/Handlers/ContentView/ContentViewTests.iOS.cs index 3afc3a80763c..70fb6de52381 100644 --- a/src/Core/tests/DeviceTests/Handlers/ContentView/ContentViewTests.iOS.cs +++ b/src/Core/tests/DeviceTests/Handlers/ContentView/ContentViewTests.iOS.cs @@ -1,15 +1,7 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection.Metadata; using System.Threading.Tasks; -using Microsoft.Maui.Controls; using Microsoft.Maui.DeviceTests.Stubs; -using Microsoft.Maui.Graphics; -using Microsoft.Maui.Handlers; -using ObjCRuntime; using UIKit; -using UserNotificationsUI; using Xunit; namespace Microsoft.Maui.DeviceTests.Handlers.ContentView @@ -17,6 +9,23 @@ namespace Microsoft.Maui.DeviceTests.Handlers.ContentView [Category(TestCategory.ContentView)] public partial class ContentViewTests { + [Theory(DisplayName = "Background Updates Correctly")] + [InlineData(0xFF0000)] + [InlineData(0x00FF00)] + [InlineData(0x0000FF)] + public async Task BackgroundUpdatesCorrectly(uint color) + { + var expected = Color.FromUint(color); + + var contentView = new ContentViewStub() + { + Content = new LabelStub { Text = "Background", TextColor = Colors.White }, + Background = new LinearGradientPaintStub(Colors.Red, Colors.Blue), + }; + + await ValidateHasColor(contentView, expected); + } + [Fact, Category(TestCategory.FlowDirection)] public async Task FlowDirectionPropagatesToContent() { @@ -114,5 +123,18 @@ public async Task DoesNotPropagateToContentWithExplicitFlowDirection() Assert.Equal(UIUserInterfaceLayoutDirection.LeftToRight, labelFlowDirection); } + + Platform.ContentView GetNativeContentView(ContentViewHandler contentViewHandler) => + contentViewHandler.PlatformView; + + Task ValidateHasColor(IContentView contentView, Color color, Action action = null) + { + return InvokeOnMainThreadAsync(() => + { + var nativeContentView = GetNativeContentView(CreateHandler(contentView)); + action?.Invoke(); + nativeContentView.AssertContainsColor(color); + }); + } } } From a44461d5ea9811a19e8c084c138627582393864b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Sua=CC=81rez?= Date: Wed, 18 Jan 2023 13:33:13 +0100 Subject: [PATCH 4/4] Removed unnecessary loop --- src/Core/src/Platform/iOS/ViewExtensions.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Core/src/Platform/iOS/ViewExtensions.cs b/src/Core/src/Platform/iOS/ViewExtensions.cs index 74f9fb56474c..ef70664cac3d 100644 --- a/src/Core/src/Platform/iOS/ViewExtensions.cs +++ b/src/Core/src/Platform/iOS/ViewExtensions.cs @@ -272,12 +272,7 @@ static void UpdateBackgroundLayerFrame(CALayer layer, CGRect bounds) { if (layer == null || layer.Sublayers == null || layer.Sublayers.Length == 0) return; - - foreach (var sublayer in layer.Sublayers) - { - UpdateBackgroundLayerFrame(sublayer, bounds); - } - + foreach (var sublayer in layer.Sublayers) { if (sublayer.Name == BackgroundLayerName && sublayer.Frame != bounds) @@ -285,6 +280,8 @@ static void UpdateBackgroundLayerFrame(CALayer layer, CGRect bounds) sublayer.Frame = bounds; break; } + + UpdateBackgroundLayerFrame(sublayer, bounds); } }