From b488b5df1f235f888182d97a1a31d5c65a57f7d9 Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Thu, 6 Jun 2019 05:07:59 +0100 Subject: [PATCH] =?UTF-8?q?[iOS]=C2=A0Fix=20Bounds=20for=20PageContainer?= =?UTF-8?q?=20=20(#6405)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Controls] Add repo for issue #6334 * [iOS] Give a default size to the PageContainer so Effects can use Bounds * {UITests] Update AutomationID fixes #6334 fixes #6372 --- .../AppDelegate.cs | 2 +- .../CustomEffects/GradientEffect.cs | 62 +++++++++++++++++++ .../Xamarin.Forms.ControlGallery.iOS.csproj | 2 + .../Issue6334.cs | 47 ++++++++++++++ ...rin.Forms.Controls.Issues.Shared.projitems | 3 +- .../Renderers/PageContainer.cs | 1 + .../Renderers/PageRenderer.cs | 3 +- 7 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 Xamarin.Forms.ControlGallery.iOS/CustomEffects/GradientEffect.cs create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue6334.cs diff --git a/Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs b/Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs index a14818e3c..91a173e7e 100644 --- a/Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs +++ b/Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs @@ -15,7 +15,7 @@ using Xamarin.Forms.Platform.iOS; [assembly: Dependency(typeof(CacheService))] [assembly: ExportRenderer(typeof(DisposePage), typeof(DisposePageRenderer))] [assembly: ExportRenderer(typeof(DisposeLabel), typeof(DisposeLabelRenderer))] -[assembly: ExportEffect(typeof(BorderEffect), "BorderEffect")] +[assembly: ExportEffect(typeof(BorderEffect), nameof(BorderEffect))] namespace Xamarin.Forms.ControlGallery.iOS { public class BorderEffect : PlatformEffect diff --git a/Xamarin.Forms.ControlGallery.iOS/CustomEffects/GradientEffect.cs b/Xamarin.Forms.ControlGallery.iOS/CustomEffects/GradientEffect.cs new file mode 100644 index 000000000..b8e3c5118 --- /dev/null +++ b/Xamarin.Forms.ControlGallery.iOS/CustomEffects/GradientEffect.cs @@ -0,0 +1,62 @@ +using System; +using System.ComponentModel; +using CoreAnimation; +using CoreGraphics; +using Xamarin.Forms; +using Xamarin.Forms.ControlGallery.iOS; +using Xamarin.Forms.Controls.Issues; +using Xamarin.Forms.Platform.iOS; + +[assembly: ExportEffect(typeof(GradientEffect), Issue6334.EffectName)] +namespace Xamarin.Forms.ControlGallery.iOS +{ + public class GradientEffect : PlatformEffect + { + protected override void OnAttached() + { + InsertGradient(); + } + + CAGradientLayer layer; + void InsertGradient() + { + System.Diagnostics.Debug.WriteLine("InsertGradient : " + Container.Bounds); + var page = Element as ContentPage; + var childLabel = page?.Content as Label; + if (childLabel != null && Container.Bounds.Width == 0) + { + return; + } + + if (layer == null) + { + + childLabel.Text = Issue6334.Success; + + var eColor = page.BackgroundColor.ToCGColor(); + var sColor = page.BackgroundColor.AddLuminosity(0.5).ToCGColor(); + layer = new CAGradientLayer + { + Frame = Container.Bounds, + Colors = new CGColor[] { sColor, eColor } + }; + Container.Layer.InsertSublayer(layer, 0); + } + } + + protected override void OnElementPropertyChanged(PropertyChangedEventArgs args) + { + base.OnElementPropertyChanged(args); + if (args.PropertyName == Page.WidthProperty.PropertyName || + args.PropertyName == Page.HeightProperty.PropertyName) + { + layer.Frame = Container.Bounds; + // or (Element as VisualElement).Bounds.ToRectangleF(); + } + } + + protected override void OnDetached() + { + } + } +} diff --git a/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj b/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj index 08e9a9716..ebe63e973 100644 --- a/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj +++ b/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj @@ -123,6 +123,7 @@ GalleryPages\AdvancedOpenGLGallery.cs + @@ -397,6 +398,7 @@ + diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue6334.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue6334.cs new file mode 100644 index 000000000..18096ec93 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue6334.cs @@ -0,0 +1,47 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +#if UITEST +using Xamarin.Forms.Core.UITests; +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ +#if UITEST + [Category(UITestCategories.ManualReview)] +#endif + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Github, 6334, "iOS effect no longer works after upgrading to XF 4.0 since UIView.Bounds has no size", PlatformAffected.iOS)] + public class Issue6334 : TestContentPage + { + public const string EffectName = "GradientEffect"; + public const string Success = "Success"; + public const string Fail = "Fail"; + + protected override void Init() + { + BackgroundColor = Color.Blue; + var effect = Effect.Resolve($"{Issues.Effects.ResolutionGroupName}.{EffectName}"); + + Effects.Add(effect); + + Content = new Label + { + AutomationId = "IssuePageLabel", + Text = Fail + }; + } + +#if UITEST && __IOS__ + [Test] + public void Issue6334Test() + { + RunningApp.WaitForElement (q => q.Marked ("IssuePageLabel")); + RunningApp.WaitForElement(q => q.Marked(Success)); + RunningApp.Screenshot ("I see the gradient"); + } +#endif + } +} diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 1e5359d3e..1089ca8d5 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -934,6 +934,7 @@ + @@ -1199,7 +1200,7 @@ Designer - MSBuild:Compile + MSBuild:UpdateDesignTimeXaml diff --git a/Xamarin.Forms.Platform.iOS/Renderers/PageContainer.cs b/Xamarin.Forms.Platform.iOS/Renderers/PageContainer.cs index 054d751a4..b34a38562 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/PageContainer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/PageContainer.cs @@ -14,6 +14,7 @@ namespace Xamarin.Forms.Platform.iOS public PageContainer(IAccessibilityElementsController parent) { + AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; _parent = parent; } diff --git a/Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs index b58677dcc..b3f6b6f3e 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs @@ -123,8 +123,9 @@ namespace Xamarin.Forms.Platform.iOS public override void LoadView() { + //by default use the MainScreen Bounds so Effects can access the Container size if (_pageContainer == null) - _pageContainer = new PageContainer(this); + _pageContainer = new PageContainer(this) { Frame = UIScreen.MainScreen.Bounds}; View = _pageContainer; }