[Android] ScrollView can now consume Effects (#836)
authorSamantha Houts <samhouts@users.noreply.github.com>
Thu, 23 Mar 2017 23:12:41 +0000 (16:12 -0700)
committerE.Z. Hart <hartez@users.noreply.github.com>
Thu, 23 Mar 2017 23:12:41 +0000 (17:12 -0600)
* Add repro

* [Android] Make ScrollView an IEffectControlProvider

Xamarin.Forms.ControlGallery.Android/Activity1.cs
Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla45874.cs [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
Xamarin.Forms.Platform.Android/Renderers/ScrollViewRenderer.cs

index 6f2b22d..b0491b0 100644 (file)
@@ -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 ()
index 1aed773..03f145b 100644 (file)
@@ -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()
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla45874.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla45874.cs
new file mode 100644 (file)
index 0000000..46c5360
--- /dev/null
@@ -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
+       }
+}
\ No newline at end of file
index ced1ef5..5a8d41f 100644 (file)
     <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" />
index a2e3ddb..b796141 100644 (file)
@@ -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);