Skip to content

Commit

Permalink
[net9.0][Enhancement] FontImageSource defaults and style (#23602)
Browse files Browse the repository at this point in the history
* FontImageSource defaults and style

* Added tests

* Added snapshots
  • Loading branch information
kubaflo authored Sep 6, 2024
1 parent c595a6b commit 65afec2
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Controls/src/Core/ImageSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ public abstract partial class ImageSource : Element

readonly WeakEventManager _weakEventManager = new WeakEventManager();

internal readonly MergedStyle _mergedStyle;

protected ImageSource()
{
_mergedStyle = new MergedStyle(GetType(), this);
}

/// <include file="../../docs/Microsoft.Maui.Controls/ImageSource.xml" path="//Member[@MemberName='IsEmpty']/Docs/*" />
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue13474.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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.Issue13474">
<ContentPage.Resources>
<Style TargetType="FontImageSource">
<Setter Property="FontFamily" Value="FontAwesome"/>
<Setter Property="Color" Value="Red"/>
</Style>
</ContentPage.Resources>

<VerticalStackLayout>
<ImageButton
HeightRequest="100"
WidthRequest="100"
BackgroundColor="Green"
AutomationId="imageButton"
Source="{FontImageSource Glyph=''}"/>
</VerticalStackLayout>
</ContentPage>
11 changes: 11 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue13474.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Maui.Controls.Sample.Issues;

[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 13474, "FontImageSource defaults and style", PlatformAffected.All)]
public partial class Issue13474 : ContentPage
{
public Issue13474()
{
InitializeComponent();
}
}
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.TestCases.Tests.Issues
{
public class Issue13474 : _IssuesUITest
{
public Issue13474(TestDevice device) : base(device) { }

public override string Issue => "FontImageSource defaults and style";

[Test]
[Category(UITestCategories.ImageButton)]
public void Issue13474Test()
{
App.WaitForElement("imageButton");

// The test passes if font family and color is applied
VerifyScreenshot();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src/Controls/tests/Xaml.UnitTests/Issues/Maui13474.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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="Microsoft.Maui.Controls.Xaml.UnitTests.Maui13474">
<ContentPage.Resources>
<Style TargetType="FontImageSource">
<Setter Property="FontFamily" Value="FontAwesome"/>
<Setter Property="Color" Value="Red"/>
</Style>
</ContentPage.Resources>

<VerticalStackLayout>
<ImageButton
x:Name="imageButton"
HeightRequest="100"
WidthRequest="100"
BackgroundColor="Green"
AutomationId="imageButton"
Source="{FontImageSource Glyph=''}"/>
</VerticalStackLayout>
</ContentPage>
52 changes: 52 additions & 0 deletions src/Controls/tests/Xaml.UnitTests/Issues/Maui13474.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Maui.ApplicationModel;
using Microsoft.Maui.Controls.Core.UnitTests;
using Microsoft.Maui.Controls.Shapes;
using Microsoft.Maui.Devices;
using Microsoft.Maui.Dispatching;

using Microsoft.Maui.Graphics;
using Microsoft.Maui.UnitTests;
using NUnit.Framework;

namespace Microsoft.Maui.Controls.Xaml.UnitTests;

public partial class Maui13474
{
public Maui13474()
{
InitializeComponent();
}

public Maui13474(bool useCompiledXaml)
{
//this stub will be replaced at compile time
}

[TestFixture]
class Test
{
[SetUp]
public void Setup()
{
Application.SetCurrentApplication(new MockApplication());
DispatcherProvider.SetCurrent(new DispatcherProviderStub());
}

[TearDown] public void TearDown() => AppInfo.SetCurrent(null);

[Test]
public void FontImageSourceIsAppliedFromSharedResources([Values(false, true)] bool useCompiledXaml)
{
var page = new Maui13474(useCompiledXaml);
var fontImageSource = page.imageButton.Source as FontImageSource;
Assert.AreEqual(fontImageSource.Color, Colors.Red);
Assert.AreEqual(fontImageSource.FontFamily, "FontAwesome");
}
}
}

0 comments on commit 65afec2

Please sign in to comment.