<ContentView>
<Button Visual="Material" ImageSource="{Binding FlyoutIcon}" Text="{Binding Text}" />
</ContentView>
- </DataTemplate>
- <DataTemplate x:Key="ShellItemTemplate">
+ </DataTemplate>
+ <DataTemplate x:Key="MenuItemTemplateWithHeight">
+ <StackLayout HeightRequest="200" BackgroundColor="Purple">
+ <Label Text="{Binding Text}"></Label>
+ <Label VerticalTextAlignment="End" VerticalOptions="EndAndExpand" Text="{Binding Text}"></Label>
+ </StackLayout>
+ </DataTemplate>
+ <DataTemplate x:Key="ShellItemTemplate">
<ContentView BackgroundColor="LightBlue">
<StackLayout Orientation="Horizontal">
<Image Source="{Binding FlyoutIcon}"/>
<ShellContent Route="sharednotab" Title="No Tabs" ContentTemplate="{DataTemplate local:UpdatesPage}" />
<ShellContent Route="Notificationstabs" Shell.TabBarIsVisible="true" Title="Yes Tabs" ContentTemplate="{DataTemplate local:LibraryPage}" />
</ShellSection>
- </ShellItem>
+ </ShellItem>
+ <MenuItem Shell.MenuItemTemplate="{StaticResource MenuItemTemplateWithHeight}" Text="Height 200"/>
</localTest:TestShell>
public ShellFlyoutContentRenderer(IShellContext context)
{
+ _shellContext = context;
+
var header = ((IShellController)context.Shell).FlyoutHeader;
if (header != null)
_headerView = new UIContainerView(((IShellController)context.Shell).FlyoutHeader);
- _tableViewController = new ShellTableViewController(context, _headerView, OnElementSelected);
+
+ _tableViewController = CreateShellTableViewController();
AddChildViewController(_tableViewController);
context.Shell.PropertyChanged += HandleShellPropertyChanged;
- _shellContext = context;
+ }
+
+ protected ShellTableViewController CreateShellTableViewController()
+ {
+ return new ShellTableViewController(_shellContext, _headerView, OnElementSelected);
}
protected virtual void HandleShellPropertyChanged(object sender, PropertyChangedEventArgs e)
((IShellController)_shellContext.Shell).OnFlyoutItemSelected(element);
}
}
-}
\ No newline at end of file
+}
double _headerOffset = 0;
double _headerSize;
bool _isDisposed;
+ Action<Element> _onElementSelected;
public ShellTableViewController(IShellContext context, UIContainerView headerView, Action<Element> onElementSelected)
{
_context = context;
+ _onElementSelected = onElementSelected;
_headerView = headerView;
- _source = new ShellTableViewSource(context, onElementSelected);
+ _source = CreateShellTableViewSource();
_source.ScrolledEvent += OnScrolled;
if (_headerView != null)
_headerView.HeaderSizeChanged += OnHeaderSizeChanged;
_context.Shell.PropertyChanged += OnShellPropertyChanged;
}
+ protected ShellTableViewSource CreateShellTableViewSource()
+ {
+ return new ShellTableViewSource(_context, _onElementSelected);
+ }
+
void OnShellPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == Shell.FlyoutHeaderBehaviorProperty.PropertyName)
switch (_context.Shell.FlyoutVerticalScrollMode)
{
case ScrollMode.Auto:
- var pathToFirstRow = Foundation.NSIndexPath.FromRowSection(0, 0);
- var firstCellRect = TableView.RectForRowAtIndexPath(pathToFirstRow);
- var firstCellIsVisible = TableView.Bounds.Contains(firstCellRect);
-
- var lastRowIndex = NMath.Max(0, TableView.NumberOfRowsInSection(0) - 1);
- var pathToLastRow = Foundation.NSIndexPath.FromRowSection(lastRowIndex, 0);
- var cellRect = TableView.RectForRowAtIndexPath(pathToLastRow);
- var lastCellIsVisible = TableView.Bounds.Contains(cellRect);
-
- TableView.ScrollEnabled = !firstCellIsVisible || !lastCellIsVisible;
+ TableView.ScrollEnabled = true;
+ TableView.AlwaysBounceVertical = false;
break;
case ScrollMode.Enabled:
TableView.ScrollEnabled = true;
+ TableView.AlwaysBounceVertical = true;
break;
case ScrollMode.Disabled:
TableView.ScrollEnabled = false;
+ TableView.AlwaysBounceVertical = false;
break;
}
}
_headerView.HeaderSizeChanged -= OnHeaderSizeChanged;
_context.Shell.PropertyChanged -= OnShellPropertyChanged;
+
+ _onElementSelected = null;
}
+
_isDisposed = true;
base.Dispose(disposing);
}
DataTemplate _defaultItemTemplate;
DataTemplate _defaultMenuItemTemplate;
List<List<Element>> _groups;
+ Dictionary<Element, View> _views;
public ShellTableViewSource(IShellContext context, Action<Element> onElementSelected)
{
if (_groups == null)
{
_groups = ((IShellController)_context.Shell).GenerateFlyoutGrouping();
+ _views = new Dictionary<Element, View>();
}
return _groups;
}
public void ClearCache()
{
_groups = null;
+ _views = null;
+ }
+
+ public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
+ {
+ int section = indexPath.Section;
+ int row = indexPath.Row;
+ var context = Groups[section][row];
+ View view;
+
+ if (!_views.TryGetValue(context, out view))
+ return UITableView.AutomaticDimension;
+
+ nfloat defaultHeight = tableView.EstimatedRowHeight == -1 ? 44 : tableView.EstimatedRowHeight;
+ nfloat height = -1;
+
+ if (view.HeightRequest >= 0)
+ height = (float)view.HeightRequest;
+ else
+ {
+ var request = view.Measure(tableView.Bounds.Width, double.PositiveInfinity, MeasureFlags.None);
+
+ if(request.Request.Height > defaultHeight)
+ height = (float)request.Request.Height;
+ else
+ height = defaultHeight;
+ }
+
+ if (height == -1)
+ height = defaultHeight;
+
+ return height;
}
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
cell.BindingContext = context;
}
+ _views[context] = cell.View;
return cell;
}