|
1 | 1 | using System; |
2 | 2 | using System.Threading.Tasks; |
3 | 3 | using Android.App; |
| 4 | +using Android.Content.Res; |
4 | 5 | using AndroidX.AppCompat.App; |
5 | 6 | using Microsoft.Extensions.DependencyInjection; |
6 | 7 | using Microsoft.Maui.Controls; |
7 | 8 | using Microsoft.Maui.DeviceTests.Stubs; |
8 | 9 | using Microsoft.Maui.Hosting; |
9 | 10 | using Xunit; |
| 11 | +using ContextThemeWrapper = Android.Views.ContextThemeWrapper; |
10 | 12 |
|
11 | 13 | namespace Microsoft.Maui.DeviceTests |
12 | 14 | { |
@@ -47,6 +49,50 @@ await InvokeOnMainThreadAsync(() => |
47 | 49 | }); |
48 | 50 | } |
49 | 51 |
|
| 52 | + [Theory] |
| 53 | + [InlineData(false, true)] |
| 54 | + [InlineData(true, false)] |
| 55 | + public async Task Material3StatusBarAppearanceUsesSurfaceColor(bool isDarkTheme, bool expectedLightAppearance) |
| 56 | + { |
| 57 | + await InvokeOnMainThreadAsync(() => |
| 58 | + { |
| 59 | + var activity = (AppCompatActivity)MauiProgramDefaults.DefaultContext; |
| 60 | + using var configuration = new Configuration(activity.Resources?.Configuration); |
| 61 | + configuration.UiMode = (configuration.UiMode & ~UiMode.NightMask) | |
| 62 | + (isDarkTheme ? UiMode.NightYes : UiMode.NightNo); |
| 63 | + using var configurationContext = activity.CreateConfigurationContext(configuration); |
| 64 | + using var themedContext = new ContextThemeWrapper( |
| 65 | + configurationContext, |
| 66 | + Resource.Style.Maui_Material3_Theme_NoActionBar); |
| 67 | + |
| 68 | + var appearance = WindowExtensions.GetStatusBarAppearance( |
| 69 | + themedContext, |
| 70 | + isLightTheme: isDarkTheme, |
| 71 | + isMaterial3: true); |
| 72 | + |
| 73 | + Assert.Equal(expectedLightAppearance, appearance); |
| 74 | + }); |
| 75 | + } |
| 76 | + |
| 77 | + [Fact] |
| 78 | + public async Task Material2StatusBarAppearanceUsesPrimaryColor() |
| 79 | + { |
| 80 | + await InvokeOnMainThreadAsync(() => |
| 81 | + { |
| 82 | + var activity = (AppCompatActivity)MauiProgramDefaults.DefaultContext; |
| 83 | + using var themedContext = new ContextThemeWrapper( |
| 84 | + activity, |
| 85 | + Resource.Style.Maui_MainTheme_NoActionBar); |
| 86 | + |
| 87 | + var appearance = WindowExtensions.GetStatusBarAppearance( |
| 88 | + themedContext, |
| 89 | + isLightTheme: true, |
| 90 | + isMaterial3: false); |
| 91 | + |
| 92 | + Assert.False(appearance); |
| 93 | + }); |
| 94 | + } |
| 95 | + |
50 | 96 |
|
51 | 97 | [Fact] |
52 | 98 | public async Task TitleSetsOnWindow() |
|
0 commit comments