[iOS] Fix Bounds for PageContainer (#6405)
* [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
This commit is contained in:
Родитель
1db7a74311
Коммит
b488b5df1f
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -123,6 +123,7 @@
|
|||
<Compile Include="..\xamarin.forms.controls\gallerypages\openglgalleries\AdvancedOpenGLGallery.cs">
|
||||
<Link>GalleryPages\AdvancedOpenGLGallery.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="CustomEffects\GradientEffect.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Xamarin.Forms.Controls\Xamarin.Forms.Controls.csproj">
|
||||
|
@ -397,6 +398,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Resources\Fonts\" />
|
||||
<Folder Include="CustomEffects\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
|
||||
</Project>
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -934,6 +934,7 @@
|
|||
<Compile Include="$(MSBuildThisFileDirectory)Issue5951.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue5132.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue5888.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue6334.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">
|
||||
|
@ -1199,7 +1200,7 @@
|
|||
<ItemGroup>
|
||||
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue6130.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace Xamarin.Forms.Platform.iOS
|
|||
|
||||
public PageContainer(IAccessibilityElementsController parent)
|
||||
{
|
||||
AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
|
||||
_parent = parent;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче