Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[macOS] Visual glitch when exiting the full screen with ScrollViewer #8086

Merged
merged 2 commits into from Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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 @@ -1079,6 +1079,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