summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-09-08 18:39:05 (GMT)
committerJason Smith <jason.smith@xamarin.com>2016-09-08 18:39:05 (GMT)
commit85426c5d9495eb1d55b3128bf97e50c68a73b53f (patch)
tree2f81e5868ce61eb90d15c6c51a354603b8395627 /Xamarin.Forms.Platform.Android
parent11326e1c182b3ff5c3d82c6ef7d09c193bc19891 (diff)
downloadxamarin-forms-85426c5d9495eb1d55b3128bf97e50c68a73b53f.zip
xamarin-forms-85426c5d9495eb1d55b3128bf97e50c68a73b53f.tar.gz
xamarin-forms-85426c5d9495eb1d55b3128bf97e50c68a73b53f.tar.bz2
Native Bindings (#278)
* [C, I, A, W] Support Native Bindings * fix tabs
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r--Xamarin.Forms.Platform.Android/ColorExtensions.cs5
-rw-r--r--Xamarin.Forms.Platform.Android/Extensions/NativeBindingExtensions.cs33
-rw-r--r--Xamarin.Forms.Platform.Android/NativeViewWrapper.cs10
-rw-r--r--Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj6
4 files changed, 53 insertions, 1 deletions
diff --git a/Xamarin.Forms.Platform.Android/ColorExtensions.cs b/Xamarin.Forms.Platform.Android/ColorExtensions.cs
index db190b4..93e2312 100644
--- a/Xamarin.Forms.Platform.Android/ColorExtensions.cs
+++ b/Xamarin.Forms.Platform.Android/ColorExtensions.cs
@@ -36,5 +36,10 @@ namespace Xamarin.Forms.Platform.Android
int disabled = defaults.GetColorForState(States[1], color.ToAndroid());
return new ColorStateList(States, new[] { color.ToAndroid().ToArgb(), disabled });
}
+
+ public static Color ToColor(this AColor color)
+ {
+ return Color.FromUint((uint)color.ToArgb());
+ }
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.Android/Extensions/NativeBindingExtensions.cs b/Xamarin.Forms.Platform.Android/Extensions/NativeBindingExtensions.cs
new file mode 100644
index 0000000..fd07246
--- /dev/null
+++ b/Xamarin.Forms.Platform.Android/Extensions/NativeBindingExtensions.cs
@@ -0,0 +1,33 @@
+´╗┐using System;
+using System.Collections.Generic;
+
+namespace Xamarin.Forms.Platform.Android
+{
+ public static class NativeBindingExtensions
+ {
+ public static void SetBinding(this global::Android.Views.View view, string propertyName, BindingBase binding, string updateSourceEventName = null)
+ {
+ NativeBindingHelpers.SetBinding(view, propertyName, binding, updateSourceEventName);
+ }
+
+ public static void SetBinding(this global::Android.Views.View view, BindableProperty targetProperty, BindingBase binding)
+ {
+ NativeBindingHelpers.SetBinding(view, targetProperty, binding);
+ }
+
+ public static void SetValue(this global::Android.Views.View target, BindableProperty targetProperty, object value)
+ {
+ NativeBindingHelpers.SetValue(target, targetProperty, value);
+ }
+
+ public static void SetBindingContext(this global::Android.Views.View target, object bindingContext, Func<global::Android.Views.View, IEnumerable<global::Android.Views.View>> getChildren = null)
+ {
+ NativeBindingHelpers.SetBindingContext(target, bindingContext, getChildren);
+ }
+
+ internal static void TransferBindablePropertiesToWrapper(this global::Android.Views.View target, View wrapper)
+ {
+ NativeBindingHelpers.TransferBindablePropertiesToWrapper(target, wrapper);
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.Android/NativeViewWrapper.cs b/Xamarin.Forms.Platform.Android/NativeViewWrapper.cs
index eecef9b..53b5253 100644
--- a/Xamarin.Forms.Platform.Android/NativeViewWrapper.cs
+++ b/Xamarin.Forms.Platform.Android/NativeViewWrapper.cs
@@ -1,3 +1,5 @@
+using Android.Views;
+
namespace Xamarin.Forms.Platform.Android
{
public class NativeViewWrapper : View
@@ -9,6 +11,8 @@ namespace Xamarin.Forms.Platform.Android
NativeView = nativeView;
OnLayoutDelegate = onLayoutDelegate;
OnMeasureDelegate = onMeasureDelegate;
+
+ nativeView.TransferBindablePropertiesToWrapper(this);
}
public GetDesiredSizeDelegate GetDesiredSizeDelegate { get; }
@@ -18,5 +22,11 @@ namespace Xamarin.Forms.Platform.Android
public OnLayoutDelegate OnLayoutDelegate { get; }
public OnMeasureDelegate OnMeasureDelegate { get; }
+
+ protected override void OnBindingContextChanged()
+ {
+ NativeView.SetBindingContext(BindingContext, (view) => (view as ViewGroup)?.GetChildrenOfType<global::Android.Views.View>());
+ base.OnBindingContextChanged();
+ }
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj b/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj
index 33bfa03..0017971 100644
--- a/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj
+++ b/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj
@@ -241,6 +241,7 @@
<Compile Include="AppCompat\FormsFragmentPagerAdapter.cs" />
<Compile Include="AndroidAppIndexProvider.cs" />
<Compile Include="Renderers\FormsSeekBar.cs" />
+ <Compile Include="Extensions\NativeBindingExtensions.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
@@ -263,6 +264,9 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
+ <ItemGroup>
+ <Folder Include="Extensions\" />
+ </ItemGroup>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Import Project="..\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\build\Xamarin.Android.Support.Vector.Drawable.targets" Condition="Exists('..\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\build\Xamarin.Android.Support.Vector.Drawable.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
@@ -271,4 +275,4 @@
</PropertyGroup>
<Error Condition="!Exists('..\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\build\Xamarin.Android.Support.Vector.Drawable.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\build\Xamarin.Android.Support.Vector.Drawable.targets'))" />
</Target>
-</Project> \ No newline at end of file
+</Project>