-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[.NET 10] [iOS] Fixed: Switch OffColor resets after minimizing and reopening the app #29771
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
[.NET 10] [iOS] Fixed: Switch OffColor resets after minimizing and reopening the app #29771
Conversation
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
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 fixes an issue on iOS and Mac where the Switch OffColor resets when the app is minimized and reopened.
- Added NSNotification observers to update the switch track color when the app returns to the foreground.
- Updated the Disconnect method to remove the observers, preventing potential memory leaks.
- Introduced test cases to validate the restoration of the OffColor after the app lifecycle events.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/Core/src/Handlers/Switch/SwitchHandler.iOS.cs | Added observers to reapply OffColor on app foreground events and updated disconnect logic |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29768.cs | Added test case verifying switch OffColor restoration after app reopening |
src/Controls/tests/TestCases.HostApp/Issues/Issue29768.cs | Added UI test page to support issue 29768 testing |
void UpdateTrackOffColor(UISwitch platformView) | ||
{ | ||
DispatchQueue.MainQueue.DispatchAsync(async () => | ||
{ | ||
if (!platformView.On) | ||
{ | ||
await Task.Delay(10); // Small delay, necessary to allow UIKit to complete its internal layout and styling processes before re-applying the custom color |
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.
[nitpick] Consider extracting the delay value '10' into a named constant to improve maintainability and clarify its purpose.
void UpdateTrackOffColor(UISwitch platformView) | |
{ | |
DispatchQueue.MainQueue.DispatchAsync(async () => | |
{ | |
if (!platformView.On) | |
{ | |
await Task.Delay(10); // Small delay, necessary to allow UIKit to complete its internal layout and styling processes before re-applying the custom color | |
const int UIKitStylingDelayMilliseconds = 10; // Small delay to allow UIKit to complete internal layout and styling processes | |
void UpdateTrackOffColor(UISwitch platformView) | |
{ | |
DispatchQueue.MainQueue.DispatchAsync(async () => | |
{ | |
if (!platformView.On) | |
{ | |
await Task.Delay(UIKitStylingDelayMilliseconds); |
Copilot uses AI. Check for mistakes.
How does this relates to #29694 ? |
@rmarinho, this change is not directly related to #29694, as it addresses a different issue. Issue #29694 concerns the default On color not being retained, whereas this change fixes a problem where the Off color is not retained when the app is minimized and reopened |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
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
Description of Change
Issues Fixed
Fixes #29768
Tested the behaviour in the following platforms
Screenshot
Before-Fix-iOS.mov
After-Fix-iOS.mov
Before-Fix-Mac.mov
After-Fix-Mac.mov