ExtendedTextCell and ExtendedViewCell for iOS and Android. BackgroundColor and Disclousure Indicators

This commit is contained in:
Kyle Spearrin 2016-05-17 21:28:19 -04:00
parent e9999adcf2
commit 72c807a5b2
14 changed files with 186 additions and 26 deletions

View file

@ -197,6 +197,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Controls\ExtendedEditorRenderer.cs" />
<Compile Include="Controls\ExtendedViewCellRenderer.cs" />
<Compile Include="Controls\ExtendedTextCellRenderer.cs" />
<Compile Include="Controls\ExtendedPickerRenderer.cs" />
<Compile Include="Controls\ExtendedEntryRenderer.cs" />

View file

@ -6,6 +6,7 @@ using Bit.App.Controls;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using AView = Android.Views.View;
using Android.Widget;
[assembly: ExportRenderer(typeof(ExtendedTextCell), typeof(ExtendedTextCellRenderer))]
namespace Bit.Android.Controls
@ -16,11 +17,29 @@ namespace Bit.Android.Controls
protected override AView GetCellCore(Cell item, AView convertView, ViewGroup parent, Context context)
{
var View = base.GetCellCore(item, convertView, parent, context);
var View = (BaseCellView)base.GetCellCore(item, convertView, parent, context);
var extendedCell = (ExtendedTextCell)item;
var cell = (ExtendedTextCell)item;
if(View != null)
{
View.SetBackgroundColor(extendedCell.BackgroundColor.ToAndroid());
View.SetBackgroundColor(cell.BackgroundColor.ToAndroid());
if(extendedCell.ShowDisclousure)
{
// TODO: different image
var resourceId = Resource.Drawable.fa_folder_open;
if(!string.IsNullOrWhiteSpace(extendedCell.DisclousureImage))
{
var fileName = System.IO.Path.GetFileNameWithoutExtension(extendedCell.DisclousureImage);
resourceId = context.Resources.GetIdentifier(fileName, "drawable", context.PackageName);
}
var image = new ImageView(context);
image.SetImageResource(resourceId);
image.SetPadding(0, 0, 30, 0);
View.SetAccessoryView(image);
}
}
return View;
}
@ -35,6 +54,8 @@ namespace Bit.Android.Controls
{
View.SetBackgroundColor(cell.BackgroundColor.ToAndroid());
}
// TODO: other properties
}
}
}

View file

@ -0,0 +1,42 @@
using Android.Content;
using System.ComponentModel;
using Android.Views;
using Bit.Android.Controls;
using Bit.App.Controls;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using AView = Android.Views.View;
[assembly: ExportRenderer(typeof(ExtendedViewCell), typeof(ExtendedViewCellRenderer))]
namespace Bit.Android.Controls
{
public class ExtendedViewCellRenderer : ViewCellRenderer
{
protected AView View { get; private set; }
protected override AView GetCellCore(Cell item, AView convertView, ViewGroup parent, Context context)
{
var View = base.GetCellCore(item, convertView, parent, context);
var extendedCell = (ExtendedViewCell)item;
if(View != null)
{
View.SetBackgroundColor(extendedCell.BackgroundColor.ToAndroid());
}
return View;
}
protected override void OnCellPropertyChanged(object sender, PropertyChangedEventArgs args)
{
base.OnCellPropertyChanged(sender, args);
var cell = (ExtendedTextCell)Cell;
if(args.PropertyName == ExtendedTextCell.BackgroundColorProperty.PropertyName)
{
View.SetBackgroundColor(cell.BackgroundColor.ToAndroid());
}
}
}
}

View file

@ -52,6 +52,7 @@
<Compile Include="Controls\ExtendedPicker.cs" />
<Compile Include="Controls\ExtendedEntry.cs" />
<Compile Include="Controls\ExtendedTabbedPage.cs" />
<Compile Include="Controls\ExtendedViewCell.cs" />
<Compile Include="Controls\FormEditorCell.cs" />
<Compile Include="Controls\ExtendedTextCell.cs" />
<Compile Include="Controls\LabeledValueCell.cs" />

View file

@ -1,17 +1,34 @@
using System;
using Xamarin.Forms;
using Xamarin.Forms;
namespace Bit.App.Controls
{
public class ExtendedTextCell : TextCell
{
public static readonly BindableProperty BackgroundColorProperty =
BindableProperty.Create(nameof(BackgroundColor), typeof(Color), typeof(ExtendedTextCell), Color.Transparent);
BindableProperty.Create(nameof(BackgroundColor), typeof(Color), typeof(ExtendedTextCell), Color.White);
public static readonly BindableProperty ShowDisclousureProperty =
BindableProperty.Create(nameof(DisclousureImage), typeof(bool), typeof(ExtendedTextCell), false);
public static readonly BindableProperty DisclousureImageProperty =
BindableProperty.Create(nameof(DisclousureImage), typeof(string), typeof(ExtendedTextCell), string.Empty);
public Color BackgroundColor
{
get { return (Color)GetValue(BackgroundColorProperty); }
set { SetValue(BackgroundColorProperty, value); }
}
public bool ShowDisclousure
{
get { return (bool)GetValue(ShowDisclousureProperty); }
set { SetValue(ShowDisclousureProperty, value); }
}
public string DisclousureImage
{
get { return (string)GetValue(DisclousureImageProperty); }
set { SetValue(DisclousureImageProperty, value); }
}
}
}

View file

@ -0,0 +1,16 @@
using Xamarin.Forms;
namespace Bit.App.Controls
{
public class ExtendedViewCell : ViewCell
{
public static readonly BindableProperty BackgroundColorProperty =
BindableProperty.Create(nameof(BackgroundColor), typeof(Color), typeof(ExtendedTextCell), Color.White);
public Color BackgroundColor
{
get { return (Color)GetValue(BackgroundColorProperty); }
set { SetValue(BackgroundColorProperty, value); }
}
}
}

View file

@ -3,7 +3,7 @@ using Xamarin.Forms;
namespace Bit.App.Controls
{
public class FormEditorCell : ViewCell
public class FormEditorCell : ExtendedViewCell
{
public FormEditorCell(Keyboard entryKeyboard = null, double? height = null)
{
@ -20,8 +20,7 @@ namespace Bit.App.Controls
var stackLayout = new StackLayout
{
Padding = new Thickness(15),
BackgroundColor = Color.White
Padding = new Thickness(15)
};
stackLayout.Children.Add(Editor);

View file

@ -1,9 +1,8 @@
using System;
using Xamarin.Forms;
using Xamarin.Forms;
namespace Bit.App.Controls
{
public class FormEntryCell : ViewCell
public class FormEntryCell : ExtendedViewCell
{
public FormEntryCell(string labelText, Keyboard entryKeyboard = null, bool IsPassword = false)
{
@ -25,8 +24,7 @@ namespace Bit.App.Controls
var stackLayout = new StackLayout
{
Padding = new Thickness(15),
BackgroundColor = Color.White
Padding = new Thickness(15)
};
stackLayout.Children.Add(Label);

View file

@ -4,7 +4,7 @@ using Xamarin.Forms;
namespace Bit.App.Controls
{
public class FormPickerCell : ViewCell
public class FormPickerCell : ExtendedViewCell
{
public FormPickerCell(string labelText, string[] pickerItems)
{
@ -31,8 +31,7 @@ namespace Bit.App.Controls
var stackLayout = new StackLayout
{
Padding = new Thickness(15),
BackgroundColor = Color.White
Padding = new Thickness(15)
};
stackLayout.Children.Add(Label);

View file

@ -1,13 +1,8 @@
using Acr.UserDialogs;
using Bit.App.Abstractions;
using Bit.App.Resources;
using System;
using Xamarin.Forms;
using XLabs.Ioc;
using Xamarin.Forms;
namespace Bit.App.Controls
{
public class LabeledValueCell : ViewCell
public class LabeledValueCell : ExtendedViewCell
{
public LabeledValueCell(
string labelText = null,
@ -18,7 +13,6 @@ namespace Bit.App.Controls
var containerStackLayout = new StackLayout
{
Padding = new Thickness(15),
BackgroundColor = Color.White,
Orientation = StackOrientation.Horizontal
};

View file

@ -20,7 +20,7 @@ namespace Bit.App.Pages
private void Init()
{
var foldersCell = new TextCell { Text = "Folders" };
var foldersCell = new ExtendedTextCell { Text = "Folders", ShowDisclousure = true };
foldersCell.Tapped += FoldersCell_Tapped;
var table = new ExtendedTableView

View file

@ -0,0 +1,45 @@
using Bit.App.Controls;
using Bit.iOS.Controls;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using CoreGraphics;
[assembly: ExportRenderer(typeof(ExtendedTextCell), typeof(ExtendedTextCellRenderer))]
namespace Bit.iOS.Controls
{
public class ExtendedTextCellRenderer : TextCellRenderer
{
public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
{
var extendedCell = (ExtendedTextCell)item;
var cell = base.GetCell(item, reusableCell, tv);
if(cell != null)
{
cell.BackgroundColor = extendedCell.BackgroundColor.ToUIColor();
if(extendedCell.ShowDisclousure)
{
cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
if(!string.IsNullOrEmpty(extendedCell.DisclousureImage))
{
var detailDisclosureButton = UIButton.FromType(UIButtonType.Custom);
detailDisclosureButton.SetImage(UIImage.FromBundle(extendedCell.DisclousureImage), UIControlState.Normal);
detailDisclosureButton.SetImage(UIImage.FromBundle(extendedCell.DisclousureImage), UIControlState.Selected);
detailDisclosureButton.Frame = new CGRect(0f, 0f, 30f, 30f);
detailDisclosureButton.TouchUpInside += (sender, e) =>
{
var index = tv.IndexPathForCell(cell);
tv.SelectRow(index, true, UITableViewScrollPosition.None);
tv.Source.AccessoryButtonTapped(tv, index);
};
cell.AccessoryView = detailDisclosureButton;
}
}
}
return cell;
}
}
}

View file

@ -0,0 +1,25 @@
using Bit.App.Controls;
using Bit.iOS.Controls;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(ExtendedViewCell), typeof(ExtendedViewCellRenderer))]
namespace Bit.iOS.Controls
{
public class ExtendedViewCellRenderer : ViewCellRenderer
{
public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
{
var extendedCell = (ExtendedViewCell)item;
var cell = base.GetCell(item, reusableCell, tv);
if(cell != null)
{
cell.BackgroundColor = extendedCell.BackgroundColor.ToUIColor();
}
return cell;
}
}
}

View file

@ -102,6 +102,8 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Controls\ContentPageRenderer.cs" />
<Compile Include="Controls\ExtendedViewCellRenderer.cs" />
<Compile Include="Controls\ExtendedTextCellRenderer.cs" />
<Compile Include="Controls\ExtendedTableViewRenderer.cs" />
<Compile Include="Controls\ExtendedPickerRenderer.cs" />
<Compile Include="Controls\ExtendedEntryRenderer.cs" />