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

feat: Allow for key override for non-ignored namespaces #105

Merged
merged 1 commit into from
Dec 16, 2022
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
50 changes: 50 additions & 0 deletions src/UWP/TestLibrary/Generated/mergedpages01.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
<ResourceDictionary Source="ms-appx:///TestLibrary/Colors.xaml" />
<ResourceDictionary Source="ms-appx:///TestLibrary/Colors.xaml" />
<ResourceDictionary Source="ms-appx:///TestLibrary/Colors.xaml" />
<ResourceDictionary Source="ms-appx:///TestLibrary/Colors.xaml" />
<ResourceDictionary Source="ms-appx:///TestLibrary/Colors.xaml" />
<ResourceDictionary Source="ms-appx:///TestLibrary/Colors.xaml" />
<ResourceDictionary Source="ms-appx:///TestLibrary/Colors.xaml" />
<ResourceDictionary Source="ms-appx:///TestLibrary/Colors.xaml" />
</ResourceDictionary.MergedDictionaries>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
Expand Down Expand Up @@ -172,6 +177,51 @@
</Setter.Value>
</Setter>
</xamarin:Style>
<xamarin:Style TargetType="ItemsControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ItemsControl">
<ItemsPresenter Padding="{TemplateBinding Padding}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</xamarin:Style>
<xamarin:Style TargetType="ItemsControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ItemsControl">
<ItemsPresenter Padding="{TemplateBinding Padding}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</xamarin:Style>
<xamarin:Style TargetType="ItemsControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ItemsControl">
<ItemsPresenter Padding="{TemplateBinding Padding}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</xamarin:Style>
<xamarin:Style TargetType="ItemsControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ItemsControl">
<ItemsPresenter Padding="{TemplateBinding Padding}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</xamarin:Style>
<xamarin:Style TargetType="ItemsControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ItemsControl">
<ItemsPresenter Padding="{TemplateBinding Padding}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</xamarin:Style>
<!--origin: Generated\mergedpages02.xaml-->
<!--origin: Inner1\Colors.xaml-->
<!--origin: Inner1\ImplicitConflict.xaml-->
Expand Down
32 changes: 31 additions & 1 deletion src/Uno.XamlMerge.Task/MergedDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,13 @@ private void AddNode(XmlNode node, Dictionary<string, string> xmlnsReplacementDi
// if it's not, or if we haven't seen a previous node with this key, then we'll just
// add it to our list.
string simpleNodeKey = GetKey(node);
string nodeKey = simpleNodeKey + node.Prefix;
var currentIgnorables = BuildIgnorables();

// We need allow ignored keys as they may be used to provide
// per-platform styles based on uno's selective ignorables.
string nodeKey = (currentIgnorables?.Contains(node.Prefix) ?? false)
? simpleNodeKey + node.Prefix
: simpleNodeKey;

if (simpleNodeKey.Length == 0 || !nodeKeyToNodeListIndexDictionary.ContainsKey(nodeKey))
{
Expand Down Expand Up @@ -275,6 +281,30 @@ private void AddNode(XmlNode node, Dictionary<string, string> xmlnsReplacementDi
}
}

private string[] BuildIgnorables()
{
HashSet<string> result = new();

var current = this;

do
{
var nsList = current._ignorablesAttribute?.Value.Split(' ') ?? Array.Empty<string>();

foreach (var ns in nsList)
{
if (!result.Contains(ns))
{
result.Add(ns);
}
}
current = current.parentDictionary;

} while (current != null);

return result.ToArray();
}

private XmlNode GetXaml()
{
if (parentDictionary == null)
Expand Down
31 changes: 31 additions & 0 deletions src/Uno.XamlMerge.Tests/Given_BatchMergeXaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,37 @@ public void When_Duplicate_Keys_Different_Namespace_Single_Input()
ValidateOutput(task);
}

[TestMethod]
public void When_Duplicate_ThemeResources()
{
var task = CreateMerger();

Assert.IsTrue(task.Execute());

ValidateOutput(task);
}

[TestMethod]
public void When_Duplicate_ThemeResources_With_Prefix()
{
var task = CreateMerger();

Assert.IsTrue(task.Execute());

ValidateOutput(task);
}


[TestMethod]
public void When_Duplicate_ThemeResources_With_Ignored_Prefix()
{
var task = CreateMerger();

Assert.IsTrue(task.Execute());

ValidateOutput(task);
}

[TestMethod]
public void When_Duplicate_Keys_Different_Namespace_Multiple_Input()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="netstdref wasm skia not_win" xmlns:contract7Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,7)" xmlns:contract7NotPresent="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractNotPresent(Windows.Foundation.UniversalApiContract,7)" xmlns:netstdref="http://uno.ui/netstdref" xmlns:wasm="http://uno.ui/wasm" xmlns:skia="http://uno.ui/skia" xmlns:not_win="http://uno.ui/not_win" xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<Thickness x:Key="FlipViewButtonBorderThemeThickness">1</Thickness>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="netstdref wasm skia not_win" xmlns:contract7Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,7)" xmlns:contract7NotPresent="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractNotPresent(Windows.Foundation.UniversalApiContract,7)" xmlns:netstdref="http://uno.ui/netstdref" xmlns:wasm="http://uno.ui/wasm" xmlns:skia="http://uno.ui/skia" xmlns:not_win="http://uno.ui/not_win" xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<Thickness x:Key="FlipViewButtonBorderThemeThickness">2</Thickness>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="netstdref wasm skia not_win" xmlns:contract7Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,7)" xmlns:contract7NotPresent="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractNotPresent(Windows.Foundation.UniversalApiContract,7)" xmlns:netstdref="http://uno.ui/netstdref" xmlns:wasm="http://uno.ui/wasm" xmlns:skia="http://uno.ui/skia" xmlns:not_win="http://uno.ui/not_win" xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<Thickness x:Key="FlipViewButtonBorderThemeThickness">2</Thickness>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<!--origin: When_Duplicate_ThemeResources\Input_Dictionary_1.xml-->
<!--origin: When_Duplicate_ThemeResources\Input_Dictionary_2.xml-->
</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="a1" xmlns:a1="using:ns1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<a1:Thickness x:Key="FlipViewButtonBorderThemeThickness">2</a1:Thickness>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="a2" xmlns:a2="using:ns1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<a2:Thickness x:Key="FlipViewButtonBorderThemeThickness">2</a2:Thickness>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="a1 a2" xmlns:a1="using:ns1" xmlns:a2="using:ns1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<a1:Thickness x:Key="FlipViewButtonBorderThemeThickness">2</a1:Thickness>
<a2:Thickness x:Key="FlipViewButtonBorderThemeThickness">2</a2:Thickness>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<!--origin: When_Duplicate_ThemeResources_With_Ignored_Prefix\Input_Dictionary_1.xml-->
<!--origin: When_Duplicate_ThemeResources_With_Ignored_Prefix\Input_Dictionary_2.xml-->
</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:a1="using:ns1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<a1:Thickness x:Key="FlipViewButtonBorderThemeThickness">2</a1:Thickness>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:a2="using:ns1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<a2:Thickness x:Key="FlipViewButtonBorderThemeThickness">2</a2:Thickness>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:a1="using:ns1" xmlns:a2="using:ns1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<a2:Thickness x:Key="FlipViewButtonBorderThemeThickness">2</a2:Thickness>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<!--origin: When_Duplicate_ThemeResources_With_Prefix\Input_Dictionary_1.xml-->
<!--origin: When_Duplicate_ThemeResources_With_Prefix\Input_Dictionary_2.xml-->
</ResourceDictionary>