2016-05-12 07:09:06 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using Bit.App.Controls;
|
|
|
|
|
using Bit.iOS.Controls;
|
2016-07-04 09:45:32 +03:00
|
|
|
|
using CoreGraphics;
|
2016-07-05 05:31:15 +03:00
|
|
|
|
using Foundation;
|
2016-05-12 07:09:06 +03:00
|
|
|
|
using UIKit;
|
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
using Xamarin.Forms.Platform.iOS;
|
|
|
|
|
|
|
|
|
|
[assembly: ExportRenderer(typeof(ExtendedTableView), typeof(ExtendedTableViewRenderer))]
|
|
|
|
|
namespace Bit.iOS.Controls
|
|
|
|
|
{
|
|
|
|
|
public class ExtendedTableViewRenderer : TableViewRenderer
|
|
|
|
|
{
|
2016-07-06 02:07:56 +03:00
|
|
|
|
public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
|
|
|
|
|
{
|
|
|
|
|
Control.LayoutIfNeeded();
|
|
|
|
|
var size = new Size(Control.ContentSize.Width, Control.ContentSize.Height);
|
|
|
|
|
return new SizeRequest(size);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-12 07:09:06 +03:00
|
|
|
|
protected override void OnElementChanged(ElementChangedEventArgs<TableView> e)
|
|
|
|
|
{
|
|
|
|
|
base.OnElementChanged(e);
|
|
|
|
|
|
|
|
|
|
var view = e.NewElement as ExtendedTableView;
|
|
|
|
|
if(view != null)
|
|
|
|
|
{
|
2016-05-13 04:30:02 +03:00
|
|
|
|
SetScrolling(view);
|
|
|
|
|
SetSelection(view);
|
|
|
|
|
UpdateRowHeight(view);
|
|
|
|
|
UpdateEstimatedRowHeight(view);
|
2016-05-14 08:34:42 +03:00
|
|
|
|
UpdateSeparatorColor(view);
|
2016-07-05 05:31:15 +03:00
|
|
|
|
SetSource();
|
2016-05-12 07:09:06 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-05 05:31:15 +03:00
|
|
|
|
|
2016-05-12 07:09:06 +03:00
|
|
|
|
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnElementPropertyChanged(sender, e);
|
|
|
|
|
|
|
|
|
|
var view = (ExtendedTableView)Element;
|
|
|
|
|
|
2016-05-13 04:30:02 +03:00
|
|
|
|
if(e.PropertyName == ExtendedTableView.EnableScrollingProperty.PropertyName)
|
|
|
|
|
{
|
|
|
|
|
SetScrolling(view);
|
|
|
|
|
}
|
|
|
|
|
else if(e.PropertyName == ExtendedTableView.RowHeightProperty.PropertyName)
|
|
|
|
|
{
|
|
|
|
|
UpdateRowHeight(view);
|
|
|
|
|
}
|
|
|
|
|
else if(e.PropertyName == ExtendedTableView.EnableSelectionProperty.PropertyName)
|
|
|
|
|
{
|
|
|
|
|
SetSelection(view);
|
|
|
|
|
}
|
2016-07-05 05:31:15 +03:00
|
|
|
|
else if(e.PropertyName == TableView.HasUnevenRowsProperty.PropertyName)
|
|
|
|
|
{
|
|
|
|
|
SetSource();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetSource()
|
|
|
|
|
{
|
2016-07-05 05:53:13 +03:00
|
|
|
|
var view = (ExtendedTableView)Element;
|
|
|
|
|
if(view.NoFooter || view.NoHeader)
|
|
|
|
|
{
|
|
|
|
|
Control.Source = new CustomTableViewModelRenderer(view);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Control.Source = Element.HasUnevenRows ? new UnEvenTableViewModelRenderer(Element) : new TableViewModelRenderer(Element);
|
|
|
|
|
}
|
2016-05-12 07:09:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-13 04:30:02 +03:00
|
|
|
|
private void SetScrolling(ExtendedTableView view)
|
|
|
|
|
{
|
|
|
|
|
Control.ScrollEnabled = view.EnableScrolling;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetSelection(ExtendedTableView view)
|
|
|
|
|
{
|
|
|
|
|
Control.AllowsSelection = view.EnableSelection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateRowHeight(ExtendedTableView view)
|
|
|
|
|
{
|
|
|
|
|
var rowHeight = view.RowHeight;
|
|
|
|
|
if(view.HasUnevenRows && rowHeight == -1)
|
|
|
|
|
{
|
|
|
|
|
Control.RowHeight = UITableView.AutomaticDimension;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Control.RowHeight = rowHeight <= 0 ? 44 : rowHeight;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateEstimatedRowHeight(ExtendedTableView view)
|
|
|
|
|
{
|
|
|
|
|
if(view.HasUnevenRows && view.RowHeight == -1)
|
|
|
|
|
{
|
|
|
|
|
Control.EstimatedRowHeight = view.EstimatedRowHeight;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Control.EstimatedRowHeight = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-14 08:34:42 +03:00
|
|
|
|
|
|
|
|
|
private void UpdateSeparatorColor(ExtendedTableView view)
|
|
|
|
|
{
|
|
|
|
|
Control.SeparatorColor = view.SeparatorColor.ToUIColor(UIColor.Gray);
|
|
|
|
|
}
|
2016-07-05 05:31:15 +03:00
|
|
|
|
|
|
|
|
|
public class CustomTableViewModelRenderer : UnEvenTableViewModelRenderer
|
|
|
|
|
{
|
|
|
|
|
private readonly ExtendedTableView _view;
|
|
|
|
|
|
|
|
|
|
public CustomTableViewModelRenderer(ExtendedTableView model)
|
|
|
|
|
: base(model)
|
|
|
|
|
{
|
|
|
|
|
_view = model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
|
|
|
|
|
{
|
|
|
|
|
if(_view.HasUnevenRows)
|
|
|
|
|
{
|
|
|
|
|
return UITableView.AutomaticDimension;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.GetHeightForRow(tableView, indexPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override nfloat GetHeightForHeader(UITableView tableView, nint section)
|
|
|
|
|
{
|
2016-07-06 02:07:56 +03:00
|
|
|
|
if(_view.NoHeader && section == 0)
|
2016-07-05 05:31:15 +03:00
|
|
|
|
{
|
|
|
|
|
return 0.00001f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.GetHeightForHeader(tableView, section);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override nfloat GetHeightForFooter(UITableView tableView, nint section)
|
|
|
|
|
{
|
2016-07-06 02:07:56 +03:00
|
|
|
|
if(_view.NoFooter && (section + 1) == NumberOfSections(tableView))
|
2016-07-05 05:31:15 +03:00
|
|
|
|
{
|
|
|
|
|
return 0.00001f;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-29 07:13:35 +03:00
|
|
|
|
return 10f;
|
2016-07-05 05:31:15 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-12 07:09:06 +03:00
|
|
|
|
}
|
|
|
|
|
}
|