Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e79dbb6
fix added
devanathan-vaithiyanathan Oct 3, 2024
e21073d
test added
devanathan-vaithiyanathan Oct 4, 2024
4f1673e
unshipped file changes reverted
devanathan-vaithiyanathan Oct 4, 2024
d784dff
attributes added
devanathan-vaithiyanathan Oct 4, 2024
df3f69f
test case changes added
devanathan-vaithiyanathan Oct 7, 2024
55ff682
ui test changes added
devanathan-vaithiyanathan Oct 7, 2024
e26a041
test case changes added
devanathan-vaithiyanathan Oct 7, 2024
fd48c53
code behind click event removed
devanathan-vaithiyanathan Oct 7, 2024
8887789
UI test files name changed
devanathan-vaithiyanathan Oct 7, 2024
e1a6f1b
API changes and test case changes added
devanathan-vaithiyanathan Oct 11, 2024
9e65be6
modified test sample
devanathan-vaithiyanathan Oct 11, 2024
19c941c
platform condition added in script file
devanathan-vaithiyanathan Oct 11, 2024
0276226
fix added
devanathan-vaithiyanathan Oct 3, 2024
4aaf0a5
test added
devanathan-vaithiyanathan Oct 4, 2024
122a241
unshipped file changes reverted
devanathan-vaithiyanathan Oct 4, 2024
4991269
attributes added
devanathan-vaithiyanathan Oct 4, 2024
265aa78
test case changes added
devanathan-vaithiyanathan Oct 7, 2024
6ef9238
ui test changes added
devanathan-vaithiyanathan Oct 7, 2024
c0f20b4
test case changes added
devanathan-vaithiyanathan Oct 7, 2024
eb6b50d
code behind click event removed
devanathan-vaithiyanathan Oct 7, 2024
ec64aad
UI test files name changed
devanathan-vaithiyanathan Oct 7, 2024
07b64eb
API changes and test case changes added
devanathan-vaithiyanathan Oct 11, 2024
6157b8b
modified test sample
devanathan-vaithiyanathan Oct 11, 2024
eb601dc
platform condition added in script file
devanathan-vaithiyanathan Oct 11, 2024
289705b
OffColor API added in tizen platform
devanathan-vaithiyanathan Oct 21, 2024
de6888f
Merge branch 'Fix-7673' of https://github.com/devanathan-vaithiyanath…
devanathan-vaithiyanathan Oct 21, 2024
f027068
Merge branch 'main' of https://github.com/devanathan-vaithiyanathan/m…
devanathan-vaithiyanathan Oct 25, 2024
54baa32
sender parameter nullable removed
devanathan-vaithiyanathan Oct 28, 2024
3838533
simplified a test case
devanathan-vaithiyanathan Oct 29, 2024
7abcd52
test sample changes
devanathan-vaithiyanathan Dec 2, 2024
32c9f44
new snapshot added
devanathan-vaithiyanathan Dec 9, 2024
760558d
script changes
devanathan-vaithiyanathan Dec 18, 2024
3c08eb9
Merge remote-tracking branch 'upstream/main' into Fix-7673
devanathan-vaithiyanathan Jan 16, 2025
1b73d18
added snapshots for mac
devanathan-vaithiyanathan Jan 16, 2025
fe698b4
Merge remote-tracking branch 'upstream/main' into Fix-7673
devanathan-vaithiyanathan Jan 29, 2025
eb707a8
Merge branch 'net10.0' into Fix-7673
devanathan-vaithiyanathan Feb 10, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ static readonly Microsoft.Maui.Controls.TitleBar.TitleProperty -> Microsoft.Maui
static readonly Microsoft.Maui.Controls.TitleBar.TrailingContentProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Window.TitleBarProperty -> Microsoft.Maui.Controls.BindableProperty!
virtual Microsoft.Maui.Controls.Application.ActivateWindow(Microsoft.Maui.Controls.Window! window) -> void
~static readonly Microsoft.Maui.Controls.Switch.OffColorProperty -> Microsoft.Maui.Controls.BindableProperty
~Microsoft.Maui.Controls.Switch.OffColor.get -> Microsoft.Maui.Graphics.Color
~Microsoft.Maui.Controls.Switch.OffColor.set -> void
~Microsoft.Maui.Controls.SearchBar.SearchIconColor.get -> Microsoft.Maui.Graphics.Color
~Microsoft.Maui.Controls.SearchBar.SearchIconColor.set -> void
~static readonly Microsoft.Maui.Controls.SearchBar.SearchIconColorProperty -> Microsoft.Maui.Controls.BindableProperty
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ virtual Microsoft.Maui.Controls.Handlers.Items2.ItemsViewController2<TItemsView>
virtual Microsoft.Maui.Controls.Handlers.Items2.ItemsViewDelegator2<TItemsView, TViewController>.GetVisibleItemsIndex() -> (bool VisibleItems, int First, int Center, int Last)
virtual Microsoft.Maui.Controls.Handlers.Items2.ItemsViewHandler2<TItemsView>.UpdateLayout() -> void
override Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.MovedToWindow() -> void
~static readonly Microsoft.Maui.Controls.Switch.OffColorProperty -> Microsoft.Maui.Controls.BindableProperty
~Microsoft.Maui.Controls.Switch.OffColor.get -> Microsoft.Maui.Graphics.Color
~Microsoft.Maui.Controls.Switch.OffColor.set -> void
~Microsoft.Maui.Controls.SearchBar.SearchIconColor.get -> Microsoft.Maui.Graphics.Color
~Microsoft.Maui.Controls.SearchBar.SearchIconColor.set -> void
~static readonly Microsoft.Maui.Controls.SearchBar.SearchIconColorProperty -> Microsoft.Maui.Controls.BindableProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ virtual Microsoft.Maui.Controls.Handlers.Items2.ItemsViewController2<TItemsView>
virtual Microsoft.Maui.Controls.Handlers.Items2.ItemsViewDelegator2<TItemsView, TViewController>.GetVisibleItemsIndex() -> (bool VisibleItems, int First, int Center, int Last)
virtual Microsoft.Maui.Controls.Handlers.Items2.ItemsViewHandler2<TItemsView>.UpdateLayout() -> void
override Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.MovedToWindow() -> void
~static readonly Microsoft.Maui.Controls.Switch.OffColorProperty -> Microsoft.Maui.Controls.BindableProperty
~Microsoft.Maui.Controls.Switch.OffColor.get -> Microsoft.Maui.Graphics.Color
~Microsoft.Maui.Controls.Switch.OffColor.set -> void
~Microsoft.Maui.Controls.SearchBar.SearchIconColor.get -> Microsoft.Maui.Graphics.Color
~Microsoft.Maui.Controls.SearchBar.SearchIconColor.set -> void
~static readonly Microsoft.Maui.Controls.SearchBar.SearchIconColorProperty -> Microsoft.Maui.Controls.BindableProperty
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ static readonly Microsoft.Maui.Controls.TitleBar.TitleProperty -> Microsoft.Maui
static readonly Microsoft.Maui.Controls.TitleBar.TrailingContentProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Window.TitleBarProperty -> Microsoft.Maui.Controls.BindableProperty!
virtual Microsoft.Maui.Controls.Application.ActivateWindow(Microsoft.Maui.Controls.Window! window) -> void
~static readonly Microsoft.Maui.Controls.Switch.OffColorProperty -> Microsoft.Maui.Controls.BindableProperty
~Microsoft.Maui.Controls.Switch.OffColor.get -> Microsoft.Maui.Graphics.Color
~Microsoft.Maui.Controls.Switch.OffColor.set -> void
~Microsoft.Maui.Controls.SearchBar.SearchIconColor.get -> Microsoft.Maui.Graphics.Color
~Microsoft.Maui.Controls.SearchBar.SearchIconColor.set -> void
~static readonly Microsoft.Maui.Controls.SearchBar.SearchIconColorProperty -> Microsoft.Maui.Controls.BindableProperty
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ static readonly Microsoft.Maui.Controls.TitleBar.TitleProperty -> Microsoft.Maui
static readonly Microsoft.Maui.Controls.TitleBar.TrailingContentProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Window.TitleBarProperty -> Microsoft.Maui.Controls.BindableProperty!
virtual Microsoft.Maui.Controls.Application.ActivateWindow(Microsoft.Maui.Controls.Window! window) -> void
~static readonly Microsoft.Maui.Controls.Switch.OffColorProperty -> Microsoft.Maui.Controls.BindableProperty
~Microsoft.Maui.Controls.Switch.OffColor.get -> Microsoft.Maui.Graphics.Color
~Microsoft.Maui.Controls.Switch.OffColor.set -> void
~Microsoft.Maui.Controls.SearchBar.SearchIconColor.get -> Microsoft.Maui.Graphics.Color
~Microsoft.Maui.Controls.SearchBar.SearchIconColor.set -> void
~static readonly Microsoft.Maui.Controls.SearchBar.SearchIconColorProperty -> Microsoft.Maui.Controls.BindableProperty
3 changes: 3 additions & 0 deletions src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ static readonly Microsoft.Maui.Controls.TitleBar.TitleProperty -> Microsoft.Maui
static readonly Microsoft.Maui.Controls.TitleBar.TrailingContentProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Window.TitleBarProperty -> Microsoft.Maui.Controls.BindableProperty!
virtual Microsoft.Maui.Controls.Application.ActivateWindow(Microsoft.Maui.Controls.Window! window) -> void
~static readonly Microsoft.Maui.Controls.Switch.OffColorProperty -> Microsoft.Maui.Controls.BindableProperty
~Microsoft.Maui.Controls.Switch.OffColor.get -> Microsoft.Maui.Graphics.Color
~Microsoft.Maui.Controls.Switch.OffColor.set -> void
~Microsoft.Maui.Controls.SearchBar.SearchIconColor.get -> Microsoft.Maui.Graphics.Color
~Microsoft.Maui.Controls.SearchBar.SearchIconColor.set -> void
~static readonly Microsoft.Maui.Controls.SearchBar.SearchIconColorProperty -> Microsoft.Maui.Controls.BindableProperty
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ static readonly Microsoft.Maui.Controls.TitleBar.TitleProperty -> Microsoft.Maui
static readonly Microsoft.Maui.Controls.TitleBar.TrailingContentProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.Window.TitleBarProperty -> Microsoft.Maui.Controls.BindableProperty!
virtual Microsoft.Maui.Controls.Application.ActivateWindow(Microsoft.Maui.Controls.Window! window) -> void
~static readonly Microsoft.Maui.Controls.Switch.OffColorProperty -> Microsoft.Maui.Controls.BindableProperty
~Microsoft.Maui.Controls.Switch.OffColor.get -> Microsoft.Maui.Graphics.Color
~Microsoft.Maui.Controls.Switch.OffColor.set -> void
~Microsoft.Maui.Controls.SearchBar.SearchIconColor.get -> Microsoft.Maui.Graphics.Color
~Microsoft.Maui.Controls.SearchBar.SearchIconColor.set -> void
~static readonly Microsoft.Maui.Controls.SearchBar.SearchIconColorProperty -> Microsoft.Maui.Controls.BindableProperty
30 changes: 24 additions & 6 deletions src/Controls/src/Core/Switch/Switch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public partial class Switch : View, IElementConfiguration<Switch>, ISwitch
((IView)bindable)?.Handler?.UpdateValue(nameof(ISwitch.TrackColor));
});

/// <summary>Bindable property for <see cref="OffColor"/>.</summary>
public static readonly BindableProperty OffColorProperty = BindableProperty.Create(nameof(OffColor), typeof(Color), typeof(Switch), null,
propertyChanged: (bindable, oldValue, newValue) =>
{
((IView)bindable)?.Handler?.UpdateValue(nameof(ISwitch.TrackColor));
});

/// <summary>Bindable property for <see cref="ThumbColor"/>.</summary>
public static readonly BindableProperty ThumbColorProperty = BindableProperty.Create(nameof(ThumbColor), typeof(Color), typeof(Switch), null);

Expand All @@ -41,6 +48,17 @@ public Color OnColor
set { SetValue(OnColorProperty, value); }
}

/// <summary>
/// Gets or sets the color of the toggle switch's track when it is in the off state.
/// If not set, the default color will be used for the off-track appearance.
/// </summary>
public Color OffColor
{
get { return (Color) GetValue(OffColorProperty); }
set { SetValue(OffColorProperty, value); }
}


/// <include file="../../docs/Microsoft.Maui.Controls/Switch.xml" path="//Member[@MemberName='ThumbColor']/Docs/*" />
public Color ThumbColor
{
Expand Down Expand Up @@ -93,14 +111,14 @@ Color ISwitch.TrackColor
{
get
{
#if WINDOWS
return OnColor;
#else
if (IsToggled)
{
return OnColor;

return null;
#endif
}
else
{
return OffColor;
}
}
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue15695.xaml
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>
44 changes: 44 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue15695.xaml.cs
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;
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
@@ -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();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pending snapshots. Already available on the latest build.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 2 additions & 5 deletions src/Core/src/Platform/Android/SwitchExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ public static void UpdateTrackColor(this ASwitch aSwitch, ISwitch view)
{
var trackColor = view.TrackColor;

if (aSwitch.Checked)
{
if (trackColor != null)
aSwitch.TrackDrawable?.SetColorFilter(trackColor, FilterMode.SrcAtop);
}
if (trackColor is not null)
aSwitch.TrackDrawable?.SetColorFilter(trackColor, FilterMode.SrcAtop);
else
aSwitch.TrackDrawable?.ClearColorFilter();
}
Expand Down
20 changes: 10 additions & 10 deletions src/Core/src/Platform/Windows/SwitchExtensions.cs
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
{
Expand All @@ -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));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why use Color.FromArgb(6, 0, 0, 0)? Ideally, we could use a resource, the color used by default by the platform control (like ToggleSwitchContainerBackground).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

screenshot


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)
Expand Down
13 changes: 7 additions & 6 deletions src/Core/src/Platform/iOS/SwitchExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ public static void UpdateTrackColor(this UISwitch uiSwitch, ISwitch view)
if (uIView is null)
return;

if (!view.IsOn)
if (view.TrackColor is not null)
{
// iOS 13+ uses the UIColor.SecondarySystemFill to support Light and Dark mode
// else, use the RGBA equivalent of UIColor.SecondarySystemFill in Light mode
uIView.BackgroundColor = OperatingSystem.IsIOSVersionAtLeast(13) ? UIColor.SecondarySystemFill : DefaultBackgroundColor;
uiSwitch.OnTintColor = view.TrackColor.ToPlatform();
uIView.BackgroundColor = uiSwitch.OnTintColor;
}

else if (view.TrackColor is not null)
else
{
uiSwitch.OnTintColor = view.TrackColor.ToPlatform();
// iOS 13+ uses the UIColor.SecondarySystemFill to support Light and Dark mode
// else, use the RGBA equivalent of UIColor.SecondarySystemFill in Light mode
uiSwitch.OnTintColor = OperatingSystem.IsIOSVersionAtLeast(13) ? UIColor.SecondarySystemFill : DefaultBackgroundColor;
uIView.BackgroundColor = uiSwitch.OnTintColor;
}
}
Expand Down