public static void Init(IActivationState activationState) { if (IsInitialized) { return; } ActivationState = activationState; IsInitialized = true; Microsoft.Maui.Controls.Internals.Registrar.RegisterRendererToHandlerShim(RendererToHandlerShim.CreateShim); //TODO: MAUI Accent Color? Color.SetAccent(Color.FromRgba(50, 79, 133, 255)); Log.Listeners.Add(new DelegateLogListener((c, m) => Trace.WriteLine(m, c))); #if __MOBILE__ Device.SetIdiom(UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? TargetIdiom.Tablet : TargetIdiom.Phone); Device.SetFlowDirection(UIApplication.SharedApplication.UserInterfaceLayoutDirection.ToFlowDirection()); #else // Subscribe to notifications in OS Theme changes NSDistributedNotificationCenter.GetDefaultCenter().AddObserver((NSString)"AppleInterfaceThemeChangedNotification", (n) => { var interfaceStyle = NSUserDefaults.StandardUserDefaults.StringForKey("AppleInterfaceStyle"); var aquaAppearance = NSAppearance.GetAppearance(interfaceStyle == "Dark" ? NSAppearance.NameDarkAqua : NSAppearance.NameAqua); NSApplication.SharedApplication.Appearance = aquaAppearance; Application.Current?.TriggerThemeChanged(new AppThemeChangedEventArgs(interfaceStyle == "Dark" ? OSAppTheme.Dark : OSAppTheme.Light)); }); Device.SetIdiom(TargetIdiom.Desktop); Device.SetFlowDirection(NSApplication.SharedApplication.UserInterfaceLayoutDirection.ToFlowDirection()); if (IsMojaveOrNewer) { var interfaceStyle = NSUserDefaults.StandardUserDefaults.StringForKey("AppleInterfaceStyle"); var aquaAppearance = NSAppearance.GetAppearance(interfaceStyle == "Dark" ? NSAppearance.NameDarkAqua : NSAppearance.NameAqua); NSApplication.SharedApplication.Appearance = aquaAppearance; } #endif Device.SetFlags(s_flags); var platformServices = new IOSPlatformServices(); Device.PlatformServices = platformServices; #if __MOBILE__ Device.PlatformInvalidator = platformServices; Device.Info = new IOSDeviceInfo(); #else Device.Info = new Platform.macOS.MacDeviceInfo(); #endif Controls.Internals.Registrar.RegisterAll(new[] { typeof(ExportRendererAttribute), typeof(ExportCellAttribute), typeof(ExportImageSourceHandlerAttribute), typeof(ExportFontAttribute) }); ExpressionSearch.Default = new iOSExpressionSearch(); }
static void SetupInit(IMauiContext context, InitializationOptions?maybeOptions = null) { MauiContext = context; Microsoft.Maui.Controls.Internals.Registrar.RegisterRendererToHandlerShim(RendererToHandlerShim.CreateShim); Application.AccentColor = Color.FromRgba(50, 79, 133, 255); #if __MOBILE__ Device.SetIdiom(UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? TargetIdiom.Tablet : TargetIdiom.Phone); Device.SetFlowDirection(UIApplication.SharedApplication.UserInterfaceLayoutDirection.ToFlowDirection()); #else if (!IsInitialized) { // Only need to do this once // Subscribe to notifications in OS Theme changes NSDistributedNotificationCenter.GetDefaultCenter().AddObserver((NSString)"AppleInterfaceThemeChangedNotification", (n) => { var interfaceStyle = NSUserDefaults.StandardUserDefaults.StringForKey("AppleInterfaceStyle"); var aquaAppearance = NSAppearance.GetAppearance(interfaceStyle == "Dark" ? NSAppearance.NameDarkAqua : NSAppearance.NameAqua); NSApplication.SharedApplication.Appearance = aquaAppearance; Application.Current?.TriggerThemeChanged(new AppThemeChangedEventArgs(interfaceStyle == "Dark" ? OSAppTheme.Dark : OSAppTheme.Light)); }); } Device.SetIdiom(TargetIdiom.Desktop); Device.SetFlowDirection(NSApplication.SharedApplication.UserInterfaceLayoutDirection.ToFlowDirection()); if (IsMojaveOrNewer) { var interfaceStyle = NSUserDefaults.StandardUserDefaults.StringForKey("AppleInterfaceStyle"); var aquaAppearance = NSAppearance.GetAppearance(interfaceStyle == "Dark" ? NSAppearance.NameDarkAqua : NSAppearance.NameAqua); NSApplication.SharedApplication.Appearance = aquaAppearance; } #endif var platformServices = new IOSPlatformServices(); Device.PlatformServices = platformServices; #if __MOBILE__ Device.PlatformInvalidator = platformServices; #endif if (maybeOptions?.Flags.HasFlag(InitializationFlags.SkipRenderers) != true) { RegisterCompatRenderers(); } ExpressionSearch.Default = new iOSExpressionSearch(); IsInitialized = true; }