Skip to content

Commit

Permalink
Merge pull request #12211 from ajpinedam/ajpm/fix.android.scroll.offset
Browse files Browse the repository at this point in the history
fix(ScrollView): Android FastScrolling wrong Offsets
  • Loading branch information
jeromelaban authored May 11, 2023
2 parents 5bdd6e9 + 45d73a6 commit 65f2ccb
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,68 @@ public async Task When_NonRound_Content_Height()
Assert.AreEqual(outerScrollViewer.ExtentHeight, outerScrollViewer.ViewportHeight, 0.000001);
}

[TestMethod]
[RunsOnUIThread]
[RequiresFullWindow]
#if __MACOS__
[Ignore("Currently fails on macOS, part of #9282! epic")]
#endif
public async Task When_ChangeView_Offset()
{
const double offset = 100;

var scroll = new ScrollViewer()
{
Background = new SolidColorBrush(Colors.Yellow)
};

var stackPanel = new StackPanel()
{
Orientation = Orientation.Vertical,
Height = 5000,
};

stackPanel.Children.Add(new Border() { Height = 200 });

var target = new Border()
{
Background = new SolidColorBrush(Colors.Lime),
Height = 50,
};

stackPanel.Children.Add(target);

var scrollChanged = false;
scroll.ViewChanged += (s, e) =>
{
scrollChanged = true;
};

scroll.Content = stackPanel;

try
{

var container = new Border() { Child = scroll };

WindowHelper.WindowContent = container;

await WindowHelper.WaitForLoaded(scroll);

_ = scroll.ChangeView(null, offset, null, true);

await WindowHelper.WaitFor(() => scrollChanged);

var loc = target.TransformToVisual(scroll).TransformPoint(new Point(0, 0));
Assert.AreEqual(offset, loc.Y);
}
finally
{
WindowHelper.WindowContent = null;
}
}


#if __ANDROID__
[TestMethod]
[RunsOnUIThread]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ public double ExtentWidth
#region Native SCP to SCP
internal void OnNativeScroll(double horizontalOffset, double verticalOffset, bool isIntermediate)
{
ScrollOffsets = new Point(horizontalOffset, verticalOffset);

Scroller?.OnPresenterScrolled(horizontalOffset, verticalOffset, isIntermediate);

ScrollOffsets = new Point(horizontalOffset, verticalOffset);
InvalidateViewport();
}

Expand Down

0 comments on commit 65f2ccb

Please sign in to comment.