Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Fix flyout behaviour switching exception #22453

Merged
merged 11 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

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

public override string Issue => "Toggling FlyoutLayoutBehavior on Android causes the app to crash";

[Test]
[Category(UITestCategories.FlyoutPage)]
public void NoExceptionShouldBeThrown()
{
App.WaitForElement("ToggleBehaviour");
App.Tap("ToggleBehaviour");
App.Tap("ToggleBehaviour");

//The test passes if no exception is thrown
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#if ANDROID || IOS
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

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

public override string Issue => "FlyoutPage Android app crashing on orientation change when flyout is open";

[Test]
[Category(UITestCategories.FlyoutPage)]
public void NoExceptionShouldBeThrown()
{
App.SetOrientationPortrait();
App.WaitForElement("OpenFlyout");
App.Tap("OpenFlyout");
App.SetOrientationLandscape();

//The test passes if no exception is thrown
}
}
#endif
24 changes: 24 additions & 0 deletions src/Controls/tests/TestCases/Issues/Issue18161.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?>
<FlyoutPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue18161">
<FlyoutPage.Flyout>
<ContentPage Title="The FlyOut">
<StackLayout>
<Label Text="This is the flyout" />
<Button Text="Change Flyout behaviour" AutomationId="ToggleBehaviour" Clicked="ToggleBehaviour_Clicked" />
</StackLayout>
</ContentPage>
</FlyoutPage.Flyout>
<FlyoutPage.Detail>
<NavigationPage>
<x:Arguments>
<ContentPage Title="The Detail">
<StackLayout>
<Label Text="The detail page." />
</StackLayout>
</ContentPage>
</x:Arguments>
</NavigationPage>
</FlyoutPage.Detail>
</FlyoutPage>
30 changes: 30 additions & 0 deletions src/Controls/tests/TestCases/Issues/Issue18161.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;
using Microsoft.Maui.Devices;

namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 18161, "Toggling FlyoutLayoutBehavior on Android causes the app to crash", PlatformAffected.Android)]
public partial class Issue18161 : FlyoutPage, IFlyoutPageController, IFlyoutView
{
public Issue18161()
{
InitializeComponent();
this.IsPresented = true;
}

public void ToggleBehaviour_Clicked(object sender, EventArgs e)
{
FlyoutLayoutBehavior = FlyoutLayoutBehavior == FlyoutLayoutBehavior.Split
? FlyoutLayoutBehavior.Popover
: FlyoutLayoutBehavior.Split;
}

bool IFlyoutPageController.ShouldShowSplitMode => FlyoutLayoutBehavior == FlyoutLayoutBehavior.Split;

double IFlyoutView.FlyoutWidth => 100;
}
}
22 changes: 22 additions & 0 deletions src/Controls/tests/TestCases/Issues/Issue20858.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<FlyoutPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue20858">
<FlyoutPage.Flyout>
<ContentPage Title="The FlyOut">
<Label Text="This is the flyout" />
</ContentPage>
</FlyoutPage.Flyout>
<FlyoutPage.Detail>
<NavigationPage>
<x:Arguments>
<ContentPage Title="The Detail">
<StackLayout>
<Label Text="Please rotate the device to portrait mode to test. Open the flyout and then rotate device to landscape." />
<Button Text="Open the Flyout to begin testing" AutomationId="OpenFlyout" Clicked="OpenFlyout_Clicked" />
</StackLayout>
</ContentPage>
</x:Arguments>
</NavigationPage>
</FlyoutPage.Detail>
</FlyoutPage>
24 changes: 24 additions & 0 deletions src/Controls/tests/TestCases/Issues/Issue20858.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;
using Microsoft.Maui.Devices;

namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 20858, "FlyoutPage Android app crashing on orientation change when flyout is open", PlatformAffected.Android)]
public partial class Issue20858 : FlyoutPage, IFlyoutPageController
{
public Issue20858()
{
InitializeComponent();
}

public void OpenFlyout_Clicked(object sender, EventArgs e)
{
IsPresented = true;
}

bool IFlyoutPageController.ShouldShowSplitMode => FlyoutLayoutBehavior == FlyoutLayoutBehavior.Split;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ void UpdateFlyoutBehavior()
var behavior = VirtualView.FlyoutBehavior;
if (_detailViewFragment?.DetailView?.Handler?.PlatformView == null)
return;

// Important to create the layout views before setting the lock mode
LayoutViews();

switch (behavior)
{
Expand All @@ -289,8 +292,6 @@ void UpdateFlyoutBehavior()
DrawerLayout.SetDrawerLockMode(VirtualView.IsGestureEnabled ? DrawerLayout.LockModeUnlocked : DrawerLayout.LockModeLockedClosed);
break;
}

LayoutViews();
}

protected override void ConnectHandler(View platformView)
Expand Down
Loading