Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#nullable disable
using System;
using System.ComponentModel;
using CoreGraphics;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Graphics;
using ObjCRuntime;
using UIKit;

namespace Microsoft.Maui.Controls.Platform.Compatibility
Expand Down Expand Up @@ -131,11 +135,12 @@ void UpdateFlyoutFooter(View view)

if (_footer is not null)
{
_footerView = new ShellFlyoutFooterContainer(_footer);
_footerView = new UIContainerView(_footer);
_uIViews[FooterIndex] = _footerView;
AddViewInCorrectOrder(_footerView, previousIndex);

_footerView.ClipsToBounds = true;
_footerView.PlatformMeasureInvalidated += OnFooterMeasureInvalidated;
}

_tableViewController.FooterView = _footerView;
Expand Down Expand Up @@ -181,10 +186,45 @@ void AddViewInCorrectOrder(UIView newView, int previousIndex)
View.AddSubview(newView);
}

void OnFooterMeasureInvalidated(object sender, System.EventArgs e)
{
ReMeasureFooter();
}

void ReMeasureFooter()
{
var size = _footerView?.SizeThatFits(new CGSize(View.Frame.Width, double.PositiveInfinity));
if (size is not null)
UpdateFooterPosition(size.Value.Height);
}

void UpdateFooterPosition()
{
if (_footerView is null)
return;

if (double.IsNaN(_footerView.MeasuredHeight))
ReMeasureFooter();
else
UpdateFooterPosition((nfloat)_footerView.MeasuredHeight);
}

void UpdateFooterPosition(nfloat footerHeight)
{
if (_footerView is null && !nfloat.IsNaN(footerHeight))
return;

var footerWidth = View.Frame.Width;

_footerView.Frame = new CoreGraphics.CGRect(0, View.Frame.Height - footerHeight, footerWidth, footerHeight);

_tableViewController.LayoutParallax();
}

public override void ViewWillLayoutSubviews()
{
base.ViewWillLayoutSubviews();
_tableViewController.LayoutParallax();
UpdateFooterPosition();
UpdateFlyoutContent();
}

Expand Down Expand Up @@ -273,6 +313,11 @@ public override void ViewDidLayoutSubviews()
_bgImage.Frame = View.Bounds;
}

public override void LoadView()
{
View = new UIContainerViewContainer();
}

public override void ViewDidLoad()
{
base.ViewDidLoad();
Expand Down Expand Up @@ -317,7 +362,7 @@ void UpdateFlyoutContent()

_uIViews[ContentIndex] = _shellFlyoutContentManager.ContentView;
AddViewInCorrectOrder(_uIViews[ContentIndex], previousIndex);
_shellFlyoutContentManager.UpdateHeaderSize();
_shellFlyoutContentManager.UpdateLayout();
}

public override void ViewWillAppear(bool animated)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,13 @@ public override Thickness Margin
}
}

public override void LayoutSubviews()
{
if (!UpdateSafeAreaMargin())
base.LayoutSubviews();

OnHeaderSizeChanged();
}

public override void SafeAreaInsetsDidChange()
{
UpdateSafeAreaMargin();
base.SafeAreaInsetsDidChange();
}

bool UpdateSafeAreaMargin()
void UpdateSafeAreaMargin()
{
var safeArea = UIApplication.SharedApplication.GetSafeAreaInsetsForWindow();

Expand All @@ -64,12 +56,8 @@ bool UpdateSafeAreaMargin()
safeArea.Right,
safeArea.Bottom);

OnHeaderSizeChanged();
return true;
OnPlatformMeasureInvalidated();
}

return false;

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ShellFlyoutLayoutManager
UIView _contentView;
UIScrollView ScrollView { get; set; }
UIContainerView _headerView;
UIView _footerView;
UIContainerView _footerView;
double _headerSize;
readonly IShellContext _context;
Action removeScrolledEvent;
Expand Down Expand Up @@ -142,7 +142,7 @@ private set
ScrollView.ContentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentBehavior.Never;
}

UpdateHeaderSize();
UpdateLayout();
}
}

Expand All @@ -155,40 +155,61 @@ public virtual UIContainerView HeaderView
return;

if (_headerView is not null)
_headerView.HeaderSizeChanged -= OnHeaderViewMeasureChanged;
_headerView.PlatformMeasureInvalidated -= OnHeaderViewMeasureChanged;

_headerView = value;

if (_headerView is not null)
_headerView.HeaderSizeChanged += OnHeaderViewMeasureChanged;
_headerView.PlatformMeasureInvalidated += OnHeaderViewMeasureChanged;

UpdateHeaderSize();
UpdateLayout();
}
}

public virtual UIView FooterView
public virtual UIContainerView FooterView
{
get => _footerView;
set
{
if (_footerView == value)
return;

if (_footerView is not null)
_footerView.PlatformMeasureInvalidated -= OnFooterViewMeasureChanged;

_footerView = value;
UpdateHeaderSize();

if (_footerView is not null)
_footerView.PlatformMeasureInvalidated += OnFooterViewMeasureChanged;

UpdateLayout();
}
}

void OnFooterViewMeasureChanged(object sender, EventArgs e)
{
if (FooterView is null || ContentView?.Superview is not { } flyoutView)
return;

var flyoutFrame = flyoutView.Frame;
var widthConstraint = flyoutFrame.Width;
var heightConstraint = flyoutFrame.Height;
var size = FooterView.SizeThatFits(new CGSize(widthConstraint, double.PositiveInfinity));
FooterView.Frame = new CGRect(0, heightConstraint - size.Height, widthConstraint, size.Height);

UpdateLayout();
}

void OnHeaderViewMeasureChanged(object sender, EventArgs e)
{
if (HeaderView is null || ContentView?.Superview is null)
return;

HeaderView.SizeThatFits(new CGSize(ContentView.Superview.Frame.Width, double.PositiveInfinity));
UpdateHeaderSize();
UpdateLayout();
}

internal void UpdateHeaderSize()
internal void UpdateLayout()
{
if (HeaderView is null || ContentView?.Superview is null)
return;
Expand Down Expand Up @@ -365,7 +386,7 @@ void OnShellPropertyChanged(object sender, PropertyChangedEventArgs e)

public void ViewDidLoad()
{
UpdateHeaderSize();
UpdateLayout();
}

public void OnScrolled(nfloat contentOffsetY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ public virtual UIContainerView HeaderView
set => ShellFlyoutContentManager.HeaderView = value;
}

// TODO: .NET10 change to UIContainerView
public virtual UIView FooterView
{
get => ShellFlyoutContentManager.FooterView;
set => ShellFlyoutContentManager.FooterView = value;
set => ShellFlyoutContentManager.FooterView = value as UIContainerView;
}

protected ShellTableViewSource CreateShellTableViewSource()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,10 @@ public override UITableViewCell GetCell(UITableView tableView, NSIndexPath index
_cells[context] = cell;
cell.TableView = tableView;
cell.IndexPath = indexPath;
cell.ViewMeasureInvalidated += OnViewMeasureInvalidated;

return cell;
}

void OnViewMeasureInvalidated(UIContainerCell cell)
{
cell.ReloadRow();
}

public override nfloat GetHeightForFooter(UITableView tableView, nint section)
{
if (section < Groups.Count - 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@

namespace Microsoft.Maui.Controls.Platform.Compatibility
{
public class UIContainerCell : UITableViewCell
public class UIContainerCell : UITableViewCell, IPlatformMeasureInvalidationController
{
IPlatformViewHandler _renderer;
object _bindingContext;

internal Action<UIContainerCell> ViewMeasureInvalidated { get; set; }
internal NSIndexPath IndexPath { get; set; }
internal UITableView TableView { get; set; }

internal UIContainerCell(string cellId, View view, Shell shell, object context) : base(UITableViewCellStyle.Default, cellId)
{
View = view;
View.MeasureInvalidated += MeasureInvalidated;
SelectionStyle = UITableViewCellSelectionStyle.None;

_renderer = (IPlatformViewHandler)view.Handler;
Expand All @@ -43,16 +41,20 @@ internal UIContainerCell(string cellId, View view, Shell shell, object context)
shell.AddLogicalChild(View);
}

public UIContainerCell(string cellId, View view) : this(cellId, view, null, null)
void IPlatformMeasureInvalidationController.InvalidateAncestorsMeasuresWhenMovedToWindow()
{
}

void MeasureInvalidated(object sender, System.EventArgs e)
void IPlatformMeasureInvalidationController.InvalidateMeasure(bool isPropagating)
{
if (View == null || TableView == null)
return;
if (isPropagating)
{
ReloadRow();
}
}

ViewMeasureInvalidated?.Invoke(this);
public UIContainerCell(string cellId, View view) : this(cellId, view, null, null)
{
}

internal void ReloadRow()
Expand All @@ -62,8 +64,6 @@ internal void ReloadRow()

internal void Disconnect(Shell shell = null, bool keepRenderer = false)
{
ViewMeasureInvalidated = null;
View.MeasureInvalidated -= MeasureInvalidated;
if (_bindingContext != null && _bindingContext is BaseShellItem baseShell)
baseShell.PropertyChanged -= OnElementPropertyChanged;

Expand Down
Loading