Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kubaflo committed Apr 13, 2024
1 parent 82d823a commit d7e6337
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Controls/samples/Controls.Sample.Sandbox/DetailPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<ContentPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.DetailPage"
Title="Detail"
xmlns:local="clr-namespace:Maui.Controls.Sample">
<!--<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="50" />
<RowDefinition Height="50" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Entry Text='Hii'
Grid.Row="0"
ClearButtonVisibility="WhileEditing" />
<DatePicker Date="06/21/2022"
Grid.Row="1" />
<CheckBox IsChecked="True"
Grid.Row="2" />
<Button Text="Click"
Grid.Row="3"
Clicked="Button_Clicked" />
</Grid>-->
</ContentPage>
18 changes: 18 additions & 0 deletions src/Controls/samples/Controls.Sample.Sandbox/DetailPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;

namespace Maui.Controls.Sample
{
public partial class DetailPage : ContentPage
{
public DetailPage()
{
InitializeComponent();
}

//void Button_Clicked(System.Object sender, System.EventArgs e)
//{
// Application.Current.UserAppTheme = AppTheme.Dark;
//}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ protected override void Dispose(bool disposing)
_footerViewFormsElement.MeasureInvalidated -= OnFormsElementMeasureInvalidated;
}

if (_headerUIView is MauiView hv)
{
hv.LayoutChanged += HeaderView_LayoutChanged;
}

if (_footerUIView is MauiView fv)
{
fv.LayoutChanged -= FooterView_LayoutChanged;
}

_headerUIView = null;
_headerViewFormsElement = null;
_footerUIView = null;
Expand Down Expand Up @@ -105,15 +115,26 @@ internal void UpdateFooterView()
UpdateSubview(ItemsView?.Footer, ItemsView?.FooterTemplate, FooterTag,
ref _footerUIView, ref _footerViewFormsElement);
UpdateHeaderFooterPosition();

if (_footerUIView is MauiView mv)
{
mv.LayoutChanged += FooterView_LayoutChanged;
}
}

internal void UpdateHeaderView()
{
UpdateSubview(ItemsView?.Header, ItemsView?.HeaderTemplate, HeaderTag,
ref _headerUIView, ref _headerViewFormsElement);
UpdateHeaderFooterPosition();

if(_headerUIView is MauiView mv)
{
mv.LayoutChanged += HeaderView_LayoutChanged;
}
}


internal void UpdateSubview(object view, DataTemplate viewTemplate, nint viewTag, ref UIView uiView, ref VisualElement formsElement)
{
uiView?.RemoveFromSuperview();
Expand Down Expand Up @@ -239,5 +260,15 @@ internal void UpdateLayoutMeasurements()
if (_footerViewFormsElement != null)
HandleFormsElementMeasureInvalidated(_footerViewFormsElement);
}

private void HeaderView_LayoutChanged(object sender, EventArgs e)
{
HandleFormsElementMeasureInvalidated(_headerViewFormsElement);
}

private void FooterView_LayoutChanged(object sender, EventArgs e)
{
HandleFormsElementMeasureInvalidated(_footerViewFormsElement);
}
}
}
9 changes: 9 additions & 0 deletions src/Core/src/Platform/iOS/MauiView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public override void LayoutSubviews()
}

CrossPlatformArrange(bounds);
OnLayoutChanged();
}

public override void SetNeedsLayout()
Expand Down Expand Up @@ -174,5 +175,13 @@ public override void MovedToWindow()
base.MovedToWindow();
_movedToWindow?.Invoke(this, EventArgs.Empty);
}

[UnconditionalSuppressMessage("Memory", "MEM0001", Justification = IUIViewLifeCycleEvents.UnconditionalSuppressMessage)]
internal event EventHandler? LayoutChanged;

private void OnLayoutChanged()
{
LayoutChanged?.Invoke(this, EventArgs.Empty);
}
}
}

0 comments on commit d7e6337

Please sign in to comment.