Skip to content

[net10.0] [iOS, Windows] Fix: Switch does not use the native default on color when OnColor is unset #29694

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

Merged
merged 7 commits into from
Jun 13, 2025

Conversation

Tamilarasan-Paranthaman
Copy link
Contributor

@Tamilarasan-Paranthaman Tamilarasan-Paranthaman commented May 27, 2025

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Root Cause of the issue

  • On both iOS and Windows, when OnColor is set to null, we assign a transparent color for the switch's on state. As a result, the native default on color is not applied.

Description of Change

  • Updated the logic to properly clear the color by setting it to null and removing the corresponding color keys on iOS and Windows.

  • This ensures that when OnColor is not explicitly set, the native default on color is applied to the Switch as expected.

Issues Fixed

Fixes #29693

Tested the behaviour in the following platforms

  • iOS
  • Mac
  • Android
  • Windows

Screenshot

Platform Before Fix After Fix
iOS
Before-Fix.mov
After-Fix.mov
Catalyst
Before-Fix.mov
After-Fix.mov
Windows
Before-Fix-WinUI.mp4
After-Fix-WinUI.mp4

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label May 27, 2025
@Tamilarasan-Paranthaman Tamilarasan-Paranthaman marked this pull request as ready for review May 27, 2025 14:48
@Copilot Copilot AI review requested due to automatic review settings May 27, 2025 14:48
@Tamilarasan-Paranthaman Tamilarasan-Paranthaman requested a review from a team as a code owner May 27, 2025 14:48
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses an issue with the Switch control not using the native default "on" color when OnColor is unset on iOS and Windows. The changes update the native platform implementations for iOS, Windows, and Android to correctly clear or assign the color based on the switch state, and add UI tests to validate the behavior.

  • Updated iOS SwitchExtensions to correctly clear OnTintColor and track subview background when needed.
  • Revised Windows implementation to remove custom resource keys when no track color is provided.
  • Improved null-checks in Android and added UI tests for issue #29693.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Core/src/Platform/iOS/SwitchExtensions.cs Updated handling of OnTintColor and track subview background for proper native default color support.
src/Core/src/Platform/Windows/SwitchExtensions.cs Modified resource key handling to remove explicit color settings when track color is unset.
src/Core/src/Platform/Android/SwitchExtensions.cs Adjusted null-checking for track and thumb colors.
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29693.cs Added automated test to verify default switch colors.
src/Controls/tests/TestCases.HostApp/Issues/Issue29693.cs Provided a sample page to manually test the Switch default color behavior.
Comments suppressed due to low confidence (1)

src/Core/src/Platform/iOS/SwitchExtensions.cs:42

  • [nitpick] Consider adding a comment to clarify why uiSwitch.OnTintColor is not reset in the off branch, noting that it is intentionally left unchanged because it only affects the switch when it is on. This would aid future maintainers in understanding the design decision.
else { if (trackColor is not null) { uIView.BackgroundColor = trackColor; } else { var fallbackColor = OperatingSystem.IsIOSVersionAtLeast(13) ? UIColor.SecondarySystemFill : DefaultBackgroundColor; uIView.BackgroundColor = fallbackColor; } }

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label May 27, 2025
@Tamilarasan-Paranthaman Tamilarasan-Paranthaman changed the title [net10.0] [iOS, Windows] Fix: Switch does not use the native default "on" color when OnColor is unset [net10.0] [iOS, Windows] Fix: Switch does not use the native default on color when OnColor is unset May 27, 2025
@rmarinho
Copy link
Member

Seems Android also behaves like that so I think is fine to take this change to be coherent.

Screenshot_1748370871

@rmarinho
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

rmarinho
rmarinho previously approved these changes May 27, 2025
App.WaitForElement("button1");
App.Tap("button1");
App.Tap("button2");
VerifyScreenshot();
Copy link
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 in the latest build. Could you commit the images?
Example:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pending snapshots already available in the latest build. Could you commit the images? Example: image

@jsuarezruiz, I have committed the pending snapshots.

@rmarinho
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@rmarinho
Copy link
Member

Ok we need to check how this works with the existing style from the template.

@rmarinho
Copy link
Member

Can we rebase ?

@Tamilarasan-Paranthaman
Copy link
Contributor Author

Can we rebase ?

@rmarinho, I have rebased the branch and resolved the conflict.

@rmarinho rmarinho merged commit c92932f into dotnet:net10.0 Jun 13, 2025
129 checks passed
@github-project-automation github-project-automation bot moved this from Changes Requested to Done in MAUI SDK Ongoing Jun 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-switch Switch community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/ios platform/windows
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants