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] InputTransparent="true" on a Layout breaks child controls - Fix #22345

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?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.Issue22289"
Title="Issue22289">
<Grid RowDefinitions="*,*,*">
<Grid InputTransparent="True" BackgroundColor="Red">
<Label Text="Grid with InputTransparent"/>
<Button AutomationId="button1" x:Name="Button1" VerticalOptions="Center" Text="Click me" IsVisible="False"/>
</Grid>
<Grid Grid.Row="1" BackgroundColor="Green">
<Label Text="Grid without InputTransparent"/>
<Button AutomationId="button2" x:Name="Button2" VerticalOptions="Center" Text="Click me" IsVisible="False"/>
</Grid>
<Button AutomationId="changeVisibilityButton" Grid.Row="2" Clicked="Button_Clicked" Text="Click" />
</Grid>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;

namespace Maui.Controls.Sample.Issues;

[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 22289, "InputTransparent=\"true\" on a Layout breaks child controls on Android", PlatformAffected.Android)]

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

void Button_Clicked(object sender, System.EventArgs e)
{
Button1.IsVisible = !Button1.IsVisible;
Button2.IsVisible = !Button2.IsVisible;
}
}
24 changes: 24 additions & 0 deletions src/Controls/tests/UITests/Tests/Issues/Issue22289.cs
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.AppiumTests.Issues
{
public class Issue22289 : _IssuesUITest
{
public override string Issue => "InputTransparent=\"true\" on a Layout breaks child controls on Android";
public Issue22289(TestDevice device) : base(device)
{
}

[Test]
public void ButtonsShouldBeVisible()
{
App.WaitForElement("changeVisibilityButton");
App.Click("changeVisibilityButton");

App.WaitForElement("button1");
App.WaitForElement("button2");
}
}
}
1 change: 0 additions & 1 deletion src/Core/src/Handlers/Label/LabelHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public static void MapBackground(ILabelHandler handler, ILabel label)

public static void MapOpacity(ILabelHandler handler, ILabel label)
{
handler.UpdateValue(nameof(IViewHandler.ContainerView));
handler.PlatformView.UpdateOpacity(label);
handler.ToPlatform().UpdateOpacity(label);
}
Expand Down
6 changes: 6 additions & 0 deletions src/Core/src/Handlers/View/ViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,12 @@ public static void MapContainerView(IViewHandler handler, IView view)
handler.HasContainer = viewHandler.NeedsContainer;
else
handler.HasContainer = view.NeedsContainer();

handler.UpdateValue(nameof(IView.Visibility));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need to add

handler.UpdateValue(nameof(IView.Opacity))

and remove this line from LabelHandler.windows.cs

    public static void MapOpacity(ILabelHandler handler, ILabel label)
    {
        handler.UpdateValue(nameof(IViewHandler.ContainerView)); // this line
        handler.PlatformView.UpdateOpacity(label);
        handler.ToPlatform().UpdateOpacity(label);
    }

I think when "handler.UpdateValue(nameof(IViewHandler.ContainerView));" was originally added we didn't have the correct MapContainerview flow, so it made sense there

You only need to update the ContainerView if that property would result in the container getting added/removed


#if WINDOWS
handler.UpdateValue(nameof(IView.Opacity));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know if it is just windows only? Somehow I feel opacity is such a basic feature it affects more and we just saw it with windows first.

If we don't want to move the cheese to much in the PR, maybe just make this comment an issue and I can have a look when I get back to my keyboard.

#endif
}

/// <summary>
Expand Down