Skip to content

Commit

Permalink
[Android] Fix flyout behaviour switching exception (#22453)
Browse files Browse the repository at this point in the history
* Fix flyout behaviour switching exception

* Tests added

* Flyout test page added

* Flyoutpage test fixes

* Flyout toggle test added

* Remove duplicate ] characters

* Flyout test pages added

* Check for platforms

* Fix title

* - fix tests

---------

Co-authored-by: Gerald Versluis <[email protected]>
Co-authored-by: Shane Neuville <[email protected]>
  • Loading branch information
3 people authored Jun 25, 2024
1 parent 4edbcbd commit 1750736
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 2 deletions.
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>
38 changes: 38 additions & 0 deletions src/Controls/tests/TestCases/Issues/Issue18161.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Threading.Tasks;
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.Loaded += Issue18161_Loaded;
}

async void Issue18161_Loaded(object sender, EventArgs e)
{
// https://github.com/dotnet/maui/issues/13496
await Task.Yield();
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;
}
}
5 changes: 3 additions & 2 deletions src/Core/src/Handlers/FlyoutView/FlyoutViewHandler.Android.cs
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

0 comments on commit 1750736

Please sign in to comment.