From 3ebae5dd1111758a3c715c76c39a5cf63be73ab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez?= Date: Thu, 30 Jul 2020 01:36:47 +0200 Subject: [PATCH] [Android] Fix issue using SwipeView in ListView using a RippleEffect (#11380) * Added repro sample * Fixed the issue Co-authored-by: Samantha Houts fixes #11374 --- .../RippleEffect.cs | 40 +++++++++ ...amarin.Forms.ControlGallery.Android.csproj | 1 + .../Issue11374.xaml | 83 +++++++++++++++++++ .../Issue11374.xaml.cs | 69 +++++++++++++++ ...rin.Forms.Controls.Issues.Shared.projitems | 4 + .../Renderers/SwipeViewRenderer.cs | 2 +- 6 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 Xamarin.Forms.ControlGallery.Android/RippleEffect.cs create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue11374.xaml create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue11374.xaml.cs diff --git a/Xamarin.Forms.ControlGallery.Android/RippleEffect.cs b/Xamarin.Forms.ControlGallery.Android/RippleEffect.cs new file mode 100644 index 000000000..0d8b421b9 --- /dev/null +++ b/Xamarin.Forms.ControlGallery.Android/RippleEffect.cs @@ -0,0 +1,40 @@ +using Android.Util; +using Xamarin.Forms; +using Xamarin.Forms.Internals; +using Xamarin.Forms.Platform.Android; +using AView = Android.Views.View; + +[assembly: ExportEffect(typeof(Xamarin.Forms.ControlGallery.Android.RippleEffect), nameof(Xamarin.Forms.ControlGallery.Android.RippleEffect))] +namespace Xamarin.Forms.ControlGallery.Android +{ + [Preserve(AllMembers = true)] + public class RippleEffect : PlatformEffect + { + protected override void OnAttached() + { + try + { + if (Container is AView view) + { + view.Clickable = true; + view.Focusable = true; + + using (var outValue = new TypedValue()) + { + view.Context.Theme.ResolveAttribute(Resource.Attribute.selectableItemBackground, outValue, true); + view.SetBackgroundResource(outValue.ResourceId); + } + } + } + catch + { + + } + } + + protected override void OnDetached() + { + + } + } +} diff --git a/Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj b/Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj index 6b39e2d85..e57dccdc9 100644 --- a/Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj +++ b/Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj @@ -137,6 +137,7 @@ + diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue11374.xaml b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue11374.xaml new file mode 100644 index 000000000..76706bcd6 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue11374.xaml @@ -0,0 +1,83 @@ + + + + + + + + + \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue11374.xaml.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue11374.xaml.cs new file mode 100644 index 000000000..2ef56c180 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue11374.xaml.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +using Xamarin.Forms.Core.UITests; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Github, 11374, + "[Bug] [Android] SwipeView in ListView is not working with RippleEffect and Release configuration", + PlatformAffected.Android)] + public partial class Issue11374 : TestContentPage + { + public Issue11374() + { +#if APP + Device.SetFlags(new List { ExperimentalFlags.SwipeViewExperimental }); + + InitializeComponent(); +#endif + } + + protected override void Init() + { + BindingContext = new Issue11374ViewModel(); + } + } + + [Preserve(AllMembers = true)] + public class Issue11374ViewModel : BindableObject + { + public ObservableCollection Items { get; set; } + + public Command LoadItemsCommand { get; set; } + + public Issue11374ViewModel() + { + LoadItems(); + } + + void LoadItems() + { + Items = new ObservableCollection + { + "Item 1", + "Item 2", + "Item 3", + "Item 4", + "Item 5" + }; + } + } + + [Preserve(AllMembers = true)] + public class RippleEffect : RoutingEffect + { + public RippleEffect() : base($"{Effects.ResolutionGroupName}.{nameof(RippleEffect)}") + { + + } + } +} \ No newline at end of file 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 1fac1c426..6abdbb571 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 @@ -1440,6 +1440,7 @@ + @@ -1690,6 +1691,9 @@ MSBuild:UpdateDesignTimeXaml + + MSBuild:UpdateDesignTimeXaml + MSBuild:UpdateDesignTimeXaml diff --git a/Xamarin.Forms.Platform.Android/Renderers/SwipeViewRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/SwipeViewRenderer.cs index 4171d9ea0..8c8a4bb38 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/SwipeViewRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/SwipeViewRenderer.cs @@ -277,7 +277,7 @@ namespace Xamarin.Forms.Platform.Android public override bool OnInterceptTouchEvent(MotionEvent e) { - return false; + return ShouldInterceptTouch(e); } public override bool DispatchTouchEvent(MotionEvent e)