-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Support for Setting Switch Off State Color #25068
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
Changes from all commits
e79dbb6
e21073d
4f1673e
d784dff
df3f69f
55ff682
e26a041
fd48c53
8887789
e1a6f1b
9e65be6
19c941c
0276226
4aaf0a5
122a241
4991269
265aa78
6ef9238
c0f20b4
eb6b50d
ec64aad
07b64eb
6157b8b
eb601dc
289705b
de6888f
f027068
54baa32
3838533
7abcd52
32c9f44
760558d
3c08eb9
1b73d18
fe698b4
eb707a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <?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" | ||
| BackgroundColor="{AppThemeBinding Light=White,Dark=Black}" | ||
| x:Class="Maui.Controls.Sample.Issues.Issue15695"> | ||
|
|
||
| <StackLayout> | ||
| <Switch x:Name="mauiSwitch" | ||
| Margin="20" | ||
| IsToggled="True" | ||
| AutomationId="Switch" | ||
| OffColor="Red" | ||
| OnColor="Green" | ||
| HorizontalOptions="Center" | ||
| VerticalOptions="Center"/> | ||
| <Button Text="ToggleSwitch" | ||
| AutomationId="ToggleSwitch" | ||
| Clicked="OnButtonClicked"/> | ||
| <Button Text="Reset State" | ||
| AutomationId="ResetStateButton" | ||
| Clicked="Reset_State_Button_Clicked"/> | ||
| <Button Text="Set Null Color for off State" | ||
| AutomationId="NullOffColorButton" | ||
| Clicked="OffNullColorButtonClicked"/> | ||
| <Button Text="Change Theme" | ||
| AutomationId="ChangeThemeButton" | ||
| Clicked="ChangeThemeButtonClicked"/> | ||
|
|
||
| </StackLayout> | ||
| </ContentPage> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [XamlCompilation(XamlCompilationOptions.Compile)] | ||
| [Issue(IssueTracker.Github, 15695, "Support for Switch OFF State color", PlatformAffected.All)] | ||
| public partial class Issue15695 : ContentPage | ||
| { | ||
| public Issue15695() | ||
| { | ||
| InitializeComponent(); | ||
| } | ||
|
|
||
| private void OnButtonClicked(object sender, EventArgs e) | ||
| { | ||
| mauiSwitch.IsToggled = !mauiSwitch.IsToggled; | ||
| } | ||
|
|
||
| private void OffNullColorButtonClicked(object sender, EventArgs e) | ||
| { | ||
| mauiSwitch.OffColor = null; | ||
| } | ||
|
|
||
| private void Reset_State_Button_Clicked(object sender, EventArgs e) | ||
| { | ||
| mauiSwitch.OnColor = Colors.Green; | ||
| mauiSwitch.OffColor = Colors.Red; | ||
| mauiSwitch.IsToggled = true; | ||
| Application.Current.UserAppTheme = AppTheme.Light; | ||
| } | ||
|
|
||
| private void ChangeThemeButtonClicked(object sender, EventArgs e) | ||
| { | ||
| if (Application.Current != null) | ||
| { | ||
| if (Application.Current.RequestedTheme == AppTheme.Dark) | ||
| { | ||
| Application.Current.UserAppTheme = AppTheme.Light; | ||
| } | ||
| else | ||
| { | ||
| Application.Current.UserAppTheme = AppTheme.Dark; | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue15695 : _IssuesUITest | ||
| { | ||
| public override string Issue => "Support for Switch OFF State color"; | ||
|
|
||
| public Issue15695(TestDevice device) : base(device) | ||
| { | ||
| } | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.Switch)] | ||
| public async Task VerifySwitchOffColorAfterToggling() | ||
| { | ||
| App.WaitForElement("Switch"); | ||
| App.Tap("ResetStateButton"); | ||
| App.Tap("ToggleSwitch"); | ||
| // Wait for the switch to animate | ||
| await Task.Delay(500); | ||
| VerifyScreenshot(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pending snapshots. Already available on the latest build.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added snapshots for all platforms |
||
| } | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.Switch)] | ||
| public async Task VerifySwitchOffColorAfterTogglingDarkTheme() | ||
| { | ||
| App.WaitForElement("Switch"); | ||
| App.Tap("ResetStateButton"); | ||
| App.Tap("ChangeThemeButton"); | ||
| App.Tap("ToggleSwitch"); | ||
| // Wait for the switch to animate | ||
| await Task.Delay(500); | ||
| VerifyScreenshot(); | ||
| } | ||
|
|
||
|
|
||
| [Test] | ||
| [Category(UITestCategories.Switch)] | ||
| public async Task VerifySwitchNullColor() | ||
| { | ||
| App.WaitForElement("Switch"); | ||
| App.Tap("ResetStateButton"); | ||
| App.Tap("NullOffColorButton"); | ||
| App.Tap("ToggleSwitch"); | ||
| // Wait for the switch to animate | ||
| await Task.Delay(500); | ||
| VerifyScreenshot(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| using Microsoft.UI.Xaml.Controls; | ||
| using Windows.UI; | ||
| using Microsoft.UI.Xaml.Media; | ||
|
|
||
| namespace Microsoft.Maui.Platform | ||
| { | ||
|
|
@@ -19,20 +21,18 @@ public static void UpdateTrackColor(this ToggleSwitch toggleSwitch, ISwitch view | |
| return; | ||
| } | ||
|
|
||
| if (view.TrackColor == null) | ||
| { | ||
| return; | ||
| } | ||
| var trackColor = view.TrackColor?.ToPlatform() ?? new SolidColorBrush(Color.FromArgb(6, 0, 0, 0)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have set the default value to match the ToggleSwitchFillOff value because it is updated whenever ToggleSwitchFillOff changes. |
||
|
|
||
| if (view.TrackColor != null) | ||
| { | ||
| toggleSwitch.TryUpdateResource( | ||
| view.TrackColor.ToPlatform(), | ||
| toggleSwitch.TryUpdateResource( | ||
| trackColor, | ||
| "ToggleSwitchFillOn", | ||
| "ToggleSwitchFillOnPointerOver", | ||
| "ToggleSwitchFillOnPressed", | ||
| "ToggleSwitchFillOnDisabled"); | ||
| } | ||
| "ToggleSwitchFillOnDisabled", | ||
| "ToggleSwitchFillOff", | ||
| "ToggleSwitchFillOffPointerOver", | ||
| "ToggleSwitchFillOffPressed", | ||
| "ToggleSwitchFillOffDisabled"); | ||
| } | ||
|
|
||
| public static void UpdateThumbColor(this ToggleSwitch toggleSwitch, ISwitch view) | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.