This repository has been archived by the owner on May 1, 2024. It is now read-only.
Adds FontImage Markup Extension for FontImageSource #6398
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2374916
Added FontImage markup extension which simplifies usage of FontImageS…
SkyeHoefling afb77fd
Added unit tests to cover TabBar which is used in Shell
SkyeHoefling c7618cd
Cleaned up xaml for test code
SkyeHoefling 01a9595
Removed class references from unit test project which were added by m…
SkyeHoefling 6c7a2aa
Removed FontImageExtension from markup parser
SkyeHoefling d81e477
Added ContentProperty to markup extension
SkyeHoefling ba40962
Added Size to FontImageExtension
SkyeHoefling 0525f1f
Updated unit tests for new properties
SkyeHoefling 14fef76
added unit tests to certify each property was set correctly by the ma…
SkyeHoefling 6a86a88
Added content property test to certify that Glyph is being set correctly
SkyeHoefling 31e4873
Flipped order in unit tests of expected and actual
SkyeHoefling 4be9b50
Updated default value for Size to use the FontImageSource default's v…
SkyeHoefling File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<TabBar | ||
xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:local="using:Xamarin.Forms.Xaml.UnitTests" | ||
x:Class="Xamarin.Forms.Xaml.UnitTests.FontImageExtension"> | ||
|
||
<Tab Title="Hello" Icon="{FontImage Size={x:Static local:FontImageExtension.Size}, Color={x:Static local:FontImageExtension.Color}, FontFamily={x:Static local:FontImageExtension.FontFamily}, Glyph={x:Static local:FontImageExtension.Glyph}}" /> | ||
<Tab Title="World" Icon="{FontImage Size={x:Static local:FontImageExtension.Size}, Color={x:Static local:FontImageExtension.Color}, FontFamily={x:Static local:FontImageExtension.FontFamily}, Glyph={x:Static local:FontImageExtension.Glyph}}" /> | ||
<Tab Title="ContentProperty" Icon="{FontImage MyGlyph, Size={x:Static local:FontImageExtension.Size}, Color={x:Static local:FontImageExtension.Color}, FontFamily={x:Static local:FontImageExtension.FontFamily}}" /> | ||
|
||
</TabBar> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using NUnit.Framework; | ||
|
||
using Xamarin.Forms.Core.UnitTests; | ||
|
||
namespace Xamarin.Forms.Xaml.UnitTests | ||
{ | ||
public partial class FontImageExtension : TabBar | ||
{ | ||
public FontImageExtension() => InitializeComponent(); | ||
public FontImageExtension(bool useCompiledXaml) | ||
{ | ||
//this stub will be replaced at compile time | ||
} | ||
|
||
public static string FontFamily => "MyFontFamily"; | ||
public static string Glyph => "MyGlyph"; | ||
public static Color Color => Color.Black; | ||
public static double Size = 50d; | ||
|
||
[TestFixture] | ||
class Tests | ||
{ | ||
[SetUp] public void Setup() => Device.PlatformServices = new MockPlatformServices(); | ||
[TearDown] public void TearDown() => Device.PlatformServices = null; | ||
|
||
[TestCase(true), TestCase(false)] | ||
public void FontImageExtension_Positive(bool useCompiledXaml) | ||
{ | ||
var layout = new FontImageExtension(useCompiledXaml); | ||
var tabs = layout.AllChildren; | ||
|
||
foreach (var tab in tabs) | ||
{ | ||
Tab myTab = (Tab)tab; | ||
if (myTab == null) | ||
continue; | ||
|
||
Assert.That(myTab.Icon, Is.TypeOf<FontImageSource>()); | ||
|
||
var fontImage = (FontImageSource)myTab.Icon; | ||
Assert.AreEqual(FontFamily, fontImage.FontFamily); | ||
Assert.AreEqual(Glyph, fontImage.Glyph); | ||
Assert.AreEqual(Size, fontImage.Size); | ||
Assert.AreEqual(Color, fontImage.Color); | ||
} | ||
} | ||
|
||
[TestCase(true), TestCase(false)] | ||
public void FontImageExtension_Negative(bool useCompiledXaml) | ||
{ | ||
var layout = new FontImageExtension(useCompiledXaml); | ||
var tabs = layout.AllChildren; | ||
|
||
foreach (var tab in tabs) | ||
{ | ||
Tab myTab = (Tab)tab; | ||
if (myTab == null) | ||
continue; | ||
|
||
Assert.That(myTab.Icon, Is.Not.TypeOf<ImageSource>()); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
|
||
namespace Xamarin.Forms.Xaml | ||
{ | ||
[AcceptEmptyServiceProvider] | ||
[ContentProperty(nameof(Glyph))] | ||
public class FontImageExtension : IMarkupExtension<ImageSource> | ||
{ | ||
public string FontFamily { get; set; } | ||
public string Glyph { get; set; } | ||
public Color Color { get; set; } | ||
public double Size { get; set; } = (double)FontImageSource.SizeProperty.DefaultValue; | ||
|
||
public ImageSource ProvideValue(IServiceProvider serviceProvider) | ||
{ | ||
return new FontImageSource | ||
{ | ||
FontFamily = FontFamily, | ||
Glyph = Glyph, | ||
Color = Color, | ||
Size = Size | ||
}; | ||
} | ||
|
||
object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) | ||
{ | ||
return (this as IMarkupExtension<ImageSource>).ProvideValue(serviceProvider); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add the
Glyph
asContentProperty
attributeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not my first MarkupExtension and I noticed the other platform ones have
[ContentProperty]
but I am not sure exactly what it is for. How is it used?Adding this change is not a problem at all