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

Merged
merged 8 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
38 changes: 38 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue23411.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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 AutomationId="ThemeLabel" x:Name="ThemeLabelText"
Text="Hello, World!"
SemanticProperties.HeadingLevel="Level1" />

<Label
Text="Welcome to &#10;.NET Multi-platform App UI"
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 AutomationId="ResetThemeButton"
x:Name="ResetThemeBtn"
Text="Reset theme"
Clicked="OnResetTheme"
HorizontalOptions="Fill" />
</VerticalStackLayout>
</ScrollView>
</ContentPage>
86 changes: 86 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,86 @@
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();
}

protected override async void OnAppearing()
{
Application.Current.UserAppTheme = AppTheme.Dark;
await Task.Delay(500);
base.OnAppearing();
}
private void OnModalPage(object sender, EventArgs e)
{
#if IOS
var modalPage = new Microsoft.Maui.Controls.NavigationPage(new Issue23411Pagesheet() { Title = "Modal Page" ,AutomationId = "PageSheetModalPage" });
modalPage.On<iOS>().SetModalPresentationStyle(UIModalPresentationStyle.PageSheet);
Navigation.PushModalAsync(modalPage);
#endif
}

private void OnResetTheme(object sender, EventArgs e)
{
Application.Current.UserAppTheme = AppTheme.Unspecified;
}
}

public partial class Issue23411Pagesheet : ContentPage
{
private Label ThemeLabelText;
private Button ResetThemeButton;

public Issue23411Pagesheet()
{
InitializeComponents();
}

private void InitializeComponents()
{
// Create Label
ThemeLabelText = new Label
{
Text = "Current Theme",
AutomationId = "ThemePageLabel",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.CenterAndExpand
};

// Create Button
ResetThemeButton = new Button
{
Text = "Reset Theme",
AutomationId = "ResetThemePageButton",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.CenterAndExpand
};
ResetThemeButton.Clicked += OnResetTheme;

// Create Layout
var stackLayout = new StackLayout
{
Children = { ThemeLabelText, ResetThemeButton },
};

// Set the page content to the layout
Content = stackLayout;
}

private void OnResetTheme(object sender, EventArgs e)
{
Application.Current.UserAppTheme = AppTheme.Unspecified;
ThemeLabelText.Text = "Theme reset to Unspecified";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#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("ModalPageButton");
App.Tap("ModalPageButton");
App.WaitForElement("PageSheetModalPage");
App.WaitForElement("ResetThemePageButton");
App.Tap("ResetThemePageButton");
VerifyScreenshot();
}
}
}
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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