Skip to content

Commit

Permalink
Merge pull request #262 from adospace/fix-261
Browse files Browse the repository at this point in the history
Fix 261
  • Loading branch information
adospace authored Nov 13, 2024
2 parents 184947c + 5b1ea66 commit 01726f0
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
Solution_Name: ./src/MauiReactor.Build.sln
Test_Project: ./samples/UnitTests/UnitTests.csproj
TemplatePack_Name: ./src/MauiReactor.TemplatePack/MauiReactor.TemplatePack.csproj
Version: 2.0.54
Version: 2.0.55

steps:
- name: Checkout
Expand Down
3 changes: 3 additions & 0 deletions samples/MauiReactor.TestApp/Pages/TestBug257.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ public override VisualNode Render()
{
return ContentPage("Page6",

ToolbarItem("Menu Item 1")
.OnClicked(() => System.Diagnostics.Debug.WriteLine("Menu Item 1 Clicked")),

Button("Click me!")
.Center()
.OnClicked(async () => await ContainerPage.DisplayAlert("Message", "Hello!", "OK"))

Check warning on line 161 in samples/MauiReactor.TestApp/Pages/TestBug257.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
Expand Down
2 changes: 1 addition & 1 deletion src/MauiReactor/FlyoutPage.partial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override IEnumerable<VisualNode> RenderChildren()

if (thisAsIFlyoutPage.Flyout != null)
{
children = children.Concat(new[] { thisAsIFlyoutPage.Flyout });
children = children.Concat([thisAsIFlyoutPage.Flyout]);
}

return children;
Expand Down
8 changes: 8 additions & 0 deletions src/MauiReactor/MultiPage`1.partial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ namespace MauiReactor;
public abstract partial class MultiPage<T, TChild> : Page<T>, IGenericMultiPage where T : Microsoft.Maui.Controls.MultiPage<TChild>, new()
where TChild : Microsoft.Maui.Controls.Page
{
protected override void OnMount()
{
base.OnMount();

Validate.EnsureNotNull(NativeControl);
NativeControl.Children.Clear();
}

protected override void OnAddChild(VisualNode widget, BindableObject childControl)
{
Validate.EnsureNotNull(NativeControl);
Expand Down
3 changes: 3 additions & 0 deletions src/MauiReactor/Page.partial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ protected override void OnMount()

if (pageHost != null && containerPage != null && containerPage is T nativeContainerPage)
{
nativeContainerPage.MenuBarItems.Clear();
nativeContainerPage.ToolbarItems.Clear();

_nativeControl = nativeContainerPage;
}

Expand Down
114 changes: 84 additions & 30 deletions src/MauiReactor/PageHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal abstract class PageHost : VisualNode
private readonly INavigation _navigation;
protected bool _sleeping;
protected bool _unloading;
protected bool _checkingUnloading;

public PageHost(INavigation navigation)
{
Expand Down Expand Up @@ -48,28 +49,33 @@ private set
}
}

//private void CheckUnloading()
//{
// var containerPage = ContainerPage;
// if (containerPage == null ||
// (!_navigation.NavigationStack.Contains(containerPage) &&
// !_navigation.ModalStack.Contains(containerPage)))
// {
// if (!_unloading)
// {
// _unloading = true;
// Invalidate();
// }
// }
// else if (containerPage != null &&
// (
// _navigation.NavigationStack.Count > 0 && _navigation.NavigationStack[_navigation.NavigationStack.Count - 1] == containerPage ||
// _navigation.ModalStack.Count > 0 && _navigation.ModalStack[_navigation.ModalStack.Count - 1] == containerPage
// ))
// {
// Application.Current?.Dispatcher.Dispatch(CheckUnloading);
// }
//}
private void CheckUnloading()
{
if (!_checkingUnloading)
{
return;
}

_checkingUnloading = false;

var containerPage = ContainerPage;
if (containerPage == null ||
(!_navigation.NavigationStack.Contains(containerPage) &&
!_navigation.ModalStack.Contains(containerPage)))
{
if (!_unloading)
{
System.Diagnostics.Debug.WriteLine($"{containerPage?.Title} Unmounting");
_checkingUnloading = false;
_unloading = true;
Invalidate();
}
}
else
{
Application.Current?.Dispatcher.Dispatch(CheckUnloading);
}
}

protected sealed override void OnAddChild(VisualNode widget, BindableObject nativeControl)
{
Expand All @@ -91,36 +97,84 @@ protected sealed override void OnAddChild(VisualNode widget, BindableObject nati
page.SetValue(MauiReactorPageHostBagKey, this);
page.Appearing += ComponentPage_Appearing;
page.Disappearing += ContainerPage_Disappearing;
//page.NavigatedFrom += ContainerPagePage_NavigatedFrom;
//page.Loaded += ContainerPage_Loaded;
//page.Unloaded += ContainerPage_Unloaded;
//page.HandlerChanged += ContainerPage_HandlerChanged;
}
else
{
throw new NotSupportedException($"Invalid root component ({nativeControl.GetType()}): must be a page (i.e. ContentPage, Shell etc)");
}
}

}

//private void ContainerPagePage_NavigatedFrom(object? sender, NavigatedFromEventArgs e)
//{
// System.Diagnostics.Debug.WriteLine($"{ContainerPage?.Title} NavigatedFrom()");
//}

//private void ContainerPage_HandlerChanged(object? sender, EventArgs e)
//{
// System.Diagnostics.Debug.WriteLine($"IsHandlerValid({ContainerPage?.Handler != null})");
//}

private void ContainerPage_Disappearing(object? sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine($"{ContainerPage?.Title} Disappearing");
//Application.Current?.Dispatcher.Dispatch(CheckUnloading);
_unloading = true;
Invalidate();

if (_checkingUnloading)
{
return;
}

_checkingUnloading = true;
Application.Current?.Dispatcher.Dispatch(CheckUnloading);

//var containerPage = ContainerPage;

//if (containerPage != null &&
// (
// _navigation.NavigationStack.Contains(containerPage) ||
// _navigation.ModalStack.Contains(containerPage)
// ))
//{
// System.Diagnostics.Debug.WriteLine($"{containerPage?.Title} Disappearing");
// return;
//}

//System.Diagnostics.Debug.WriteLine($"{containerPage?.Title} Unmounting");
//_unloading = true;
//Invalidate();
}

private void ComponentPage_Appearing(object? sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine($"{ContainerPage?.Title} Appearing");
{
_checkingUnloading = false;

if (_unloading)
{
System.Diagnostics.Debug.WriteLine($"{ContainerPage?.Title} Mounting");
_unloading = false;
IsLayoutCycleRequired = true;
Application.Current?.Dispatcher.Dispatch(OnRecyclingPage);
}
else
{
System.Diagnostics.Debug.WriteLine($"{ContainerPage?.Title} Appearing");
_sleeping = false;
OnLayoutCycleRequested();
}
}
}


//private void ContainerPage_Loaded(object? sender, EventArgs e)
//{
// System.Diagnostics.Debug.WriteLine($"{ContainerPage?.Title} Loaded");
//}
//private void ContainerPage_Unloaded(object? sender, EventArgs e)
//{
// System.Diagnostics.Debug.WriteLine($"{ContainerPage?.Title} Unloaded");
//}

protected sealed override void OnRemoveChild(VisualNode widget, BindableObject nativeControl)
{
Expand Down

0 comments on commit 01726f0

Please sign in to comment.