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] Fixed box view properties #21322

Merged
merged 6 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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,36 @@
<?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.Issue19926"
Title="Issue19926">

<ContentPage.Resources>
<Style TargetType="BoxView">
<Setter Property="WidthRequest" Value="100"/>
<Setter Property="HeightRequest" Value="100"/>
<Setter Property="Background">
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0.4" Color="Red" />
<GradientStop Offset="1" Color="Blue" />
</LinearGradientBrush>
</Setter>
</Style>
</ContentPage.Resources>

<StackLayout Spacing="20">
<StackLayout>
<Label HorizontalTextAlignment="Center" Text="Translation X"/>
<BoxView TranslationX="30" AutomationId="boxView"/>
</StackLayout>

<StackLayout>
<Label HorizontalTextAlignment="Center" Text="Opacity"/>
<BoxView Opacity="0.2"/>
</StackLayout>

<StackLayout>
<Label HorizontalTextAlignment="Center" Text="Scale X"/>
<BoxView ScaleX="1.5"/>
</StackLayout>
</StackLayout>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;

namespace Maui.Controls.Sample.Issues;

[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 19926, "[Android] Opacity bug on BoxView.Background", PlatformAffected.Android)]

public partial class Issue19926 : ContentPage
{
public Issue19926()
{
InitializeComponent();
}
}
3 changes: 2 additions & 1 deletion src/Controls/src/Core/BoxView/BoxView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ protected override void OnPropertyChanged([CallerMemberName] string? propertyNam

if (propertyName == BackgroundColorProperty.PropertyName ||
propertyName == ColorProperty.PropertyName ||
propertyName == BackgroundProperty.PropertyName ||
propertyName == CornerRadiusProperty.PropertyName)
Handler?.UpdateValue(nameof(IShapeView.Shape));
}
Expand All @@ -64,7 +65,7 @@ protected override void OnPropertyChanged([CallerMemberName] string? propertyNam

PathAspect IShapeView.Aspect => PathAspect.None;

Paint? IShapeView.Fill => Color?.AsPaint() ?? ((IView)this).Background;
Paint? IShapeView.Fill => Color?.AsPaint();
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand how this fixes it ,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rmarinho I've noticed that the box view is rendered twice. It is easy to observe when setting the translationY property to 200. This is the outcome:
Screenshot_2024-03-23_at_06 41 39

With this ((IView)this).Background part removed from the code the shapeViewHandler doesn't update the background and therefore does not draw that top right boxView

if (shapeView.Background is not null && shapeView.Fill is not null)


Paint? IStroke.Stroke => null;

Expand Down
23 changes: 23 additions & 0 deletions src/Controls/tests/UITests/Tests/Issues/Issue19926.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.AppiumTests.Issues;

public class Issue19926 : _IssuesUITest
{
public override string Issue => "[Android] Opacity bug on BoxView.Background";

public Issue19926(TestDevice device)
: base(device)
{ }

[Test]
public void PropertiesShouldBeCorrectlyApplied()
{
this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.iOS, TestDevice.Mac, TestDevice.Windows });
_ = App.WaitForElement("boxView");

VerifyScreenshot();
Copy link
Contributor

Choose a reason for hiding this comment

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

Added pending snapshot.

}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading