-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[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
[net10.0] [iOS, Windows] Fix: Switch does not use the native default on
color when OnColor is unset
#29694
Conversation
There was a problem hiding this 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; } }
on
color when OnColor is unset
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
App.WaitForElement("button1"); | ||
App.Tap("button1"); | ||
App.Tap("button2"); | ||
VerifyScreenshot(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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:
@jsuarezruiz, I have committed the pending snapshots.
385da84
to
c8262bb
Compare
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Ok we need to check how this works with the existing style from the template. |
Can we rebase ? |
c8262bb
to
1446993
Compare
@rmarinho, I have rebased the branch and resolved the conflict. |
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
state. As a result, the native defaulton
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
Screenshot
Before-Fix.mov
After-Fix.mov
Before-Fix.mov
After-Fix.mov
Before-Fix-WinUI.mp4
After-Fix-WinUI.mp4