Skip to content
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

Fix for [iOS] Use non-overridden traits in AppInfoImplementation.RequestTheme #25497

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue23411.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue23411">

<ScrollView AutomationId="ThemePage">
<VerticalStackLayout
Padding="30,0"
Spacing="25">
<Image
Source="dotnet_bot.png"
HeightRequest="185"
Aspect="AspectFit"
SemanticProperties.Description="dot net bot in a race car number eight" />

<Label
Text="Hello, World!"
Style="{StaticResource Headline}"
SemanticProperties.HeadingLevel="Level1" />

<Label
Text="Welcome to &#10;.NET Multi-platform App UI"
Style="{StaticResource SubHeadline}"
SemanticProperties.HeadingLevel="Level2"
SemanticProperties.Description="Welcome to dot net Multi platform App U I" />

<Button AutomationId="ModalPageButton"
x:Name="ModalPageBtn"
Text="Open modal page"
Clicked="OnModalPage"
HorizontalOptions="Fill" />

<Button
x:Name="LightThemeBtn"
Text="Light theme"
Clicked="OnLightTheme"
HorizontalOptions="Fill" />

<Button
x:Name="DarkThemeBtn"
Text="Dark theme"
Clicked="OnDarkTheme"
HorizontalOptions="Fill" />

<Button AutomationId="ResetThemeButton"
x:Name="ResetThemeBtn"
Text="Reset theme"
Clicked="OnResetTheme"
HorizontalOptions="Fill" />
</VerticalStackLayout>
</ScrollView>
</ContentPage>
43 changes: 43 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue23411.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#if IOS
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.PlatformConfiguration;
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;
using Application = Microsoft.Maui.Controls.Application;
using NavigationPage = Microsoft.Maui.Controls.NavigationPage;

namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 23411, "[iOS]Use non-overridden traits in AppInfoImplementation.RequestTheme",
PlatformAffected.iOS)]
public partial class Issue23411 : ContentPage
{
public Issue23411()
{
InitializeComponent();
Application.Current.UserAppTheme = AppTheme.Dark;
}

private void OnModalPage(object sender, EventArgs e)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EventHandler is only created for iOS and failing in the rest of the platforms.

D:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Issues\Issue23411.xaml(30,17): XamlC error XC0002: EventHandler "OnModalPage" with correct signature not found in type "Maui.Controls.Sample.Issues.Issue23411". [D:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-windows10.0.20348.0]
    5 Error(s)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsuarezruiz ,Thank you for sharing your concerns with us. We are actively working to resolve the issue and optimize the code for all platforms. We will provide you with an update on the latest fix as soon as possible.

{
var modalPage = new NavigationPage(new Issue23411() { Title = "Modal Page" ,AutomationId = "PageSheetModalPage" });
modalPage.On<iOS>().SetModalPresentationStyle(UIModalPresentationStyle.PageSheet);
Navigation.PushModalAsync(modalPage);
}

private void OnDarkTheme(object sender, EventArgs e)
{
Application.Current!.UserAppTheme = AppTheme.Dark;
}

private void OnLightTheme(object sender, EventArgs e)
{
Application.Current!.UserAppTheme = AppTheme.Light;
}

private void OnResetTheme(object sender, EventArgs e)
{
Application.Current!.UserAppTheme = AppTheme.Unspecified;
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#if IOS
using NUnit.Framework.Legacy;
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
internal class Issue23411 : _IssuesUITest
{
public override string Issue => "[iOS]Use non-overridden traits in AppInfoImplementation.RequestTheme";

public Issue23411(TestDevice device) : base(device)
{
}

[Test]
[Category(UITestCategories.Page)]
public void ThemeUnspecifiedDoesNotAffectModalPageSheet()
{
// Is a iOS issue; see https://github.com/dotnet/maui/issues/23411
App.WaitForElement("ThemePage");
App.WaitForElement("ModalPageButton");
App.Tap("ModalPage");
App.WaitForElement("PageSheetModalPage");
App.WaitForElement("ResetThemeButton");
VerifyScreenshot();

}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public AppTheme RequestedTheme
if ((OperatingSystem.IsIOS() && !OperatingSystem.IsIOSVersionAtLeast(13, 0)) || (OperatingSystem.IsTvOS() && !OperatingSystem.IsTvOSVersionAtLeast(13, 0)))
return AppTheme.Unspecified;

var traits =
MainThread.InvokeOnMainThread(() => WindowStateManager.Default.GetCurrentUIViewController()?.TraitCollection) ??
UITraitCollection.CurrentTraitCollection;
// This always returns the non-overridden trais which allows restoring the
// application back to the system theme.
var traits = UIScreen.MainScreen.TraitCollection;

var uiStyle = traits.UserInterfaceStyle;

Expand Down
Loading