summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS
diff options
context:
space:
mode:
authorSamantha Houts <samantha@teamredwall.com>2016-06-17 03:10:18 -0700
committerRui Marinho <me@ruimarinho.net>2016-06-17 11:10:18 +0100
commit925fc0aa588a060eb23fa16c1d225dd030012c23 (patch)
tree83676c25c29d97d9250516b217020ba85425796d /Xamarin.Forms.Platform.iOS
parentd44396a4534b1e2bc81143c809e4adaee656ab15 (diff)
downloadxamarin-forms-925fc0aa588a060eb23fa16c1d225dd030012c23.tar.gz
xamarin-forms-925fc0aa588a060eb23fa16c1d225dd030012c23.tar.bz2
xamarin-forms-925fc0aa588a060eb23fa16c1d225dd030012c23.zip
Prep Cell & friends for removal of InternalsVisibleTo (#142)
* Prep Cell & friends for removal of InternalsVisibleTo Includes: - Cell - EntryCell - ListView - MenuItem - TableView - ViewCell - Toolbar Moved extensions to Internal & removed TPH * Update docs * [Controls] Ignore Issue2411 on iOS <9 * [Controls] Formatting for Issue2411
Diffstat (limited to 'Xamarin.Forms.Platform.iOS')
-rw-r--r--Xamarin.Forms.Platform.iOS/Cells/CellRenderer.cs7
-rw-r--r--Xamarin.Forms.Platform.iOS/Cells/CellTableViewCell.cs14
-rw-r--r--Xamarin.Forms.Platform.iOS/Cells/EntryCellRenderer.cs2
-rw-r--r--Xamarin.Forms.Platform.iOS/Cells/ImageCellRenderer.cs1
-rw-r--r--Xamarin.Forms.Platform.iOS/Cells/ViewCellRenderer.cs12
-rw-r--r--Xamarin.Forms.Platform.iOS/ContextActionCell.cs16
-rw-r--r--Xamarin.Forms.Platform.iOS/Extensions/CellExtensions.cs9
-rw-r--r--Xamarin.Forms.Platform.iOS/Extensions/ToolbarItemExtensions.cs15
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/CarouselPageRenderer.cs1
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs128
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs1
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs1
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/TableViewModelRenderer.cs23
13 files changed, 133 insertions, 97 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Cells/CellRenderer.cs b/Xamarin.Forms.Platform.iOS/Cells/CellRenderer.cs
index c01a7774..3ec12bd8 100644
--- a/Xamarin.Forms.Platform.iOS/Cells/CellRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Cells/CellRenderer.cs
@@ -1,4 +1,5 @@
using System;
+using Xamarin.Forms.Internals;
#if __UNIFIED__
using UIKit;
using Foundation;
@@ -32,7 +33,7 @@ namespace Xamarin.Forms.Platform.iOS
protected void UpdateBackground(UITableViewCell tableViewCell, Cell cell)
{
- if (TemplatedItemsList<ItemsView<Cell>, Cell>.GetIsGroupHeader(cell))
+ if (cell.GetIsGroupHeader<ItemsView<Cell>, Cell>())
{
if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
tableViewCell.BackgroundColor = new UIColor(247f / 255f, 247f / 255f, 247f / 255f, 1);
@@ -50,11 +51,11 @@ namespace Xamarin.Forms.Platform.iOS
}
}
- protected void WireUpForceUpdateSizeRequested(Cell cell, UITableViewCell nativeCell, UITableView tableView)
+ protected void WireUpForceUpdateSizeRequested(ICellController cell, UITableViewCell nativeCell, UITableView tableView)
{
cell.ForceUpdateSizeRequested -= _onForceUpdateSizeRequested;
- _onForceUpdateSizeRequested = delegate
+ _onForceUpdateSizeRequested = (sender, e) =>
{
var index = tableView.IndexPathForCell(nativeCell);
if (index != null)
diff --git a/Xamarin.Forms.Platform.iOS/Cells/CellTableViewCell.cs b/Xamarin.Forms.Platform.iOS/Cells/CellTableViewCell.cs
index a9265868..f1a53917 100644
--- a/Xamarin.Forms.Platform.iOS/Cells/CellTableViewCell.cs
+++ b/Xamarin.Forms.Platform.iOS/Cells/CellTableViewCell.cs
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
+using Xamarin.Forms.Internals;
#if __UNIFIED__
using UIKit;
@@ -27,11 +28,16 @@ namespace Xamarin.Forms.Platform.iOS
if (_cell == value)
return;
- if (_cell != null)
- Device.BeginInvokeOnMainThread(_cell.SendDisappearing);
+ ICellController cellController = _cell;
+
+ if (cellController != null)
+ Device.BeginInvokeOnMainThread(cellController.SendDisappearing);
+
_cell = value;
- if (_cell != null)
- Device.BeginInvokeOnMainThread(_cell.SendAppearing);
+ cellController = value;
+
+ if (cellController != null)
+ Device.BeginInvokeOnMainThread(cellController.SendAppearing);
}
}
diff --git a/Xamarin.Forms.Platform.iOS/Cells/EntryCellRenderer.cs b/Xamarin.Forms.Platform.iOS/Cells/EntryCellRenderer.cs
index 1af49b4a..e94e0ea5 100644
--- a/Xamarin.Forms.Platform.iOS/Cells/EntryCellRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Cells/EntryCellRenderer.cs
@@ -82,7 +82,7 @@ namespace Xamarin.Forms.Platform.iOS
static void OnKeyBoardDoneButtonPressed(object sender, EventArgs e)
{
var cell = (EntryCellTableViewCell)sender;
- var model = (EntryCell)cell.Cell;
+ var model = (IEntryCellController)cell.Cell;
model.SendCompleted();
}
diff --git a/Xamarin.Forms.Platform.iOS/Cells/ImageCellRenderer.cs b/Xamarin.Forms.Platform.iOS/Cells/ImageCellRenderer.cs
index ade59e82..010319ba 100644
--- a/Xamarin.Forms.Platform.iOS/Cells/ImageCellRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Cells/ImageCellRenderer.cs
@@ -1,5 +1,6 @@
using System.ComponentModel;
using System.Threading.Tasks;
+using Xamarin.Forms.Internals;
#if __UNIFIED__
using UIKit;
using Foundation;
diff --git a/Xamarin.Forms.Platform.iOS/Cells/ViewCellRenderer.cs b/Xamarin.Forms.Platform.iOS/Cells/ViewCellRenderer.cs
index 9493c8fb..f1cb2fb6 100644
--- a/Xamarin.Forms.Platform.iOS/Cells/ViewCellRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Cells/ViewCellRenderer.cs
@@ -1,6 +1,7 @@
using System;
using System.ComponentModel;
-using System.Diagnostics;
+using Xamarin.Forms.Internals;
+
#if __UNIFIED__
using UIKit;
#else
@@ -145,11 +146,14 @@ namespace Xamarin.Forms.Platform.iOS
void UpdateCell(ViewCell cell)
{
- if (_viewCell != null)
- Device.BeginInvokeOnMainThread(_viewCell.SendDisappearing);
+ ICellController cellController = _viewCell;
+ if (cellController != null)
+ Device.BeginInvokeOnMainThread(cellController.SendDisappearing);
_viewCell = cell;
- Device.BeginInvokeOnMainThread(_viewCell.SendAppearing);
+ cellController = cell;
+
+ Device.BeginInvokeOnMainThread(cellController.SendAppearing);
IVisualElementRenderer renderer;
if (_rendererRef == null || !_rendererRef.TryGetTarget(out renderer))
diff --git a/Xamarin.Forms.Platform.iOS/ContextActionCell.cs b/Xamarin.Forms.Platform.iOS/ContextActionCell.cs
index a2409c62..5d50d31d 100644
--- a/Xamarin.Forms.Platform.iOS/ContextActionCell.cs
+++ b/Xamarin.Forms.Platform.iOS/ContextActionCell.cs
@@ -131,7 +131,7 @@ namespace Xamarin.Forms.Platform.iOS
public void Update(UITableView tableView, Cell cell, UITableViewCell nativeCell)
{
- var parentListView = cell.RealParent as ListView;
+ var parentListView = cell.RealParent as IListViewController;
var recycling = parentListView != null && parentListView.CachingStrategy == ListViewCachingStrategy.RecycleElement;
if (_cell != cell && recycling)
{
@@ -342,7 +342,7 @@ namespace Xamarin.Forms.Platform.iOS
_scroller.SetContentOffset(new PointF(0, 0), true);
MenuItem mi;
if (weakItem.TryGetTarget(out mi))
- mi.Activate();
+ ((IMenuItemController)mi).Activate();
});
actionSheet.AddAction(action);
}
@@ -419,7 +419,7 @@ namespace Xamarin.Forms.Platform.iOS
button.SetTitle(item.Text, UIControlState.Normal);
button.TitleEdgeInsets = new UIEdgeInsets(0, 15, 0, 15);
- button.Enabled = item.IsEnabled;
+ button.Enabled = ((IMenuItemController)item).IsEnabled;
return button;
}
@@ -460,7 +460,7 @@ namespace Xamarin.Forms.Platform.iOS
else
{
_scroller.SetContentOffset(new PointF(0, 0), true);
- _cell.ContextActions[(int)button.Tag].Activate();
+ ((IMenuItemController)_cell.ContextActions[(int)button.Tag]).Activate();
}
}
@@ -468,7 +468,7 @@ namespace Xamarin.Forms.Platform.iOS
{
if (e.PropertyName == "HasContextActions")
{
- var parentListView = _cell.RealParent as ListView;
+ var parentListView = _cell.RealParent as IListViewController;
var recycling = parentListView != null && parentListView.CachingStrategy == ListViewCachingStrategy.RecycleElement;
if (!recycling)
ReloadRow();
@@ -477,7 +477,7 @@ namespace Xamarin.Forms.Platform.iOS
void OnContextItemsChanged(object sender, NotifyCollectionChangedEventArgs e)
{
- var parentListView = _cell.RealParent as ListView;
+ var parentListView = _cell.RealParent as IListViewController;
var recycling = parentListView != null && parentListView.CachingStrategy == ListViewCachingStrategy.RecycleElement;
if (recycling)
Update(_tableView, _cell, ContentCell);
@@ -488,7 +488,7 @@ namespace Xamarin.Forms.Platform.iOS
void OnMenuItemPropertyChanged(object sender, PropertyChangedEventArgs e)
{
- var parentListView = _cell.RealParent as ListView;
+ var parentListView = _cell.RealParent as IListViewController;
var recycling = parentListView != null && parentListView.CachingStrategy == ListViewCachingStrategy.RecycleElement;
if (recycling)
Update(_tableView, _cell, ContentCell);
@@ -708,7 +708,7 @@ namespace Xamarin.Forms.Platform.iOS
// do not activate a -1 index when dismissing by clicking outside the popover
if (buttonIndex >= 0)
- Items[(int)buttonIndex].Activate();
+ ((IMenuItemController)Items[(int)buttonIndex]).Activate();
}
}
}
diff --git a/Xamarin.Forms.Platform.iOS/Extensions/CellExtensions.cs b/Xamarin.Forms.Platform.iOS/Extensions/CellExtensions.cs
index ca05bc54..7243456b 100644
--- a/Xamarin.Forms.Platform.iOS/Extensions/CellExtensions.cs
+++ b/Xamarin.Forms.Platform.iOS/Extensions/CellExtensions.cs
@@ -1,4 +1,5 @@
using System;
+using Xamarin.Forms.Internals;
#if __UNIFIED__
using Foundation;
@@ -20,16 +21,16 @@ namespace Xamarin.Forms.Platform.iOS
if (self.RealParent is ListView)
{
var section = 0;
- var til = TemplatedItemsList<ItemsView<Cell>, Cell>.GetGroup(self);
+ var til = self.GetGroup<ItemsView<Cell>, Cell>();
if (til != null)
- section = TemplatedItemsList<ItemsView<Cell>, Cell>.GetIndex(til.HeaderContent);
+ section = til.HeaderContent.GetIndex<ItemsView<Cell>, Cell>();
- var row = TemplatedItemsList<ItemsView<Cell>, Cell>.GetIndex(self);
+ var row = self.GetIndex<ItemsView<Cell>, Cell>();
path = NSIndexPath.FromRowSection(row, section);
}
else if (self.RealParent is TableView)
{
- var tmPath = TableView.TableSectionModel.GetPath(self);
+ var tmPath = self.GetPath();
path = NSIndexPath.FromRowSection(tmPath.Item2, tmPath.Item1);
}
else
diff --git a/Xamarin.Forms.Platform.iOS/Extensions/ToolbarItemExtensions.cs b/Xamarin.Forms.Platform.iOS/Extensions/ToolbarItemExtensions.cs
index 71bdbbac..3ee09643 100644
--- a/Xamarin.Forms.Platform.iOS/Extensions/ToolbarItemExtensions.cs
+++ b/Xamarin.Forms.Platform.iOS/Extensions/ToolbarItemExtensions.cs
@@ -33,6 +33,8 @@ namespace Xamarin.Forms.Platform.iOS
readonly bool _forceName;
readonly ToolbarItem _item;
+ IMenuItemController Controller => _item;
+
public PrimaryToolbarItem(ToolbarItem item, bool forceName)
{
_forceName = forceName;
@@ -44,7 +46,7 @@ namespace Xamarin.Forms.Platform.iOS
UpdateTextAndStyle();
UpdateIsEnabled();
- Clicked += (sender, e) => item.Activate();
+ Clicked += (sender, e) => Controller.Activate();
item.PropertyChanged += OnPropertyChanged;
if (item != null && !string.IsNullOrEmpty(item.AutomationId))
@@ -60,7 +62,7 @@ namespace Xamarin.Forms.Platform.iOS
void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
- if (e.PropertyName == MenuItem.IsEnabledProperty.PropertyName)
+ if (e.PropertyName == Controller.IsEnabledPropertyName)
UpdateIsEnabled();
else if (e.PropertyName == MenuItem.TextProperty.PropertyName)
{
@@ -88,7 +90,7 @@ namespace Xamarin.Forms.Platform.iOS
void UpdateIsEnabled()
{
- Enabled = _item.IsEnabled;
+ Enabled = Controller.IsEnabled;
}
void UpdateTextAndStyle()
@@ -102,6 +104,7 @@ namespace Xamarin.Forms.Platform.iOS
sealed class SecondaryToolbarItem : UIBarButtonItem
{
readonly ToolbarItem _item;
+ IMenuItemController Controller => _item;
public SecondaryToolbarItem(ToolbarItem item) : base(new SecondaryToolbarItemContent())
{
@@ -110,7 +113,7 @@ namespace Xamarin.Forms.Platform.iOS
UpdateIcon();
UpdateIsEnabled();
- ((SecondaryToolbarItemContent)CustomView).TouchUpInside += (sender, e) => item.Activate();
+ ((SecondaryToolbarItemContent)CustomView).TouchUpInside += (sender, e) => Controller.Activate();
item.PropertyChanged += OnPropertyChanged;
if (item != null && !string.IsNullOrEmpty(item.AutomationId))
@@ -130,7 +133,7 @@ namespace Xamarin.Forms.Platform.iOS
UpdateText();
else if (e.PropertyName == MenuItem.IconProperty.PropertyName)
UpdateIcon();
- else if (e.PropertyName == MenuItem.IsEnabledProperty.PropertyName)
+ else if (e.PropertyName == Controller.IsEnabledPropertyName)
UpdateIsEnabled();
}
@@ -141,7 +144,7 @@ namespace Xamarin.Forms.Platform.iOS
void UpdateIsEnabled()
{
- ((UIControl)CustomView).Enabled = _item.IsEnabled;
+ ((UIControl)CustomView).Enabled = Controller.IsEnabled;
}
void UpdateText()
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/CarouselPageRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/CarouselPageRenderer.cs
index 6e7c6b2a..49921313 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/CarouselPageRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/CarouselPageRenderer.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Drawing;
+using Xamarin.Forms.Internals;
#if __UNIFIED__
using UIKit;
#else
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs
index 80fcf53f..238759e9 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs
@@ -5,6 +5,7 @@ using System.Collections.Specialized;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
+using Xamarin.Forms.Internals;
#if __UNIFIED__
using UIKit;
using Foundation;
@@ -38,6 +39,8 @@ namespace Xamarin.Forms.Platform.iOS
ScrollToRequestedEventArgs _requestedScroll;
bool _shouldEstimateRowHeight = true;
FormsUITableViewController _tableViewController;
+ IListViewController Controller => Element;
+ ITemplatedItemsView<Cell> TemplatedItemsView => Element;
public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
{
@@ -123,8 +126,9 @@ namespace Xamarin.Forms.Platform.iOS
if (Element != null)
{
- Element.TemplatedItems.CollectionChanged -= OnCollectionChanged;
- Element.TemplatedItems.GroupedCollectionChanged -= OnGroupedCollectionChanged;
+ var templatedItems = TemplatedItemsView.TemplatedItems;
+ templatedItems.CollectionChanged -= OnCollectionChanged;
+ templatedItems.GroupedCollectionChanged -= OnGroupedCollectionChanged;
}
if (_tableViewController != null)
@@ -151,14 +155,12 @@ namespace Xamarin.Forms.Platform.iOS
_footerRenderer = null;
}
- var controller = Element as IListViewController;
-
- var headerView = controller?.HeaderElement as VisualElement;
+ var headerView = Controller?.HeaderElement as VisualElement;
if (headerView != null)
headerView.MeasureInvalidated -= OnHeaderMeasureInvalidated;
Control?.TableHeaderView?.Dispose();
- var footerView = controller?.FooterElement as VisualElement;
+ var footerView = Controller?.FooterElement as VisualElement;
if (footerView != null)
footerView.MeasureInvalidated -= OnFooterMeasureInvalidated;
Control?.TableFooterView?.Dispose();
@@ -182,9 +184,11 @@ namespace Xamarin.Forms.Platform.iOS
if (footerView != null)
footerView.MeasureInvalidated -= OnFooterMeasureInvalidated;
- e.OldElement.ScrollToRequested -= OnScrollToRequested;
- e.OldElement.TemplatedItems.CollectionChanged -= OnCollectionChanged;
- e.OldElement.TemplatedItems.GroupedCollectionChanged -= OnGroupedCollectionChanged;
+ controller.ScrollToRequested -= OnScrollToRequested;
+ var templatedItems = ((ITemplatedItemsView<Cell>)e.OldElement).TemplatedItems;
+
+ templatedItems.CollectionChanged -= OnCollectionChanged;
+ templatedItems.GroupedCollectionChanged -= OnGroupedCollectionChanged;
}
if (e.NewElement != null)
@@ -204,14 +208,14 @@ namespace Xamarin.Forms.Platform.iOS
});
}
_shouldEstimateRowHeight = true;
- //if the user specifies he wants to sacrifice performance we will do things like:
- // - don't EstimateRowHeight anymore
- if (e.NewElement.TakePerformanceHit)
- _shouldEstimateRowHeight = false;
- e.NewElement.ScrollToRequested += OnScrollToRequested;
- e.NewElement.TemplatedItems.CollectionChanged += OnCollectionChanged;
- e.NewElement.TemplatedItems.GroupedCollectionChanged += OnGroupedCollectionChanged;
+ var controller = (IListViewController)e.NewElement;
+
+ controller.ScrollToRequested += OnScrollToRequested;
+ var templatedItems = ((ITemplatedItemsView<Cell>)e.NewElement).TemplatedItems;
+
+ templatedItems.CollectionChanged += OnCollectionChanged;
+ templatedItems.GroupedCollectionChanged += OnGroupedCollectionChanged;
UpdateRowHeight();
@@ -306,9 +310,10 @@ namespace Xamarin.Forms.Platform.iOS
void OnGroupedCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
- var til = (TemplatedItemsList<ItemsView<Cell>, Cell>)sender;
+ var til = (ITemplatedItemsList<Cell>)sender;
- var groupIndex = Element.TemplatedItems.IndexOf(til.HeaderContent);
+ var templatedItems = TemplatedItemsView.TemplatedItems;
+ var groupIndex = templatedItems.IndexOf(til.HeaderContent);
UpdateItems(e, groupIndex, false);
}
@@ -334,16 +339,17 @@ namespace Xamarin.Forms.Platform.iOS
}
var position = GetScrollPosition(e.Position);
-
+ var scrollArgs = (ITemplatedItemsListScrollToRequestedEventArgs)e;
+ var templatedItems = TemplatedItemsView.TemplatedItems;
if (Element.IsGroupingEnabled)
{
- var result = Element.TemplatedItems.GetGroupAndIndexOfItem(e.Group, e.Item);
+ var result = templatedItems.GetGroupAndIndexOfItem(scrollArgs.Group, scrollArgs.Item);
if (result.Item1 != -1 && result.Item2 != -1)
Control.ScrollToRow(NSIndexPath.FromRowSection(result.Item2, result.Item1), position, e.ShouldAnimate);
}
else
{
- var index = Element.TemplatedItems.GetGlobalIndexOfItem(e.Item);
+ var index = templatedItems.GetGlobalIndexOfItem(scrollArgs.Item);
if (index != -1)
Control.ScrollToRow(NSIndexPath.FromRowSection(index, 0), position, e.ShouldAnimate);
}
@@ -360,16 +366,17 @@ namespace Xamarin.Forms.Platform.iOS
var source = _dataSource as UnevenListViewDataSource;
if (_shouldEstimateRowHeight)
{
- if (Element.TemplatedItems.Count > 0 && source != null)
+ var templatedItems = TemplatedItemsView.TemplatedItems;
+ if (templatedItems.Count > 0 && source != null)
{
- var estimatedHeightFromFirstCell = source.CalculateHeightForCell(Control, Element.TemplatedItems.First());
+ var estimatedHeightFromFirstCell = source.CalculateHeightForCell(Control, templatedItems.First());
Control.EstimatedRowHeight = estimatedHeightFromFirstCell;
_estimatedRowHeight = true;
}
else
{
//We need to set a default estimated row height, because re-setting it later(when we have items on the TIL)
- //will cause the UITableView to reload, and throw a Excepetion
+ //will cause the UITableView to reload, and throw an Exception
Control.EstimatedRowHeight = DefaultRowHeight;
}
}
@@ -384,7 +391,7 @@ namespace Xamarin.Forms.Platform.iOS
void UpdateFooter()
{
- var footer = ((IListViewController)Element).FooterElement;
+ var footer = Controller.FooterElement;
var footerView = (View)footer;
if (footerView != null)
@@ -428,7 +435,7 @@ namespace Xamarin.Forms.Platform.iOS
void UpdateHeader()
{
- var header = ((IListViewController)Element).HeaderElement;
+ var header = Controller.HeaderElement;
var headerView = (View)header;
if (headerView != null)
@@ -506,7 +513,7 @@ namespace Xamarin.Forms.Platform.iOS
Control.EndUpdates();
- if (_estimatedRowHeight && Element.TemplatedItems.Count == 0)
+ if (_estimatedRowHeight && TemplatedItemsView.TemplatedItems.Count == 0)
_estimatedRowHeight = false;
break;
@@ -558,7 +565,7 @@ namespace Xamarin.Forms.Platform.iOS
{
if (_tableViewController != null)
{
- var isPullToRequestEnabled = Element.IsPullToRefreshEnabled && (Element as IListViewController).RefreshAllowed;
+ var isPullToRequestEnabled = Element.IsPullToRefreshEnabled && Controller.RefreshAllowed;
_tableViewController.UpdatePullToRefreshEnabled(isPullToRequestEnabled);
}
}
@@ -667,6 +674,8 @@ namespace Xamarin.Forms.Platform.iOS
readonly UITableView _uiTableView;
readonly FormsUITableViewController _uiTableViewController;
protected readonly ListView List;
+ IListViewController Controller => List;
+ ITemplatedItemsView<Cell> TemplatedItemsView => List;
bool _isDragging;
bool _selectionFromNative;
@@ -715,7 +724,7 @@ namespace Xamarin.Forms.Platform.iOS
{
UITableViewCell nativeCell = null;
- var cachingStrategy = List.CachingStrategy;
+ var cachingStrategy = Controller.CachingStrategy;
if (cachingStrategy == ListViewCachingStrategy.RetainElement)
{
var cell = GetCellForPath(indexPath);
@@ -732,11 +741,12 @@ namespace Xamarin.Forms.Platform.iOS
}
else
{
- var templatedList = List.TemplatedItems.GetGroup(indexPath.Section);
+ var templatedList = TemplatedItemsView.TemplatedItems.GetGroup(indexPath.Section);
var cell = (Cell)((INativeElementView)nativeCell).Element;
- cell.SendDisappearing();
+ ICellController controller = cell;
+ controller.SendDisappearing();
templatedList.UpdateContent(cell, indexPath.Row);
- cell.SendAppearing();
+ controller.SendAppearing();
}
}
else
@@ -753,7 +763,7 @@ namespace Xamarin.Forms.Platform.iOS
{
if (List.IsGroupingEnabled)
{
- var cell = List.TemplatedItems[(int)section];
+ var cell = TemplatedItemsView.TemplatedItems[(int)section];
nfloat height = (float)cell.RenderHeight;
if (height == -1)
height = _defaultSectionHeight;
@@ -768,7 +778,7 @@ namespace Xamarin.Forms.Platform.iOS
{
if (List.IsGroupingEnabled && List.GroupHeaderTemplate != null)
{
- var cell = List.TemplatedItems[(int)section];
+ var cell = TemplatedItemsView.TemplatedItems[(int)section];
if (cell.HasContextActions)
throw new NotSupportedException("Header cells do not support context actions");
@@ -786,7 +796,7 @@ namespace Xamarin.Forms.Platform.iOS
public override nint NumberOfSections(UITableView tableView)
{
if (List.IsGroupingEnabled)
- return List.TemplatedItems.Count;
+ return TemplatedItemsView.TemplatedItems.Count;
return 1;
}
@@ -799,7 +809,7 @@ namespace Xamarin.Forms.Platform.iOS
return;
}
- var location = List.TemplatedItems.GetGroupAndIndexOfItem(eventArg.SelectedItem);
+ var location = TemplatedItemsView.TemplatedItems.GetGroupAndIndexOfItem(eventArg.SelectedItem);
if (location.Item1 == -1 || location.Item2 == -1)
{
var selectedIndexPath = _uiTableView.IndexPathForSelectedRow;
@@ -842,7 +852,7 @@ namespace Xamarin.Forms.Platform.iOS
return;
Cell formsCell = null;
- if (List.CachingStrategy == ListViewCachingStrategy.RecycleElement)
+ if (Controller.CachingStrategy == ListViewCachingStrategy.RecycleElement)
formsCell = (Cell)((INativeElementView)cell).Element;
SetCellBackgroundColor(cell, UIColor.Clear);
@@ -850,7 +860,7 @@ namespace Xamarin.Forms.Platform.iOS
_selectionFromNative = true;
tableView.EndEditing(true);
- List.NotifyRowTapped(indexPath.Section, indexPath.Row, formsCell);
+ Controller.NotifyRowTapped(indexPath.Section, indexPath.Row, formsCell);
}
public override nint RowsInSection(UITableView tableview, nint section)
@@ -862,13 +872,14 @@ namespace Xamarin.Forms.Platform.iOS
return countOverride;
}
+ var templatedItems = TemplatedItemsView.TemplatedItems;
if (List.IsGroupingEnabled)
{
- var group = (IList)((IList)List.TemplatedItems)[(int)section];
+ var group = (IList)((IList)templatedItems)[(int)section];
return group.Count;
}
- return List.TemplatedItems.Count;
+ return templatedItems.Count;
}
public override void Scrolled(UIScrollView scrollView)
@@ -879,10 +890,11 @@ namespace Xamarin.Forms.Platform.iOS
public override string[] SectionIndexTitles(UITableView tableView)
{
- if (List.TemplatedItems.ShortNames == null)
+ var templatedItems = TemplatedItemsView.TemplatedItems;
+ if (templatedItems.ShortNames == null)
return null;
- return List.TemplatedItems.ShortNames.ToArray();
+ return templatedItems.ShortNames.ToArray();
}
public override string TitleForHeader(UITableView tableView, nint section)
@@ -905,25 +917,25 @@ namespace Xamarin.Forms.Platform.iOS
protected Cell GetCellForPath(NSIndexPath indexPath)
{
- var templatedList = List.TemplatedItems;
+ var templatedItems = TemplatedItemsView.TemplatedItems;
if (List.IsGroupingEnabled)
- templatedList = (TemplatedItemsList<ItemsView<Cell>, Cell>)((IList)templatedList)[indexPath.Section];
+ templatedItems = (ITemplatedItemsList<Cell>)((IList)templatedItems)[indexPath.Section];
- var cell = templatedList[indexPath.Row];
+ var cell = templatedItems[indexPath.Row];
return cell;
}
- TemplatedItemsList<ItemsView<Cell>, Cell> GetSectionList(int section)
+ ITemplatedItemsList<Cell> GetSectionList(int section)
{
- return (TemplatedItemsList<ItemsView<Cell>, Cell>)((IList)List.TemplatedItems)[section];
+ return (ITemplatedItemsList<Cell>)((IList)TemplatedItemsView.TemplatedItems) [section];
}
void OnSectionPropertyChanged(object sender, PropertyChangedEventArgs e)
{
var currentSelected = _uiTableView.IndexPathForSelectedRow;
- var til = (TemplatedItemsList<ItemsView<Cell>, Cell>)sender;
- var groupIndex = ((IList)List.TemplatedItems).IndexOf(til);
+ var til = (ITemplatedItemsView<Cell>)sender;
+ var groupIndex = ((IList)TemplatedItemsView.TemplatedItems).IndexOf(til);
if (groupIndex == -1)
{
til.PropertyChanged -= OnSectionPropertyChanged;
@@ -954,11 +966,11 @@ namespace Xamarin.Forms.Platform.iOS
if (selector == null)
return DefaultItemTemplateId;
- var templatedList = List.TemplatedItems;
+ var templatedList = TemplatedItemsView.TemplatedItems;
if (List.IsGroupingEnabled)
- templatedList = (TemplatedItemsList<ItemsView<Cell>, Cell>)((IList)templatedList)[indexPath.Section];
+ templatedList = (ITemplatedItemsList<Cell>)((IList)templatedList)[indexPath.Section];
- var item = templatedList.ListProxy[indexPath.Row];
+ var item = ((ITemplatedItemsView<Cell>)templatedList).ListProxy[indexPath.Row];
itemTemplate = selector.SelectTemplate(item, List);
int key;
@@ -973,15 +985,16 @@ namespace Xamarin.Forms.Platform.iOS
void UpdateShortNameListener()
{
+ var templatedList = TemplatedItemsView.TemplatedItems;
if (List.IsGroupingEnabled)
{
- if (List.TemplatedItems.ShortNames != null)
- ((INotifyCollectionChanged)List.TemplatedItems.ShortNames).CollectionChanged += OnShortNamesCollectionChanged;
+ if (templatedList.ShortNames != null)
+ ((INotifyCollectionChanged)templatedList.ShortNames).CollectionChanged += OnShortNamesCollectionChanged;
}
else
{
- if (List.TemplatedItems.ShortNames != null)
- ((INotifyCollectionChanged)List.TemplatedItems.ShortNames).CollectionChanged -= OnShortNamesCollectionChanged;
+ if (templatedList.ShortNames != null)
+ ((INotifyCollectionChanged)templatedList.ShortNames).CollectionChanged -= OnShortNamesCollectionChanged;
}
}
}
@@ -1000,6 +1013,7 @@ namespace Xamarin.Forms.Platform.iOS
internal class FormsUITableViewController : UITableViewController
{
readonly ListView _list;
+ IListViewController Controller => _list;
UIRefreshControl _refresh;
bool _refreshAdded;
@@ -1101,7 +1115,7 @@ namespace Xamarin.Forms.Platform.iOS
void OnRefreshingChanged(object sender, EventArgs eventArgs)
{
if (_refresh.Refreshing)
- (_list as IListViewController).SendRefreshing();
+ Controller.SendRefreshing();
}
void RemoveRefresh()
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs
index d0798ed3..9f2c2666 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs
@@ -7,6 +7,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Xamarin.Forms.Internals;
+
#if __UNIFIED__
using UIKit;
using CoreGraphics;
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs
index 4ec16967..25fceb41 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs
@@ -3,6 +3,7 @@ using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Collections.Generic;
+using Xamarin.Forms.Internals;
#if __UNIFIED__
using UIKit;
#else
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/TableViewModelRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/TableViewModelRenderer.cs
index dcb943bf..cc70a5f1 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/TableViewModelRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/TableViewModelRenderer.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Xamarin.Forms;
+using Xamarin.Forms.Internals;
#if __UNIFIED__
using UIKit;
using Foundation;
@@ -25,6 +26,8 @@ namespace Xamarin.Forms.Platform.iOS
{
readonly Dictionary<nint, Cell> _headerCells = new Dictionary<nint, Cell>();
+ protected ITableViewController Controller => View;
+
protected bool HasBoundGestures;
protected UITableView Table;
@@ -33,7 +36,7 @@ namespace Xamarin.Forms.Platform.iOS
public TableViewModelRenderer(TableView model)
{
View = model;
- View.ModelChanged += (s, e) =>
+ Controller.ModelChanged += (s, e) =>
{
if (Table != null)
Table.ReloadData();
@@ -45,7 +48,7 @@ namespace Xamarin.Forms.Platform.iOS
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
- var cell = View.Model.GetCell(indexPath.Section, indexPath.Row);
+ var cell = Controller.Model.GetCell(indexPath.Section, indexPath.Row);
var nativeCell = CellTableViewCell.GetNativeCell(tableView, cell);
return nativeCell;
@@ -54,7 +57,7 @@ namespace Xamarin.Forms.Platform.iOS
public override nfloat GetHeightForHeader(UITableView tableView, nint section)
{
if (!_headerCells.ContainsKey((int)section))
- _headerCells[section] = View.Model.GetHeaderCell((int)section);
+ _headerCells[section] = Controller.Model.GetHeaderCell((int)section);
var result = _headerCells[section];
@@ -64,7 +67,7 @@ namespace Xamarin.Forms.Platform.iOS
public override UIView GetViewForHeader(UITableView tableView, nint section)
{
if (!_headerCells.ContainsKey((int)section))
- _headerCells[section] = View.Model.GetHeaderCell((int)section);
+ _headerCells[section] = Controller.Model.GetHeaderCell((int)section);
var result = _headerCells[section];
@@ -85,35 +88,35 @@ namespace Xamarin.Forms.Platform.iOS
if (indexPath == null)
return;
- View.Model.RowLongPressed(indexPath.Section, indexPath.Row);
+ Controller.Model.RowLongPressed(indexPath.Section, indexPath.Row);
}
public override nint NumberOfSections(UITableView tableView)
{
BindGestures(tableView);
- return View.Model.GetSectionCount();
+ return Controller.Model.GetSectionCount();
}
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
- View.Model.RowSelected(indexPath.Section, indexPath.Row);
+ Controller.Model.RowSelected(indexPath.Section, indexPath.Row);
if (AutomaticallyDeselect)
tableView.DeselectRow(indexPath, true);
}
public override nint RowsInSection(UITableView tableview, nint section)
{
- return View.Model.GetRowCount((int)section);
+ return Controller.Model.GetRowCount((int)section);
}
public override string[] SectionIndexTitles(UITableView tableView)
{
- return View.Model.GetSectionIndexTitles();
+ return Controller.Model.GetSectionIndexTitles();
}
public override string TitleForHeader(UITableView tableView, nint section)
{
- return View.Model.GetSectionTitle((int)section);
+ return Controller.Model.GetSectionTitle((int)section);
}
void BindGestures(UITableView tableview)