-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Window lifecycle #1754
Window lifecycle #1754
Changes from all commits
616cad5
0ff0297
0c50402
f958a15
1f0c7db
29a288c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Microsoft.Maui.LifecycleEvents; | ||
using Microsoft.Maui.Hosting; | ||
using Microsoft.Maui.Controls.Compatibility; | ||
|
||
namespace Microsoft.Maui.Controls.Hosting | ||
{ | ||
public static partial class AppHostBuilderExtensions | ||
{ | ||
internal static IAppHostBuilder ConfigureCompatibilityLifecycleEvents(this IAppHostBuilder builder) => | ||
builder.ConfigureLifecycleEvents(events => events.AddAndroid(OnConfigureLifeCycle)); | ||
|
||
static void OnConfigureLifeCycle(IAndroidLifecycleBuilder android) | ||
{ | ||
android | ||
.OnApplicationCreating((app) => | ||
{ | ||
// This is the initial Init to set up any system services registered by | ||
// Forms.Init(). This happens in the Application's OnCreate - before | ||
// any UI has appeared. | ||
// This creates a dummy MauiContext that wraps the Application. | ||
|
||
var services = MauiApplication.Current.Services; | ||
var mauiContext = new MauiContext(services, app); | ||
var state = new ActivationState(mauiContext); | ||
Forms.Init(state, new InitializationOptions { Flags = InitializationFlags.SkipRenderers }); | ||
}) | ||
.OnMauiContextCreated((mauiContext) => | ||
{ | ||
// This is the final Init that sets up the real context from the activity. | ||
|
||
var state = new ActivationState(mauiContext); | ||
Forms.Init(state); | ||
}); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Microsoft.Maui.Hosting; | ||
using Microsoft.Maui.LifecycleEvents; | ||
using System; | ||
|
||
namespace Microsoft.Maui.Controls.Hosting | ||
{ | ||
public static partial class AppHostBuilderExtensions | ||
{ | ||
internal static IAppHostBuilder ConfigureCompatibilityLifecycleEvents(this IAppHostBuilder builder) => | ||
builder; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#nullable enable | ||
using Microsoft.Maui.Controls.Compatibility.Platform.UWP; | ||
using Microsoft.Maui.Graphics.Win2D; | ||
using BoxRenderer = Microsoft.Maui.Controls.Compatibility.Platform.UWP.BoxViewBorderRenderer; | ||
using CellRenderer = Microsoft.Maui.Controls.Compatibility.Platform.UWP.TextCellRenderer; | ||
using Deserializer = Microsoft.Maui.Controls.Compatibility.Platform.UWP.WindowsSerializer; | ||
using ResourcesProvider = Microsoft.Maui.Controls.Compatibility.Platform.UWP.WindowsResourcesProvider; | ||
using StreamImagesourceHandler = Microsoft.Maui.Controls.Compatibility.Platform.UWP.StreamImageSourceHandler; | ||
using ImageLoaderSourceHandler = Microsoft.Maui.Controls.Compatibility.Platform.UWP.UriImageSourceHandler; | ||
using DefaultRenderer = Microsoft.Maui.Controls.Compatibility.Platform.UWP.DefaultRenderer; | ||
using Microsoft.Maui.LifecycleEvents; | ||
using Microsoft.Maui.Controls.Compatibility; | ||
using System; | ||
using Microsoft.Maui.Hosting; | ||
|
||
namespace Microsoft.Maui.Controls.Hosting | ||
{ | ||
public static partial class AppHostBuilderExtensions | ||
{ | ||
internal static IAppHostBuilder ConfigureCompatibilityLifecycleEvents(this IAppHostBuilder builder) => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No changes here. Just moving platform specific code to its own file |
||
builder.ConfigureLifecycleEvents(events => events.AddWindows(OnConfigureLifeCycle)); | ||
|
||
static void OnConfigureLifeCycle(IWindowsLifecycleBuilder windows) | ||
{ | ||
windows.OnLaunching((app, args) => | ||
{ | ||
// This is the initial Init to set up any system services registered by | ||
// Forms.Init(). This happens before any UI has appeared. | ||
// This creates a dummy MauiContext. | ||
// We need to call this so the Window and Root Page can new up successfully | ||
// The dispatcher that's inside of Forms.Init needs to be setup before the initial | ||
// window and root page start creating. | ||
// Inside OnLaunched we grab the MauiContext that's on the window so we can have the correct | ||
// MauiContext inside Forms | ||
|
||
var services = MauiWinUIApplication.Current.Services; | ||
var mauiContext = new MauiContext(services); | ||
var state = new ActivationState(mauiContext, args); | ||
Forms.Init(state, new InitializationOptions { Flags = InitializationFlags.SkipRenderers }); | ||
}) | ||
.OnMauiContextCreated((mauiContext) => | ||
{ | ||
// This is the final Init that sets up the real context from the application. | ||
|
||
var state = new ActivationState(mauiContext); | ||
Forms.Init(state); | ||
}); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ | |
|
||
namespace Microsoft.Maui.Controls.Hosting | ||
{ | ||
public static class AppHostBuilderExtensions | ||
public static partial class AppHostBuilderExtensions | ||
{ | ||
public static IAppHostBuilder UseMauiApp<TApp>(this IAppHostBuilder builder) | ||
where TApp : class, IApplication | ||
|
@@ -67,81 +67,11 @@ public static IAppHostBuilder UseMauiApp<TApp>(this IAppHostBuilder builder, Fun | |
|
||
return builder; | ||
} | ||
|
||
|
||
static IAppHostBuilder SetupDefaults(this IAppHostBuilder builder) | ||
{ | ||
builder.ConfigureLifecycleEvents(events => | ||
{ | ||
#if __ANDROID__ | ||
events.AddAndroid(android => android | ||
.OnApplicationCreating((app) => | ||
{ | ||
// This is the initial Init to set up any system services registered by | ||
// Forms.Init(). This happens in the Application's OnCreate - before | ||
// any UI has appeared. | ||
// This creates a dummy MauiContext that wraps the Application. | ||
|
||
var services = MauiApplication.Current.Services; | ||
var mauiContext = new MauiContext(services, app); | ||
var state = new ActivationState(mauiContext); | ||
Forms.Init(state, new InitializationOptions { Flags = InitializationFlags.SkipRenderers }); | ||
}) | ||
.OnMauiContextCreated((mauiContext) => | ||
{ | ||
// This is the final Init that sets up the real context from the activity. | ||
|
||
var state = new ActivationState(mauiContext); | ||
Forms.Init(state); | ||
})); | ||
#elif __IOS__ | ||
events.AddiOS(iOS => iOS | ||
.WillFinishLaunching((app, options) => | ||
{ | ||
// This is the initial Init to set up any system services registered by | ||
// Forms.Init(). This happens before any UI has appeared. | ||
// This creates a dummy MauiContext. | ||
|
||
var services = MauiUIApplicationDelegate.Current.Services; | ||
var mauiContext = new MauiContext(services); | ||
var state = new ActivationState(mauiContext); | ||
Forms.Init(state, new InitializationOptions { Flags = InitializationFlags.SkipRenderers }); | ||
return true; | ||
}) | ||
.OnMauiContextCreated((mauiContext) => | ||
{ | ||
// This is the final Init that sets up the real context from the application. | ||
|
||
var state = new ActivationState(mauiContext); | ||
Forms.Init(state); | ||
})); | ||
#elif WINDOWS | ||
events.AddWindows(windows => windows | ||
.OnLaunching((app, args) => | ||
{ | ||
// This is the initial Init to set up any system services registered by | ||
// Forms.Init(). This happens before any UI has appeared. | ||
// This creates a dummy MauiContext. | ||
// We need to call this so the Window and Root Page can new up successfully | ||
// The dispatcher that's inside of Forms.Init needs to be setup before the initial | ||
// window and root page start creating. | ||
// Inside OnLaunched we grab the MauiContext that's on the window so we can have the correct | ||
// MauiContext inside Forms | ||
|
||
var services = MauiWinUIApplication.Current.Services; | ||
var mauiContext = new MauiContext(services); | ||
var state = new ActivationState(mauiContext, args); | ||
Forms.Init(state, new InitializationOptions { Flags = InitializationFlags.SkipRenderers }); | ||
}) | ||
.OnMauiContextCreated((mauiContext) => | ||
{ | ||
// This is the final Init that sets up the real context from the application. | ||
|
||
var state = new ActivationState(mauiContext); | ||
Forms.Init(state); | ||
})); | ||
#endif | ||
}); | ||
|
||
builder.ConfigureCompatibilityLifecycleEvents(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No changes here. Just moving platform specific code to its own file |
||
builder | ||
.ConfigureMauiHandlers(handlers => | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Microsoft.Maui.Hosting; | ||
using Microsoft.Maui.LifecycleEvents; | ||
using Microsoft.Maui.Controls.Compatibility; | ||
|
||
namespace Microsoft.Maui.Controls.Hosting | ||
{ | ||
public static partial class AppHostBuilderExtensions | ||
{ | ||
internal static IAppHostBuilder ConfigureCompatibilityLifecycleEvents(this IAppHostBuilder builder) => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No changes here. Just moving platform specific code to its own file |
||
builder.ConfigureLifecycleEvents(events => events.AddiOS(OnConfigureLifeCycle)); | ||
|
||
static void OnConfigureLifeCycle(IiOSLifecycleBuilder iOS) | ||
{ | ||
iOS.WillFinishLaunching((app, options) => | ||
{ | ||
// This is the initial Init to set up any system services registered by | ||
// Forms.Init(). This happens before any UI has appeared. | ||
// This creates a dummy MauiContext. | ||
|
||
var services = MauiUIApplicationDelegate.Current.Services; | ||
var mauiContext = new MauiContext(services); | ||
var state = new ActivationState(mauiContext); | ||
Forms.Init(state, new InitializationOptions { Flags = InitializationFlags.SkipRenderers }); | ||
return true; | ||
}) | ||
.OnMauiContextCreated((mauiContext) => | ||
{ | ||
// This is the final Init that sets up the real context from the application. | ||
|
||
var state = new ActivationState(mauiContext); | ||
Forms.Init(state); | ||
}); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,11 +119,11 @@ static void SetupInit( | |
{ | ||
MainWindow = mainWindow; | ||
|
||
if (mainWindow is WindowsBasePage windowsPage) | ||
{ | ||
windowsPage.LoadApplication(windowsPage.CreateApplication()); | ||
windowsPage.Activate(); | ||
} | ||
//if (mainWindow is WindowsBasePage windowsPage) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've commented out WindowsBasePage because it's not a type that we need for compatibility or MAUI |
||
//{ | ||
// windowsPage.LoadApplication(windowsPage.CreateApplication()); | ||
// windowsPage.Activate(); | ||
//} | ||
} | ||
|
||
IsInitialized = true; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,11 +35,8 @@ public class NavigationPageRenderer : IVisualElementRenderer, ITitleProvider, IT | |
WImageSource _titleIcon; | ||
VisualElementTracker<Page, PageControl> _tracker; | ||
EntranceThemeTransition _transition; | ||
Platform _platform; | ||
bool _parentsLookedUp = false; | ||
|
||
Platform Platform => _platform ?? (_platform = Platform.Current); | ||
|
||
public NavigationPage Element { get; private set; } | ||
|
||
protected VisualElementTracker<Page, PageControl> Tracker | ||
|
@@ -676,7 +673,7 @@ void UpdateBackButton() | |
_container.SetBackButtonTitle(Element); | ||
} | ||
|
||
async void UpdateTitleOnParents() | ||
void UpdateTitleOnParents() | ||
{ | ||
if (Element == null || _currentPage == null) | ||
return; | ||
|
@@ -710,10 +707,10 @@ async void UpdateTitleOnParents() | |
|
||
if (_showTitle || (render != null && render.ShowTitle)) | ||
{ | ||
if (Platform != null) | ||
{ | ||
await Platform.UpdateToolbarItems(); | ||
} | ||
//if (Platform != null) | ||
//{ | ||
// await Platform.UpdateToolbarItems(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently none of this code is running so commenting this out doesn't break anything. |
||
//} | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No changes here. Just moving platform specific code to its own file