From 515c4553dbbb25c6ab9a7f763ea6ac888b66ac3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez=20Ruiz?= Date: Mon, 9 Mar 2020 15:29:39 +0100 Subject: [PATCH] [Android, iOS] Allow transparent background color in SwipeView Content (#9726) fixes #9305 * Allow transparent background color in SwipeView * Update Xamarin.Forms.Controls.Issues.Shared.projitems Co-authored-by: Rui Marinho --- .../Issue9305.xaml | 59 +++++++++++++++++++ .../Issue9305.xaml.cs | 29 +++++++++ ...rin.Forms.Controls.Issues.Shared.projitems | 7 ++- .../Renderers/SwipeViewRenderer.cs | 11 ++-- .../Renderers/SwipeViewRenderer.cs | 7 +-- 5 files changed, 102 insertions(+), 11 deletions(-) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue9305.xaml create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue9305.xaml.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue9305.xaml b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue9305.xaml new file mode 100644 index 000000000..99ea892a0 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue9305.xaml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue9305.xaml.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue9305.xaml.cs new file mode 100644 index 000000000..5ba29c6d8 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue9305.xaml.cs @@ -0,0 +1,29 @@ +using Xamarin.Forms.CustomAttributes; +using System.Collections.Generic; + +#if UITEST +using Xamarin.Forms.Core.UITests; +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ + [Issue(IssueTracker.Github, 9305, "Swipe View BackgroundColor Issues", PlatformAffected.Android | PlatformAffected.iOS)] + public partial class Issue9305 : TestContentPage + { + public Issue9305() + { +#if APP + Device.SetFlags(new List { ExperimentalFlags.SwipeViewExperimental }); + Title = "Issue 9305"; + InitializeComponent(); +#endif + } + + protected override void Init() + { + + } + } +} \ 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 af3d59103..e579c905c 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 @@ -1268,6 +1268,7 @@ + @@ -1418,6 +1419,10 @@ + + Designer + MSBuild:UpdateDesignTimeXaml + MSBuild:UpdateDesignTimeXaml @@ -1834,4 +1839,4 @@ MSBuild:UpdateDesignTimeXaml - \ No newline at end of file + diff --git a/Xamarin.Forms.Platform.Android/Renderers/SwipeViewRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/SwipeViewRenderer.cs index a45370f75..d8dc5c64f 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/SwipeViewRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/SwipeViewRenderer.cs @@ -28,7 +28,6 @@ namespace Xamarin.Forms.Platform.Android public class SwipeViewRenderer : ViewRenderer, GestureDetector.IOnGestureListener { const int SwipeThreshold = 250; - const int SwipeThresholdMargin = 0; const int SwipeItemWidth = 100; const long SwipeAnimationDuration = 200; const float SwipeMinimumDelta = 10f; @@ -141,7 +140,7 @@ namespace Xamarin.Forms.Platform.Android SetBackgroundColor(backgroundColor); - if (Element.Content == null) + if (Element.Content == null || (Element.Content != null && Element.Content.BackgroundColor == Color.Default)) _contentView?.SetBackgroundColor(backgroundColor); } else @@ -578,7 +577,7 @@ namespace Xamarin.Forms.Platform.Android void UpdateSwipeItems() { - if (_contentView == null) + if (_contentView == null || _actionView != null) return; var items = GetSwipeItemsByDirection(); @@ -730,7 +729,7 @@ namespace Xamarin.Forms.Platform.Android { if (_actionView != null) { - RemoveView(_actionView); + _actionView.RemoveFromParent(); _actionView.Dispose(); _actionView = null; } @@ -1019,13 +1018,13 @@ namespace Xamarin.Forms.Platform.Android if (swipeThreshold > contentWidth) swipeThreshold = contentWidth; - return swipeThreshold - SwipeThresholdMargin; + return swipeThreshold; } if (swipeThreshold > contentHeight) swipeThreshold = contentHeight; - return swipeThreshold - SwipeThresholdMargin / 2; + return swipeThreshold; } Size GetSwipeItemSize(ISwipeItem swipeItem) diff --git a/Xamarin.Forms.Platform.iOS/Renderers/SwipeViewRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/SwipeViewRenderer.cs index afc1c9241..f69aac771 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/SwipeViewRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/SwipeViewRenderer.cs @@ -14,7 +14,6 @@ namespace Xamarin.Forms.Platform.iOS public class SwipeViewRenderer : ViewRenderer { const double SwipeThreshold = 250; - const int SwipeThresholdMargin = 0; const double SwipeItemWidth = 100; const double SwipeAnimationDuration = 0.2; const double SwipeMinimumDelta = 10; @@ -148,7 +147,7 @@ namespace Xamarin.Forms.Platform.iOS { BackgroundColor = Element.BackgroundColor.ToUIColor(); - if (_contentView != null && Element.Content == null) + if (_contentView != null && (Element.Content == null || (Element.Content != null && Element.Content.BackgroundColor == Color.Default))) _contentView.BackgroundColor = Element.BackgroundColor.ToUIColor(); } else @@ -916,13 +915,13 @@ namespace Xamarin.Forms.Platform.iOS if (swipeThreshold > _contentView.Frame.Width) swipeThreshold = _contentView.Frame.Width; - return swipeThreshold - SwipeThresholdMargin; + return swipeThreshold; } if (swipeThreshold > _contentView.Frame.Height) swipeThreshold = _contentView.Frame.Height; - return swipeThreshold - SwipeThresholdMargin / 2; + return swipeThreshold; } Size GetSwipeItemSize(ISwipeItem swipeItem)