Skip to content

Commit

Permalink
App Crash during Scroll Animation while navigating away from Page - f…
Browse files Browse the repository at this point in the history
…ix (#22492)

* Fix #22443 & UITest

* Update ScrollViewHandler.Android.cs & move tests

* Fixed the UI test
  • Loading branch information
kubaflo authored May 21, 2024
1 parent c507cd2 commit 7ad1b69
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue22443 : _IssuesUITest
{
public Issue22443(TestDevice device)
: base(device)
{ }

public override string Issue => "App Crash on Scroll Animation while navigating away from Page";

[Test]
public void NoExceptionShouldBeThrown()
{
App.WaitForElement("button");
App.Click("button");
App.WaitForElement("button");

//The test passes if no exception is thrown
}
}
7 changes: 7 additions & 0 deletions src/Controls/tests/TestCases/Issues/Issue22443.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue22443"
Title="Issue22443">
<Button Text="Navigate to next page" AutomationId="button" Clicked="Button_Clicked"/>
</ContentPage>
81 changes: 81 additions & 0 deletions src/Controls/tests/TestCases/Issues/Issue22443.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using Microsoft.Maui.ApplicationModel;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;
using Microsoft.Maui.Graphics;
using System;
using System.Threading.Tasks;

namespace Maui.Controls.Sample.Issues;

[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 22443, "App Crash on Scroll Animation while navigating away from Page", PlatformAffected.Android)]
public partial class Issue22443NavPage : NavigationPage
{
public Issue22443NavPage() : base(new Issue22443())
{

}
}

public partial class Issue22443 : ContentPage
{
public Issue22443()
{
InitializeComponent();
}

void Button_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new Issue22443ScrollPage());
}
}

public class Issue22443ScrollPage : ContentPage
{
private ScrollView _scrollView;

public Issue22443ScrollPage()
{
_scrollView = new ScrollView
{
Content = new VerticalStackLayout
{
Children =
{
new BoxView
{
HeightRequest = 10000,
Background = new LinearGradientBrush(
new GradientStopCollection
{
new GradientStop(Colors.White, .1f),
new GradientStop(Colors.Black, .9f)
})
},
new Label
{
FontSize = 40,
Text = "End of Second Page",
HorizontalOptions = LayoutOptions.Center,
},
}
}
};

Content = _scrollView;
}

protected override async void OnAppearing()
{
MainThread.BeginInvokeOnMainThread(() =>_scrollView!.ScrollToAsync(0, 10000, true));

await Task.Delay(200);
await Navigation.PopAsync();
}

protected override void OnDisappearing()
{
base.OnDisappearing();
_scrollView?.Handler?.DisconnectHandler();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,13 @@ public static void MapRequestScrollTo(IScrollViewHandler handler, IScrollView sc
var verticalOffsetDevice = (int)context.ToPixels(request.VerticalOffset);

handler.PlatformView.ScrollTo(horizontalOffsetDevice, verticalOffsetDevice,
request.Instant, () => handler.VirtualView.ScrollFinished());
request.Instant, () =>
{
if (handler.IsConnected())
{
handler.VirtualView.ScrollFinished();
}
});
}

/*
Expand Down

0 comments on commit 7ad1b69

Please sign in to comment.