UpdateTabBarItem();
}
+ protected virtual IShellSectionRootRenderer CreateShellSectionRootRenderer(ShellSection shellSection, IShellContext shellContext)
+ {
+ return new ShellSectionRootRenderer(shellSection, shellContext);
+ }
+
protected virtual void LoadPages()
{
- _renderer = new ShellSectionRootRenderer(ShellSection, _context);
+ _renderer = CreateShellSectionRootRenderer(ShellSection, _context);
PushViewController(_renderer.ViewController, false);
-
+
var stack = ShellSection.Stack;
for (int i = 1; i < stack.Count; i++)
{
namespace Xamarin.Forms.Platform.iOS
{
- public class ShellSectionRootHeader : UICollectionViewController, IAppearanceObserver
+ public class ShellSectionRootHeader : UICollectionViewController, IAppearanceObserver, IShellSectionRootHeader
{
#region IAppearanceObserver
public double SelectedIndex { get; set; }
public ShellSection ShellSection { get; set; }
+ public UIViewController ViewController => this;
+
public override bool CanMoveItem(UICollectionView collectionView, NSIndexPath indexPath)
{
return false;
public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
{
- var headerCell = (ShellSectionHeaderCell)collectionView.DequeueReusableCell(CellId, indexPath);
+ var reusedCell = (UICollectionViewCell)collectionView.DequeueReusableCell(CellId, indexPath);
+ var headerCell = reusedCell as ShellSectionHeaderCell;
+
+ if (headerCell == null)
+ return reusedCell;
var selectedItems = collectionView.GetIndexPathsForSelectedItems();
public override void ItemDeselected(UICollectionView collectionView, NSIndexPath indexPath)
{
- var cell = (ShellSectionHeaderCell)CollectionView.CellForItem(indexPath);
- cell.Label.TextColor = _unselectedColor.ToUIColor();
+ if(CollectionView.CellForItem(indexPath) is ShellSectionHeaderCell cell)
+ cell.Label.TextColor = _unselectedColor.ToUIColor();
}
public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath)
if (item != ShellSection.CurrentItem)
ShellSection.SetValueFromRenderer(ShellSection.CurrentItemProperty, item);
- var cell = (ShellSectionHeaderCell)CollectionView.CellForItem(indexPath);
- cell.Label.TextColor = _selectedColor.ToUIColor();
+ if (CollectionView.CellForItem(indexPath) is ShellSectionHeaderCell cell)
+ cell.Label.TextColor = _selectedColor.ToUIColor();
}
public override nint NumberOfSections(UICollectionView collectionView)
flowLayout.MinimumLineSpacing = 0;
flowLayout.EstimatedItemSize = new CGSize(70, 35);
- CollectionView.RegisterClassForCell(typeof(ShellSectionHeaderCell), CellId);
+ CollectionView.RegisterClassForCell(GetCellType(), CellId);
((IShellController)_shellContext.Shell).AddAppearanceObserver(this, ShellSection);
((INotifyCollectionChanged)ShellSection.Items).CollectionChanged += OnShellSectionItemsChanged;
ShellSection.PropertyChanged += OnShellSectionPropertyChanged;
}
+ protected virtual Type GetCellType()
+ {
+ return typeof(ShellSectionHeaderCell);
+ }
+
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
UIView _blurView;
UIView _containerArea;
int _currentIndex;
- ShellSectionRootHeader _header;
+ IShellSectionRootHeader _header;
bool _isAnimating;
Dictionary<ShellContent, IVisualElementRenderer> _renderers = new Dictionary<ShellContent, IVisualElementRenderer>();
IShellPageRendererTracker _tracker;
}
}
+ protected virtual IShellSectionRootHeader CreateShellSectionRootHeader(IShellContext shellContext)
+ {
+ return new ShellSectionRootHeader(shellContext);
+ }
+
protected virtual void UpdateHeaderVisibility()
{
bool visible = ShellSection.Items.Count > 1;
{
if (_header == null)
{
- _header = new ShellSectionRootHeader(_shellContext);
+ _header = CreateShellSectionRootHeader(_shellContext);
_header.ShellSection = ShellSection;
- AddChildViewController(_header);
- View.AddSubview(_header.View);
+ AddChildViewController(_header.ViewController);
+ View.AddSubview(_header.ViewController.View);
}
_blurView.Hidden = false;
LayoutHeader();
{
if (_header != null)
{
- _header.View.RemoveFromSuperview();
- _header.RemoveFromParentViewController();
+ _header.ViewController.View.RemoveFromSuperview();
+ _header.ViewController.RemoveFromParentViewController();
_header.Dispose();
_header = null;
}
var headerTop = Forms.IsiOS11OrNewer ? View.SafeAreaInsets.Top : TopLayoutGuide.Length;
CGRect frame = new CGRect(View.Bounds.X, headerTop, View.Bounds.Width, HeaderHeight);
_blurView.Frame = frame;
- _header.View.Frame = frame;
+ _header.ViewController.View.Frame = frame;
}
nfloat left;