From 77c7066c89ae0d039a34faefbd9fef2b5bdb9468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Kulik=C3=B3w?= Date: Tue, 29 Oct 2019 13:19:49 +0100 Subject: [PATCH] [macOS] Visual glitch when exiting the full screen with ScrollViewer (#8086) fixes #4854 * added test for issue4854 * fix issue4854 --- .../Issue4854.cs | 42 +++++++++++++++++++ ...rin.Forms.Controls.Issues.Shared.projitems | 1 + .../Renderers/ScrollViewRenderer.cs | 16 ++++--- 3 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4854.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4854.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4854.cs new file mode 100644 index 000000000..2a939715a --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4854.cs @@ -0,0 +1,42 @@ +using System; +using System.Linq.Expressions; +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +#if UITEST +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Github, 4854, "[macOS] Visual glitch when exiting the full screen with ScrollViewer", PlatformAffected.macOS)] + public class Issue4854 : TestContentPage + { + + protected override void Init() + { + var gMain = new Grid { BackgroundColor = Color.LightBlue }; + gMain.RowDefinitions.Add(new RowDefinition { Height = GridLength.Star }); + gMain.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + + var label = new Label + { + Text = "Enter full screen and exit and see the artifacts on the screen.", + FontSize = 14 + }; + var sl = new StackLayout { HorizontalOptions = LayoutOptions.Center, WidthRequest = 300, Padding = new Thickness(15) }; + sl.Children.Add(label); + gMain.Children.Add(sl); + + var button = new Button { Text = "Test", BackgroundColor = Color.Gray, HorizontalOptions = LayoutOptions.Center }; + var g = new Grid { BackgroundColor = Color.LightGray, Padding = new Thickness(20) }; + g.Children.Add(button); + Grid.SetRow(g, 1); + gMain.Children.Add(g); + + Content = new ScrollView { Content = gMain, BackgroundColor = Color.LightGreen }; + } + + } +} 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 05a80a1f3..83ef72305 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 @@ -1094,6 +1094,7 @@ Issue4356.xaml + diff --git a/Xamarin.Forms.Platform.MacOS/Renderers/ScrollViewRenderer.cs b/Xamarin.Forms.Platform.MacOS/Renderers/ScrollViewRenderer.cs index ad4ed3707..54cba78c6 100644 --- a/Xamarin.Forms.Platform.MacOS/Renderers/ScrollViewRenderer.cs +++ b/Xamarin.Forms.Platform.MacOS/Renderers/ScrollViewRenderer.cs @@ -255,7 +255,7 @@ namespace Xamarin.Forms.Platform.MacOS if (ContentView == null || ScrollView == null || ScrollView.Content == null) return false; - if (Math.Abs(ScrollView.ScrollY) < 0.001 && Math.Abs(ScrollView.ScrollX) < 0.001 && ScrollView.Content.Height > ScrollView.Height) + if (Math.Abs(ScrollView.ScrollY) < 0.001 && Math.Abs(ScrollView.ScrollX) < 0.001 && ScrollView.Content.Height >= ScrollView.Height) { ContentView.ScrollToPoint(new CoreGraphics.CGPoint(0, 0)); return true; @@ -270,12 +270,16 @@ namespace Xamarin.Forms.Platform.MacOS if (ScrollView == null) return; - if (ScrollView.ContentSize.Height >= ScrollView.Height) + var height = ScrollView.Height; + var contentHeightOverflow = ScrollView.ContentSize.Height - height; + if (contentHeightOverflow >= 0) { - CoreGraphics.CGPoint location = ContentView.DocumentVisibleRect().Location; - - if (location.Y > -1 && ScrollView.Height >= 0) - ScrollView.SetScrolledPosition(Math.Max(0, location.X), Math.Max(0, ScrollView.ContentSize.Height - ScrollView.Height - location.Y)); + if (height >= 0) + { + var location = ContentView.DocumentVisibleRect().Location; + if (location.Y > -1) + ScrollView.SetScrolledPosition(Math.Max(0, location.X), Math.Max(0, contentHeightOverflow - location.Y)); + } } else ResetNativeNonScroll();