[Android] ScrollView can now consume Effects (#836)

* Add repro

* [Android] Make ScrollView an IEffectControlProvider
This commit is contained in:
Samantha Houts 2017-03-23 16:12:41 -07:00 коммит произвёл E.Z. Hart
Родитель f27f5a3650
Коммит 79ecf97d92
5 изменённых файлов: 70 добавлений и 1 удалений

Просмотреть файл

@ -39,6 +39,10 @@ namespace Xamarin.Forms.ControlGallery.Android
protected override void OnAttached ()
{
Control.SetBackgroundColor (global::Android.Graphics.Color.Aqua);
var childLabel = (Element as ScrollView)?.Content as Label;
if (childLabel != null)
childLabel.Text = "Success";
}
protected override void OnDetached ()

Просмотреть файл

@ -25,6 +25,10 @@ namespace Xamarin.Forms.ControlGallery.iOS
protected override void OnAttached()
{
Control.BackgroundColor = UIColor.Blue;
var childLabel = (Element as ScrollView)?.Content as Label;
if (childLabel != null)
childLabel.Text = "Success";
}
protected override void OnDetached()

Просмотреть файл

@ -0,0 +1,44 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif
// Apply the default category of "Issues" to all of the tests in this assembly
// We use this as a catch-all for tests which haven't been individually categorized
#if UITEST
[assembly: NUnit.Framework.Category("Issues")]
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Bugzilla, 45874, "Effect not attaching to ScrollView", PlatformAffected.iOS | PlatformAffected.Android)]
public class Bugzilla45874 : TestContentPage
{
const string Success = "Success";
protected override void Init()
{
var label = new Label { Text = "FAIL" };
var scrollView = new ScrollView { Content = label };
var effect = Effect.Resolve("XamControl.BorderEffect");
scrollView.Effects.Add(effect);
Content = scrollView;
}
#if UITEST
[Test]
public void Bugzilla45874Test()
{
RunningApp.WaitForElement(q => q.Marked(Success));
}
#endif
}
}

Просмотреть файл

@ -266,6 +266,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla51505.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla52533.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla53362.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla45874.cs" />
<Compile Include="$(MSBuildThisFileDirectory)_Template.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1028.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1075.cs" />

Просмотреть файл

@ -5,11 +5,12 @@ using Android.Animation;
using Android.Graphics;
using Android.Views;
using Android.Widget;
using Xamarin.Forms.Internals;
using AScrollView = Android.Widget.ScrollView;
namespace Xamarin.Forms.Platform.Android
{
public class ScrollViewRenderer : AScrollView, IVisualElementRenderer
public class ScrollViewRenderer : AScrollView, IVisualElementRenderer, IEffectControlProvider
{
ScrollViewContainer _container;
HorizontalScrollView _hScrollView;
@ -77,6 +78,8 @@ namespace Xamarin.Forms.Platform.Android
if (!string.IsNullOrEmpty(element.AutomationId))
ContentDescription = element.AutomationId;
}
EffectUtilities.RegisterEffectControlProvider(this, oldElement, element);
}
public VisualElementTracker Tracker { get; private set; }
@ -216,6 +219,19 @@ namespace Xamarin.Forms.Platform.Android
}
}
void IEffectControlProvider.RegisterEffect(Effect effect)
{
var platformEffect = effect as PlatformEffect;
if (platformEffect != null)
OnRegisterEffect(platformEffect);
}
void OnRegisterEffect(PlatformEffect effect)
{
effect.SetContainer(this);
effect.SetControl(this);
}
static int GetDistance(double start, double position, double v)
{
return (int)(start + (position - start) * v);