summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-12-23 09:21:30 (GMT)
committerGitHub <noreply@github.com>2016-12-23 09:21:30 (GMT)
commitc34016dc84a30a351d9323285b68ce6cb02af969 (patch)
tree1c223684896b460d13a0fe84f4d91926f540f922
parentb96df000db76ba3490589c37e93224271249bc88 (diff)
downloadxamarin-forms-c34016dc84a30a351d9323285b68ce6cb02af969.zip
xamarin-forms-c34016dc84a30a351d9323285b68ce6cb02af969.tar.gz
xamarin-forms-c34016dc84a30a351d9323285b68ce6cb02af969.tar.bz2
Xamlc compile data triggers (#648)
* [Xaml] DataTrigger and PropertyCondition no longer use a ServiceProvider * [XamlC] avoid generating ServiceProvider for unused ProvideValue * fix tests
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledValueProviders/PassthroughValueProvider.cs18
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs1
-rw-r--r--Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj1
-rw-r--r--Xamarin.Forms.Core.UnitTests/DataTriggerTests.cs14
-rw-r--r--Xamarin.Forms.Core.UnitTests/MultiTriggerTests.cs14
-rw-r--r--Xamarin.Forms.Core/Interactivity/BindingCondition.cs15
-rw-r--r--Xamarin.Forms.Core/Interactivity/DataTrigger.cs5
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Issues/Bz28719.xaml.cs18
-rw-r--r--Xamarin.Forms.Xaml/ValueConverterProvider.cs5
9 files changed, 74 insertions, 17 deletions
diff --git a/Xamarin.Forms.Build.Tasks/CompiledValueProviders/PassthroughValueProvider.cs b/Xamarin.Forms.Build.Tasks/CompiledValueProviders/PassthroughValueProvider.cs
new file mode 100644
index 0000000..b3d59f9
--- /dev/null
+++ b/Xamarin.Forms.Build.Tasks/CompiledValueProviders/PassthroughValueProvider.cs
@@ -0,0 +1,18 @@
+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 PassthroughValueProvider : ICompiledValueProvider
+ {
+ public IEnumerable<Instruction> ProvideValue(VariableDefinitionReference vardefref, ModuleDefinition module, BaseNode node, ILContext context)
+ {
+ yield break;
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs b/Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs
index c2875c7..6a0ca82 100644
--- a/Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs
+++ b/Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs
@@ -8,7 +8,6 @@ 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)
diff --git a/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj b/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj
index ac7d6f1..21c5168 100644
--- a/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj
+++ b/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj
@@ -108,6 +108,7 @@
<Compile Include="CompiledValueProviders\SetterValueProvider.cs" />
<Compile Include="CompiledValueProviders\ICompiledValueProvider.cs" />
<Compile Include="CompiledValueProviders\TriggerValueProvider.cs" />
+ <Compile Include="CompiledValueProviders\PassthroughValueProvider.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild">
diff --git a/Xamarin.Forms.Core.UnitTests/DataTriggerTests.cs b/Xamarin.Forms.Core.UnitTests/DataTriggerTests.cs
index 585bebc..2238429 100644
--- a/Xamarin.Forms.Core.UnitTests/DataTriggerTests.cs
+++ b/Xamarin.Forms.Core.UnitTests/DataTriggerTests.cs
@@ -6,6 +6,20 @@ namespace Xamarin.Forms.Core.UnitTests
[TestFixture]
public class DataTriggerTests : BaseTestFixture
{
+ [SetUp]
+ public override void Setup()
+ {
+ Device.PlatformServices = new MockPlatformServices();
+ base.Setup();
+ }
+
+ [TearDown]
+ public override void TearDown()
+ {
+ base.TearDown();
+ Device.PlatformServices = null;
+ }
+
class MockElement : VisualElement
{
}
diff --git a/Xamarin.Forms.Core.UnitTests/MultiTriggerTests.cs b/Xamarin.Forms.Core.UnitTests/MultiTriggerTests.cs
index df253e7..df51534 100644
--- a/Xamarin.Forms.Core.UnitTests/MultiTriggerTests.cs
+++ b/Xamarin.Forms.Core.UnitTests/MultiTriggerTests.cs
@@ -5,6 +5,20 @@ namespace Xamarin.Forms.Core.UnitTests
[TestFixture]
public class MultiTriggerTests : BaseTestFixture
{
+ [SetUp]
+ public override void Setup()
+ {
+ Device.PlatformServices = new MockPlatformServices();
+ base.Setup();
+ }
+
+ [TearDown]
+ public override void TearDown()
+ {
+ base.TearDown();
+ Device.PlatformServices = null;
+ }
+
class MockElement : VisualElement
{
}
diff --git a/Xamarin.Forms.Core/Interactivity/BindingCondition.cs b/Xamarin.Forms.Core/Interactivity/BindingCondition.cs
index 1d11185..ccf55e5 100644
--- a/Xamarin.Forms.Core/Interactivity/BindingCondition.cs
+++ b/Xamarin.Forms.Core/Interactivity/BindingCondition.cs
@@ -3,6 +3,7 @@ using Xamarin.Forms.Xaml;
namespace Xamarin.Forms
{
+ [ProvideCompiled("Xamarin.Forms.Core.XamlC.PassthroughValueProvider")]
public sealed class BindingCondition : Condition, IValueProvider
{
readonly BindableProperty _boundProperty;
@@ -41,15 +42,9 @@ namespace Xamarin.Forms
}
}
- internal IServiceProvider ServiceProvider { get; set; }
-
- internal IValueConverterProvider ValueConverter { get; set; }
-
object IValueProvider.ProvideValue(IServiceProvider serviceProvider)
{
- ValueConverter = serviceProvider.GetService(typeof(IValueConverterProvider)) as IValueConverterProvider;
- ServiceProvider = serviceProvider;
-
+ //This is no longer required
return this;
}
@@ -71,14 +66,16 @@ namespace Xamarin.Forms
bindable.ClearValue(_boundProperty);
}
+ static IValueConverterProvider s_valueConverter = DependencyService.Get<IValueConverterProvider>();
+
bool EqualsToValue(object other)
{
if ((other == Value) || (other != null && other.Equals(Value)))
return true;
object converted = null;
- if (ValueConverter != null)
- converted = ValueConverter.Convert(Value, other != null ? other.GetType() : typeof(object), null, ServiceProvider);
+ if (s_valueConverter != null)
+ converted = s_valueConverter.Convert(Value, other != null ? other.GetType() : typeof(object), null, null);
else
return false;
diff --git a/Xamarin.Forms.Core/Interactivity/DataTrigger.cs b/Xamarin.Forms.Core/Interactivity/DataTrigger.cs
index e27ec13..d90cf44 100644
--- a/Xamarin.Forms.Core/Interactivity/DataTrigger.cs
+++ b/Xamarin.Forms.Core/Interactivity/DataTrigger.cs
@@ -5,6 +5,7 @@ using Xamarin.Forms.Xaml;
namespace Xamarin.Forms
{
[ContentProperty("Setters")]
+ [ProvideCompiled("Xamarin.Forms.Core.XamlC.PassthroughValueProvider")]
public sealed class DataTrigger : TriggerBase, IValueProvider
{
public DataTrigger([TypeConverter(typeof(TypeTypeConverter))] [Parameter("TargetType")] Type targetType) : base(new BindingCondition(), targetType)
@@ -48,9 +49,7 @@ namespace Xamarin.Forms
object IValueProvider.ProvideValue(IServiceProvider serviceProvider)
{
- var valueconverter = serviceProvider.GetService(typeof(IValueConverterProvider)) as IValueConverterProvider;
- (Condition as BindingCondition).ValueConverter = valueconverter;
-
+ //This is no longer required
return this;
}
}
diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28719.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28719.xaml.cs
index 5cd1f9c..bd0fe48 100644
--- a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28719.xaml.cs
+++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28719.xaml.cs
@@ -1,8 +1,6 @@
-´╗┐using System;
-using System.Collections.Generic;
+´╗┐using NUnit.Framework;
-using Xamarin.Forms;
-using NUnit.Framework;
+using Xamarin.Forms.Core.UnitTests;
namespace Xamarin.Forms.Xaml.UnitTests
{
@@ -21,6 +19,18 @@ namespace Xamarin.Forms.Xaml.UnitTests
[TestFixture]
class Tests
{
+ [SetUp]
+ public void Setup()
+ {
+ Device.PlatformServices = new MockPlatformServices();
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ Device.PlatformServices = null;
+ }
+
[TestCase(true)]
[TestCase(false)]
public void DataTriggerInTemplates (bool useCompiledXaml)
diff --git a/Xamarin.Forms.Xaml/ValueConverterProvider.cs b/Xamarin.Forms.Xaml/ValueConverterProvider.cs
index 6758f9a..0f3871b 100644
--- a/Xamarin.Forms.Xaml/ValueConverterProvider.cs
+++ b/Xamarin.Forms.Xaml/ValueConverterProvider.cs
@@ -1,6 +1,11 @@
using System;
using System.Reflection;
+using Xamarin.Forms;
+using Xamarin.Forms.Xaml;
+
+[assembly:Dependency(typeof(ValueConverterProvider))]
+
namespace Xamarin.Forms.Xaml
{
class ValueConverterProvider : IValueConverterProvider