Skip to content

Commit

Permalink
Add a Default Property binder for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
anaisbetts committed Jun 12, 2013
1 parent c849402 commit 7cc5cf0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
30 changes: 30 additions & 0 deletions ReactiveUI.Platforms/Android/AndroidDefaultPropertyBinding.cs
@@ -0,0 +1,30 @@
using System;
using System.Linq;
using ReactiveUI;
using Android.Widget;

namespace ReactiveUI.Android
{
/// <summary>
/// Default property bindings for common Android widgets
/// </summary>
public class AndroidDefaultPropertyBinding : IDefaultPropertyBindingProvider
{
public Tuple<string, int> GetPropertyForControl(object control)
{
// NB: These are intentionally arranged in priority order from most
// specific to least specific.
var items = new[] {
new { Type = typeof(TextView), Property = "Text" },
new { Type = typeof(ImageView), Property = "Drawable" },
new { Type = typeof(ProgressBar), Property = "Progress" },
new { Type = typeof(CompoundButton), Property = "Checked" },
};

var type = control.GetType();
var kvp = items.FirstOrDefault(x => x.Type.IsAssignableFrom(type));

return kvp != null ? Tuple.Create(kvp.Property, 5) : null;
}
}
}
1 change: 0 additions & 1 deletion ReactiveUI.Platforms/Cocoa/CocoaDefaultPropertyBinding.cs
Expand Up @@ -43,6 +43,5 @@ public class CocoaDefaultPropertyBinding : IDefaultPropertyBindingProvider

return kvp != null ? Tuple.Create(kvp.Property, 5) : null;
}

}
}
1 change: 1 addition & 0 deletions ReactiveUI.Platforms/ReactiveUI.Android.csproj
Expand Up @@ -74,6 +74,7 @@
<Compile Include="Android\PlatformOperations.cs" />
<Compile Include="Android\ReactiveActivity.cs" />
<Compile Include="Android\ReactiveFragment.cs" />
<Compile Include="Android\AndroidDefaultPropertyBinding.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ReactiveUI\ReactiveUI_Monodroid.csproj">
Expand Down
4 changes: 4 additions & 0 deletions ReactiveUI.Platforms/Registrations.cs
Expand Up @@ -51,6 +51,10 @@ public void Register(Action<Func<object>, Type> registerFunction)
registerFunction(() => new AutoDataTemplateBindingHook(), typeof(IPropertyBindingHook));
#endif

#if ANDROID
registerFunction(() => new AndroidDefaultPropertyBinding(), typeof(IDefaultPropertyBindingProvider));
#endif

#if UIKIT
registerFunction(() => UIKitObservableForProperty.Instance.Value, typeof(ICreatesObservableForProperty));
registerFunction(() => UIKitCommandBinders.Instance.Value, typeof(ICreatesCommandBinding));
Expand Down

0 comments on commit 7cc5cf0

Please sign in to comment.