Skip to content

Commit

Permalink
[Android] FlyoutIsPresented property opens the Flyout (dotnet#19807)
Browse files Browse the repository at this point in the history
* Fix the issue

* Added device test

* Added sample

* Added comment

* - fix tests

---------

Co-authored-by: Shane Neuville <shneuvil@microsoft.com>
  • Loading branch information
jsuarezruiz and PureWeen authored Jan 16, 2024
1 parent a36ceae commit abe0025
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ protected override void OnAppearing()
AppShell!.FlyoutHeaderBehavior = (FlyoutHeaderBehavior)flyoutHeaderBehavior.SelectedIndex;
}

void OnToggleFlyoutIsPresented(object sender, EventArgs e)
{
AppShell!.FlyoutIsPresented = !AppShell!.FlyoutIsPresented;
}

void OnToggleFlyoutBackgroundColor(object sender, EventArgs e)
{
AppShell!.RemoveBinding(Shell.FlyoutBackgroundProperty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
Text="Flyout Behavior"
Style="{StaticResource Headline}"/>
<Picker x:Name="flyoutBehavior" />
<Label
Text="FlyoutIsPresented"
Style="{StaticResource Headline}"/>
<Button Text="Toggle FlyoutIsPresented" x:Name="flyoutIsPresented" Clicked="OnToggleFlyoutIsPresented" />
<Label
Text="Flyout Background Color"
Style="{StaticResource Headline}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,10 @@ protected override bool DrawChild(Canvas canvas, AView child, long drawingTime)
canvas.DrawRect(0, 0, Width, Height, _scrimPaint);
}

if (!FlyoutFirstDrawPassFinished && _flyoutContent != null)
if (!FlyoutFirstDrawPassFinished && _flyoutContent is not null)
{
if (child == _flyoutContent?.AndroidView)
// If the AndroidView property which is the DrawerLayout is initialized at this point, the Flyout first draw pass finished.
if (_flyoutContent?.AndroidView is not null)
FlyoutFirstDrawPassFinished = true;

if (this.IsDrawerOpen(_flyoutContent.AndroidView) != _shellContext.Shell.FlyoutIsPresented)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using AndroidX.DrawerLayout.Widget;
using Microsoft.Maui.Controls;
using System.Threading.Tasks;
using Xunit;

namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Shell)]
public partial class ShellTests
{
[Fact(DisplayName = "FlyoutIsPresented=true sets the visible status of the Shell Flyout.")]
public async Task FlyoutIsPresentedOpenDrawer()
{
await RunShellTest(shell =>
{
shell.FlyoutContent = new VerticalStackLayout() { new Label() { Text = "Flyout Content" } };
},
async (shell, handler) =>
{
// 1. Set FlyoutIsPresented=true to make the Shell Flyout visible.
shell.FlyoutIsPresented = true;

var dl = GetDrawerLayout(handler) as DrawerLayout;
Assert.NotNull(dl);

await AssertionExtensions.AssertEventually(() =>
{
// 2. Check that the Flyout has size.
var flyoutFrame = GetFlyoutFrame(handler);
return flyoutFrame.Width > 0 && flyoutFrame.Height > 0 && dl.IsOpen;
});
});
}
}
}

0 comments on commit abe0025

Please sign in to comment.