public static MauiAppBuilder ConfigureEssentials(this MauiAppBuilder builder, Action <IEssentialsBuilder> configureDelegate = null) { if (configureDelegate != null) { builder.Services.AddSingleton <EssentialsRegistration>(new EssentialsRegistration(configureDelegate)); } builder.Services.TryAddEnumerable(ServiceDescriptor.Transient <IMauiInitializeService, EssentialsInitializer>()); builder.ConfigureLifecycleEvents(life => { #if __ANDROID__ Platform.Init(MauiApplication.Current); life.AddAndroid(android => android .OnRequestPermissionsResult((activity, requestCode, permissions, grantResults) => { Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults); }) .OnNewIntent((activity, intent) => { Platform.OnNewIntent(intent); }) .OnResume((activity) => { Platform.OnResume(); })); #elif __IOS__ life.AddiOS(ios => ios .ContinueUserActivity((application, userActivity, completionHandler) => { return(Platform.ContinueUserActivity(application, userActivity, completionHandler)); }) .OpenUrl((application, url, options) => { return(Platform.OpenUrl(application, url, options)); }) .PerformActionForShortcutItem((application, shortcutItem, completionHandler) => { Platform.PerformActionForShortcutItem(application, shortcutItem, completionHandler); })); #elif WINDOWS life.AddWindows(windows => windows .OnActivated((window, args) => { Platform.OnActivated(window, args); }) .OnLaunched((application, args) => { Platform.OnLaunched(args); }) .OnNativeMessage((app, args) => { app.ExtendsContentIntoTitleBar = false; })); #endif }); return(builder); }
internal static MauiAppBuilder UseEssentials(this MauiAppBuilder builder) { builder.ConfigureLifecycleEvents(life => { #if __ANDROID__ Platform.Init(MauiApplication.Current); life.AddAndroid(android => android .OnCreate((activity, savedInstanceState) => { Platform.Init(activity, savedInstanceState); }) .OnRequestPermissionsResult((activity, requestCode, permissions, grantResults) => { Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults); }) .OnNewIntent((activity, intent) => { Platform.OnNewIntent(intent); }) .OnResume((activity) => { Platform.OnResume(); })); #elif __IOS__ life.AddiOS(ios => ios .ContinueUserActivity((application, userActivity, completionHandler) => { return(Platform.ContinueUserActivity(application, userActivity, completionHandler)); }) .OpenUrl((application, url, options) => { return(Platform.OpenUrl(application, url, options)); }) .PerformActionForShortcutItem((application, shortcutItem, completionHandler) => { Platform.PerformActionForShortcutItem(application, shortcutItem, completionHandler); })); #elif WINDOWS life.AddWindows(windows => windows .OnNativeMessage((window, args) => { Platform.NewWindowProc(args.Hwnd, args.MessageId, args.WParam, args.LParam); }) .OnActivated((window, args) => { Platform.OnActivated(window, args); }) .OnLaunched((application, args) => { Platform.OnLaunched(args); })); #endif }); return(builder); }
public static MauiAppBuilder UseFoldable(this MauiAppBuilder builder) { builder.Services.AddScoped(typeof(IFoldableContext), (sp) => new FoldableService()); builder.Services.AddScoped(typeof(IFoldableService), (sp) => sp.GetService <IFoldableContext>() as IFoldableService ?? new FoldableService()); builder.ConfigureLifecycleEvents(lc => { lc.AddAndroid(android => { android.OnConfigurationChanged((activity, configuration) => { GetFoldableService(activity) ?.OnConfigurationChanged(activity, configuration); }) .OnStart((activity) => { GetFoldableService(activity) ?.OnStart(activity); }) .OnStop((activity) => { GetFoldableService(activity) ?.OnStop(activity); }) .OnMauiContextCreated((context) => { var activity = context.Context.GetActivity(); var foldableService = (context.Services.GetService <IFoldableContext>() as FoldableService); if (activity != null && foldableService != null) { foldableService.OnCreate(activity); } }) .OnResume((activity) => { var foldableService = activity .GetWindow()? .Handler? .MauiContext? .Services?.GetService <IFoldableService>(); DualScreenInfo.Current.SetFoldableService(foldableService); }); }); }); return(builder); }
internal static MauiAppBuilder ConfigureCrossPlatformLifecycleEvents(this MauiAppBuilder builder) => builder.ConfigureLifecycleEvents(events => events.AddWindows(OnConfigureLifeCycle));
internal static MauiAppBuilder ConfigureCompatibilityLifecycleEvents(this MauiAppBuilder builder) => builder.ConfigureLifecycleEvents(events => events.AddAndroid(OnConfigureLifeCycle));