summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-12-14 12:50:15 (GMT)
committerGitHub <noreply@github.com>2016-12-14 12:50:15 (GMT)
commit859b05887415ffdb1453065ee37cf225ca869523 (patch)
tree81eedba6697457fe124b72004aaf36ae463b18d0
parentd4792dc98dfca29849bedc21519d9cf9ae6f2cb6 (diff)
downloadxamarin-forms-859b05887415ffdb1453065ee37cf225ca869523.zip
xamarin-forms-859b05887415ffdb1453065ee37cf225ca869523.tar.gz
xamarin-forms-859b05887415ffdb1453065ee37cf225ca869523.tar.bz2
Xamlc compiled trigger (#629)
* [XamlC] compiled Trigger * remove file header * name bool parameters
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledValueProviders/SetterValueProvider.cs3
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs40
-rw-r--r--Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj1
-rw-r--r--Xamarin.Forms.Core/Interactivity/PropertyCondition.cs2
-rw-r--r--Xamarin.Forms.Core/Interactivity/Trigger.cs1
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/TriggerTests.xaml.cs13
6 files changed, 57 insertions, 3 deletions
diff --git a/Xamarin.Forms.Build.Tasks/CompiledValueProviders/SetterValueProvider.cs b/Xamarin.Forms.Build.Tasks/CompiledValueProviders/SetterValueProvider.cs
index 163bd9e..482ee7c 100644
--- a/Xamarin.Forms.Build.Tasks/CompiledValueProviders/SetterValueProvider.cs
+++ b/Xamarin.Forms.Build.Tasks/CompiledValueProviders/SetterValueProvider.cs
@@ -1,5 +1,4 @@
-´╗┐using System;
-using System.Collections.Generic;
+´╗┐using System.Collections.Generic;
using Mono.Cecil;
using Mono.Cecil.Cil;
diff --git a/Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs b/Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs
new file mode 100644
index 0000000..c2875c7
--- /dev/null
+++ b/Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs
@@ -0,0 +1,40 @@
+using System.Collections.Generic;
+
+using Mono.Cecil;
+using Mono.Cecil.Cil;
+
+using Xamarin.Forms.Xaml;
+using Xamarin.Forms.Build.Tasks;
+
+namespace Xamarin.Forms.Core.XamlC
+{
+
+ class TriggerValueProvider : ICompiledValueProvider
+ {
+ public IEnumerable<Instruction> ProvideValue(VariableDefinitionReference vardefref, ModuleDefinition module, BaseNode node, ILContext context)
+ {
+ var valueNode = ((IElementNode)node).Properties[new XmlName("", "Value")];
+
+ //if it's an elementNode, there's probably no need to convert it
+ if (valueNode is IElementNode)
+ yield break;
+
+ var value = ((string)((ValueNode)valueNode).Value);
+ var bpNode = ((ValueNode)((IElementNode)node).Properties[new XmlName("", "Property")]);
+ var bpRef = (new BindablePropertyConverter()).GetBindablePropertyFieldReference((string)bpNode.Value, module, bpNode);
+
+ TypeReference _;
+ var setValueRef = module.Import(module.Import(typeof(Trigger)).GetProperty(p => p.Name == "Value", out _).SetMethod);
+
+ //push the setter
+ yield return Instruction.Create(OpCodes.Ldloc, vardefref.VariableDefinition);
+
+ //push the value
+ foreach (var instruction in ((ValueNode)valueNode).PushConvertedValue(context, bpRef, valueNode.PushServiceProvider(context, bpRef: bpRef), boxValueTypes: true, unboxValueTypes: false))
+ yield return instruction;
+
+ //set the value
+ yield return Instruction.Create(OpCodes.Callvirt, setValueRef);
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj b/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj
index 51dd60b..ac7d6f1 100644
--- a/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj
+++ b/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj
@@ -107,6 +107,7 @@
<Compile Include="CompiledConverters\TypeTypeConverter.cs" />
<Compile Include="CompiledValueProviders\SetterValueProvider.cs" />
<Compile Include="CompiledValueProviders\ICompiledValueProvider.cs" />
+ <Compile Include="CompiledValueProviders\TriggerValueProvider.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild">
diff --git a/Xamarin.Forms.Core/Interactivity/PropertyCondition.cs b/Xamarin.Forms.Core/Interactivity/PropertyCondition.cs
index be37d48..34f4e1b 100644
--- a/Xamarin.Forms.Core/Interactivity/PropertyCondition.cs
+++ b/Xamarin.Forms.Core/Interactivity/PropertyCondition.cs
@@ -14,7 +14,7 @@ namespace Xamarin.Forms
public PropertyCondition()
{
- _stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(DataTrigger), false, propertyChanged: OnStatePropertyChanged);
+ _stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(PropertyCondition), false, propertyChanged: OnStatePropertyChanged);
}
public BindableProperty Property
diff --git a/Xamarin.Forms.Core/Interactivity/Trigger.cs b/Xamarin.Forms.Core/Interactivity/Trigger.cs
index ea3dc5a..a5d2c10 100644
--- a/Xamarin.Forms.Core/Interactivity/Trigger.cs
+++ b/Xamarin.Forms.Core/Interactivity/Trigger.cs
@@ -6,6 +6,7 @@ using Xamarin.Forms.Xaml;
namespace Xamarin.Forms
{
[ContentProperty("Setters")]
+ [ProvideCompiled("Xamarin.Forms.Core.XamlC.TriggerValueProvider")]
public sealed class Trigger : TriggerBase, IValueProvider
{
public Trigger([TypeConverter(typeof(TypeTypeConverter))] [Parameter("TargetType")] Type targetType) : base(new PropertyCondition(), targetType)
diff --git a/Xamarin.Forms.Xaml.UnitTests/TriggerTests.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/TriggerTests.xaml.cs
index 5fe61be..79886f8 100644
--- a/Xamarin.Forms.Xaml.UnitTests/TriggerTests.xaml.cs
+++ b/Xamarin.Forms.Xaml.UnitTests/TriggerTests.xaml.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using Xamarin.Forms;
using NUnit.Framework;
+using Xamarin.Forms.Core.UnitTests;
namespace Xamarin.Forms.Xaml.UnitTests
{
@@ -20,6 +21,18 @@ namespace Xamarin.Forms.Xaml.UnitTests
[TestFixture]
public class Tests
{
+ [SetUp]
+ public void Setup()
+ {
+ Device.PlatformServices = new MockPlatformServices();
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ Device.PlatformServices = null;
+ }
+
[TestCase (false)]
[TestCase (true)]
public void ValueIsConverted (bool useCompiledXaml)