This commit is contained in:
Rui Marinho 2018-08-15 20:19:45 +01:00
Родитель 884035ce8f 689a0bb9bc
Коммит 0610191b3d
6 изменённых файлов: 77 добавлений и 10 удалений

Просмотреть файл

@ -137,7 +137,7 @@ namespace Xamarin.Forms.Build.Tasks
var parentVar = Context.Variables[(IElementNode)parentNode];
string contentProperty;
if (CanAddToResourceDictionary(parentVar.VariableType, node, node, Context)) {
if (CanAddToResourceDictionary(parentVar, parentVar.VariableType, node, node, Context)) {
Context.IL.Emit(Ldloc, parentVar);
Context.IL.Append(AddToResourceDictionary(node, node, Context));
}
@ -186,7 +186,7 @@ namespace Xamarin.Forms.Build.Tasks
TypeReference propertyType;
Context.IL.Append(GetPropertyValue(parent, parentList.XmlName, Context, node, out propertyType));
if (CanAddToResourceDictionary(propertyType, node, node, Context)) {
if (CanAddToResourceDictionary(parent, propertyType, node, node, Context)) {
Context.IL.Append(AddToResourceDictionary(node, node, Context));
return;
}
@ -1220,15 +1220,23 @@ namespace Xamarin.Forms.Build.Tasks
return true;
}
static bool CanAddToResourceDictionary(TypeReference collectionType, IElementNode node, IXmlLineInfo lineInfo, ILContext context)
static Dictionary<VariableDefinition, IList<string>> resourceNamesInUse = new Dictionary<VariableDefinition, IList<string>>();
static bool CanAddToResourceDictionary(VariableDefinition parent, TypeReference collectionType, IElementNode node, IXmlLineInfo lineInfo, ILContext context)
{
if ( collectionType.FullName != "Xamarin.Forms.ResourceDictionary"
&& collectionType.ResolveCached().BaseType?.FullName != "Xamarin.Forms.ResourceDictionary")
return false;
if (node.Properties.ContainsKey(XmlName.xKey))
if (node.Properties.ContainsKey(XmlName.xKey)) {
var key = (node.Properties[XmlName.xKey] as ValueNode).Value as string;
if (!resourceNamesInUse.TryGetValue(parent, out var names))
resourceNamesInUse[parent] = (names = new List<string>());
if (names.Contains(key))
throw new XamlParseException($"A resource with the key '{key}' is already present in the ResourceDictionary.", lineInfo);
names.Add(key);
return true;
}
//is there a RD.Add() overrides that accepts this ?
var nodeTypeRef = context.Variables[node].VariableType;
@ -1251,7 +1259,7 @@ namespace Xamarin.Forms.Build.Tasks
foreach (var instruction in GetPropertyValue(parent, propertyName, context, iXmlLineInfo, out propertyType))
yield return instruction;
if (CanAddToResourceDictionary(propertyType, elementNode, iXmlLineInfo, context)) {
if (CanAddToResourceDictionary(parent, propertyType, elementNode, iXmlLineInfo, context)) {
foreach (var instruction in AddToResourceDictionary(elementNode, iXmlLineInfo, context))
yield return instruction;
yield break;

Просмотреть файл

@ -75,7 +75,7 @@ namespace Xamarin.Forms.Controls
{
FlowDirection = direction;
Master = new FlowDirectionGalleryCP(direction) { Title = "Master", BackgroundColor = Color.Red };
Detail = new FlowDirectionGalleryCP(direction) { Title = "Detail" };
Detail = new NavigationPage(new FlowDirectionGalleryCP(direction) { Title = "Detail" });
IsPresented = true;
}
}

Просмотреть файл

@ -47,11 +47,8 @@ namespace Xamarin.Forms.Platform.iOS
InnerDelegate _innerDelegate;
nfloat _masterWidth = 0;
EventedViewController _masterController;
MasterDetailPage _masterDetailPage;
bool _masterVisible;
VisualElementTracker _tracker;
Page PageController => Element as Page;
@ -186,7 +183,7 @@ namespace Xamarin.Forms.Platform.iOS
_masterWidth = (nfloat)Math.Max(_masterWidth, masterBounds.Width);
if (!masterBounds.IsEmpty)
MasterDetailPage.MasterBounds = new Rectangle(_masterWidth, 0, _masterWidth, masterBounds.Height);
MasterDetailPage.MasterBounds = new Rectangle(0, 0, _masterWidth, masterBounds.Height);
if (!detailsBounds.IsEmpty)
MasterDetailPage.DetailBounds = new Rectangle(0, 0, detailsBounds.Width, detailsBounds.Height);

Просмотреть файл

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Xamarin.Forms.Xaml.UnitTests.Gh3512">
<ContentPage.Resources>
<Style x:Key="foo" TargetType="Label"/>
<Style x:Key="foo" TargetType="Label"/>
</ContentPage.Resources>
</ContentPage>

Просмотреть файл

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using Xamarin.Forms;
using Xamarin.Forms.Core.UnitTests;
namespace Xamarin.Forms.Xaml.UnitTests
{
[XamlCompilation(XamlCompilationOptions.Skip)]
public partial class Gh3512 : ContentPage
{
public Gh3512()
{
InitializeComponent();
}
public Gh3512(bool useCompiledXaml)
{
//this stub will be replaced at compile time
}
[TestFixture]
class Tests
{
[SetUp]
public void Setup()
{
Device.PlatformServices = new MockPlatformServices();
}
[TearDown]
public void TearDown()
{
Device.PlatformServices = null;
}
[TestCase(false), TestCase(true)]
public void ThrowsOnDuplicateXKey(bool useCompiledXaml)
{
if (useCompiledXaml)
Assert.Throws<XamlParseException>(() => MockCompiler.Compile(typeof(Gh3512)));
else
Assert.Throws<ArgumentException>(() => new Gh3512(useCompiledXaml));
}
}
}
}

Просмотреть файл

@ -634,6 +634,9 @@
<Compile Include="Issues\Gh3280.xaml.cs">
<DependentUpon>Gh3280.xaml</DependentUpon>
</Compile>
<Compile Include="Issues\Gh3512.xaml.cs">
<DependentUpon>Gh3512.xaml</DependentUpon>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\.nuspec\Xamarin.Forms.Debug.targets" Condition="'$(BuildingInsideVisualStudio)' == 'true' AND Exists('..\.nuspec\Xamarin.Forms.Build.Tasks.dll')" />
@ -1152,6 +1155,10 @@
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Issues\Gh3512.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />