Open drasticactions opened 8 months ago
Same behavior when using IOS native Sheets. Theme seams to reset on minimize.
Verified this issue with Visual Studio For Mac 17.6.9(415). Can repro on iOS platform with sample project. https://github.com/drasticactions/MauiRepros/blob/main/MauiTheme/
Sadly, this seems to still be an issue with SR3 (V8.0.10). Will this be added to a new Service Release soon?
Run also into this issue. When Maui Page.DisplayAlert is open and iOS gets minimized and resume the app the lightmode switches to dark mode. MAUI bug.
For now a easy complete workaround is to set UserAppTheme manually uppon App-Startup or App-Resume on iOS:
using Microsoft.Extensions.Logging;
using Microsoft.Maui.LifecycleEvents;
namespace MauiSyncfusion;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureLifecycleEvents(events => {
events.AddiOS(ios => ios.OnActivated((app) =>
{
var uiStyle = UIKit.UIScreen.MainScreen.TraitCollection.UserInterfaceStyle;
if (uiStyle == UIKit.UIUserInterfaceStyle.Light) Application.Current.UserAppTheme = AppTheme.Light;
if (uiStyle == UIKit.UIUserInterfaceStyle.Dark) Application.Current.UserAppTheme = AppTheme.Dark;
}
));
})
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
#if DEBUG
builder.Logging.AddDebug();
#endif
return builder.Build();
}
}
Description
I think it's related to this: https://github.com/dotnet/maui/issues/15962#issuecomment-1621304855
When you switch back and forth between apps, the trait change event is fired from iOS for Light, then Dark, themes. When you don't have a system prompt on screen, both events fire and the app theme changes. When a system prompt is on screen, however, both events still fire, but MAUI only processes the first event so it sticks to the "light" mode. This also happens in reverse if your system is in light mode; it will be stuck in dark mode.
You can fix it by switching off the prompt and renavigating back to the page, or handling themes yourself by setting UserAppTheme.
https://github.com/dotnet/maui/assets/898335/eb28f667-77e6-4343-87c1-8b36e8238dba
I'm not sure if this is a "regression" in MAUI, in that it's either a change in iOS that's causing behavior that now breaks what happens in MAUI, or it's always been happening.
Steps to Reproduce
Run the sample
Link to public reproduction project repository
https://github.com/drasticactions/MauiRepros/blob/main/MauiTheme/
Version with bug
8.0.3
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
No response
Did you find any workaround?
No response
Relevant log output
No response