Skip to content
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

Fix #3009 (iOS default widget background color) #3104

Merged
merged 2 commits into from
Jan 14, 2025

Conversation

proneon267
Copy link
Contributor

@proneon267 proneon267 commented Jan 13, 2025

A bug has slipped past me in #3009. The current implementation sets backgroundColor = None as the default background color. The docs also mentions that None or nil gets the default background color, which is the transparent background color: https://developer.apple.com/documentation/uikit/uiview/backgroundcolor?language=objc:

Changes to this property can be animated. The default value is nil, which results in a transparent background color.

However, contrary to the docs, when backgroundColor = None is set as the default background color for UILabel, then it displays a black background color instead:

On further testing, I have found that the default background color(default value of native.backgroundColor) which the system assigns to UILabel on initialization is not None/nil or even UIColor.clearColor, but rather UIExtendedGrayColorSpace 0 0.

I couldn't find any official docs for UIExtendedGrayColorSpace 0 0, the best I could get was: https://stackoverflow.com/a/45491411, which suggests that:

UIExtendedGrayColorSpace 0 0 is "clear"

So, it seems contrary to the docs, setting backgroundColor to nil doesn't always set it to the widget's system assigned default background color. So, the best option is to cache the system assigned widget default background color during the widget initialization and use that as the default reset background color, in order to avoid any similar background color bugs.

I have tested this PR with both light mode and dark mode, and it works correctly even when the system theme is changed while the app is running:

Light Mode to Dark Mode Screenshot 2025-01-13 at 10 06 01 AM Screenshot 2025-01-13 at 10 08 11 AM
Dark Mode to Light Mode Screenshot 2025-01-13 at 10 09 12 AM Screenshot 2025-01-13 at 10 10 09 AM

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

Nice catch.

I'd feel a lot better if there was a way to automate testing of this, but I appreciate that this is one of those areas where the property we're trying to test is inherently visual.

@freakboy3742 freakboy3742 merged commit 8a02735 into beeware:main Jan 14, 2025
41 checks passed
@proneon267 proneon267 deleted the iOS_label_background_fix branch January 21, 2025 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants