Skip to content

Commit

Permalink
[macOS] Visual glitch when exiting the full screen with ScrollViewer (x…
Browse files Browse the repository at this point in the history
…amarin#8086) fixes xamarin#4854

* added test for issue4854

* fix issue4854
  • Loading branch information
slakul authored and felipebaltazar committed Dec 1, 2019
1 parent 530857d commit 848daa6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
@@ -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 };
}

}
}
Expand Up @@ -1123,6 +1123,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue4356.cs">
<DependentUpon>Issue4356.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue4854.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue5951.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Github6021.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue5132.cs" />
Expand Down
16 changes: 10 additions & 6 deletions Xamarin.Forms.Platform.MacOS/Renderers/ScrollViewRenderer.cs
Expand Up @@ -255,7 +255,7 @@ private bool ResetNativeNonScroll( )
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;
Expand All @@ -270,12 +270,16 @@ void UpdateScrollPosition()
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();
Expand Down

0 comments on commit 848daa6

Please sign in to comment.