From 1b495da2c50ae495c7b1017e1c1e5b89c7db4e52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez?= Date: Tue, 22 Sep 2020 11:47:56 +0200 Subject: [PATCH] [Android] SwipeView removes Frame borders (#11947) fixes #11831 * Added repro sample * Fixed issue with default SwipeView BackgroundColor on iOS * Updated the sample * Avoid to set the Content BackgroundColor updating the SwipeView BackgroundColor * Fixed build error * Fixed build error * Fix build error Co-authored-by: Rui Marinho --- .../Issue11831.xaml | 105 ++++++++++++++++++ .../Issue11831.xaml.cs | 53 +++++++++ ...rin.Forms.Controls.Issues.Shared.projitems | 4 + .../Renderers/SwipeViewRenderer.cs | 26 +---- .../Renderers/SwipeViewRenderer.cs | 23 +--- 5 files changed, 171 insertions(+), 40 deletions(-) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue11831.xaml create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue11831.xaml.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue11831.xaml b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue11831.xaml new file mode 100644 index 000000000..b04f2d627 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue11831.xaml @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue11831.xaml.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue11831.xaml.cs new file mode 100644 index 000000000..e2ec05184 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue11831.xaml.cs @@ -0,0 +1,53 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; +using Xamarin.Forms.Xaml; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Windows.Input; +using System; + +#if UITEST +using Xamarin.UITest; +using Xamarin.UITest.Queries; +using NUnit.Framework; +using Xamarin.Forms.Core.UITests; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ +#if UITEST + [NUnit.Framework.Category(UITestCategories.SwipeView)] +#endif +#if APP + [XamlCompilation(XamlCompilationOptions.Compile)] +#endif + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Github, 11831, "[Bug] SwipeView removes Frame borders on Android", PlatformAffected.Android)] + public partial class Issue11831 : TestContentPage + { + public Issue11831() + { +#if APP + Title = "Issue 11831"; + InitializeComponent(); + + var random = new Random(); + for (var i = 0; i < 16; i++) + Data.Add($"Entry #{i + 1} - {random.Next(0, 999999)}"); + + DeleteCommand = new Command(input => DisplayAlert("Delete entry", $"Delete: {input}", "OK")); + + BindingContext = this; +#endif + } + + public ObservableCollection Data { get; } = new ObservableCollection(); + + public ICommand DeleteCommand { get; } + + 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 bc1fde72e..434e3f593 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 @@ -1587,6 +1587,7 @@ + Issue11496.xaml @@ -1900,6 +1901,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 837d5a7a9..7b178c661 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/SwipeViewRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/SwipeViewRenderer.cs @@ -76,8 +76,6 @@ namespace Xamarin.Forms.Platform.Android UpdateContent(); UpdateIsSwipeEnabled(); UpdateSwipeTransitionMode(); - UpdateBackgroundColor(); - UpdateBackground(); } if (e.OldElement != null) @@ -100,10 +98,6 @@ namespace Xamarin.Forms.Platform.Android if (e.PropertyName == ContentView.ContentProperty.PropertyName) UpdateContent(); - else if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName) - UpdateBackgroundColor(); - else if (e.PropertyName == VisualElement.BackgroundProperty.PropertyName) - UpdateBackground(); else if (e.PropertyName == VisualElement.IsEnabledProperty.PropertyName) UpdateIsSwipeEnabled(); else if (e.PropertyName == Specifics.SwipeTransitionModeProperty.PropertyName) @@ -137,29 +131,19 @@ namespace Xamarin.Forms.Platform.Android protected override void UpdateBackgroundColor() { if (Element.BackgroundColor != Color.Default) - { - var backgroundColor = Element.BackgroundColor.ToAndroid(); - - SetBackgroundColor(backgroundColor); - - if (Element.Content == null || (Element.Content != null && Element.Content.BackgroundColor == Color.Default)) - _contentView?.SetBackgroundColor(backgroundColor); - } + SetBackgroundColor(Element.BackgroundColor.ToAndroid()); else - Control.SetWindowBackground(); - - if (_contentView != null && _contentView.Background == null) - _contentView?.SetWindowBackground(); + Control?.SetWindowBackground(); } protected override void UpdateBackground() { Brush background = Element.Background; - this.UpdateBackground(background); + if (Brush.IsNullOrEmpty(background)) + return; - if (Element.Content == null) - _contentView?.UpdateBackground(background); + this.UpdateBackground(background); } protected override void OnAttachedToWindow() diff --git a/Xamarin.Forms.Platform.iOS/Renderers/SwipeViewRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/SwipeViewRenderer.cs index 3210d47fb..865bdb119 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/SwipeViewRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/SwipeViewRenderer.cs @@ -87,7 +87,6 @@ namespace Xamarin.Forms.Platform.iOS UpdateContent(); UpdateIsSwipeEnabled(); UpdateSwipeTransitionMode(); - SetBackgroundColor(Element.BackgroundColor); } if (e.OldElement != null) @@ -152,10 +151,6 @@ namespace Xamarin.Forms.Platform.iOS if (e.PropertyName == ContentView.ContentProperty.PropertyName) UpdateContent(); - else if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName) - SetBackgroundColor(Element.BackgroundColor); - else if (e.PropertyName == VisualElement.BackgroundProperty.PropertyName) - SetBackground(Element.Background); else if (e.PropertyName == VisualElement.IsEnabledProperty.PropertyName) UpdateIsSwipeEnabled(); else if (e.PropertyName == Specifics.SwipeTransitionModeProperty.PropertyName) @@ -164,31 +159,21 @@ namespace Xamarin.Forms.Platform.iOS protected override void SetBackgroundColor(Color color) { - UIColor backgroundColor = ColorExtensions.BackgroundColor; - if (Element.BackgroundColor != Color.Default) - { BackgroundColor = Element.BackgroundColor.ToUIColor(); - - if (_contentView != null && (Element.Content == null || (Element.Content != null && Element.Content.BackgroundColor == Color.Default))) - _contentView.BackgroundColor = Element.BackgroundColor.ToUIColor(); - } else - BackgroundColor = backgroundColor; - - if (_contentView != null && _contentView.BackgroundColor == UIColor.Clear) - _contentView.BackgroundColor = backgroundColor; + BackgroundColor = ColorExtensions.BackgroundColor; } protected override void SetBackground(Brush brush) { Brush background = Element.Background; + if (Brush.IsNullOrEmpty(background)) + return; + if (Control != null) Control.UpdateBackground(background); - - if (_contentView != null && Element.Content == null && HasSwipeItems()) - _contentView.UpdateBackground(background); } public override void TouchesEnded(NSSet touches, UIEvent evt)