Skip to content

Commit

Permalink
Added pending lifecycle events (#7225)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuarezruiz committed May 17, 2022
1 parent 820c03a commit a6c12a1
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 10 deletions.
35 changes: 35 additions & 0 deletions src/Controls/samples/Controls.Sample/MauiWindow.cs
@@ -0,0 +1,35 @@
using System;
using Microsoft.Maui.Controls;

namespace Maui.Controls.Sample
{
public class MauiWindow : Window
{
public MauiWindow() : base() { }
public MauiWindow(Page page) : base(page) { }

protected override void OnCreated()
{
Console.WriteLine("OnCreated");
base.OnCreated();
}

protected override void OnStopped()
{
Console.WriteLine("OnStopped");
base.OnStopped();
}

protected override void OnResumed()
{
Console.WriteLine("OnResumed");
base.OnResumed();
}

protected override void OnDestroying()
{
Console.WriteLine("OnDestroying");
base.OnDestroying();
}
}
}
8 changes: 5 additions & 3 deletions src/Controls/samples/Controls.Sample/XamlApp.xaml.cs
Expand Up @@ -5,7 +5,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Devices;
using Microsoft.Maui.Storage;

namespace Maui.Controls.Sample
Expand Down Expand Up @@ -49,8 +48,11 @@ async void LoadAsset()
// Must not use MainPage for multi-window
protected override Window CreateWindow(IActivationState activationState)
{
var window = new Window(Services.GetRequiredService<Page>());
window.Title = ".NET MAUI Samples Gallery";
var window = new MauiWindow(Services.GetRequiredService<Page>())
{
Title = ".NET MAUI Samples Gallery"
};

return window;
}

Expand Down
@@ -1,6 +1,4 @@
using System;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.LifecycleEvents;

namespace Microsoft.Maui.LifecycleEvents
{
Expand Down Expand Up @@ -66,4 +64,4 @@ static void OnConfigureLifeCycle(IAndroidLifecycleBuilder android)
});
}
}
}
}
@@ -1,9 +1,7 @@
using Microsoft.Maui.Hosting;
using Microsoft.Maui.LifecycleEvents;
using System;

namespace Microsoft.Maui.LifecycleEvents
{
{
public static partial class AppHostBuilderExtensions
{
internal static MauiAppBuilder ConfigureCrossPlatformLifecycleEvents(this MauiAppBuilder builder) =>
Expand Down
Expand Up @@ -3,7 +3,6 @@
using Android.Content.PM;
using Android.Content.Res;
using Android.OS;
using Android.Views;
using Microsoft.Maui.Devices;
using Microsoft.Maui.LifecycleEvents;

Expand Down Expand Up @@ -95,5 +94,12 @@ protected override void OnRestoreInstanceState(Bundle savedInstanceState)

MauiApplication.Current?.Services?.InvokeLifecycleEvents<AndroidLifecycle.OnRestoreInstanceState>(del => del(this, savedInstanceState));
}

protected override void OnDestroy()
{
base.OnDestroy();

MauiApplication.Current?.Services?.InvokeLifecycleEvents<AndroidLifecycle.OnDestroy>(del => del(this));
}
}
}
6 changes: 6 additions & 0 deletions src/Core/src/Platform/iOS/MauiUIApplicationDelegate.cs
Expand Up @@ -114,6 +114,12 @@ public virtual void OnResignActivation(UIApplication application)
Services?.InvokeLifecycleEvents<iOSLifecycle.OnResignActivation>(del => del(application));
}

[Export("sceneDidDisconnect:")]
public void DidDisconnect(UIScene scene)
{
Services?.InvokeLifecycleEvents<iOSLifecycle.SceneDidDisconnect>(del => del(scene));
}

[Export("applicationWillTerminate:")]
public virtual void WillTerminate(UIApplication application)
{
Expand Down

0 comments on commit a6c12a1

Please sign in to comment.