Fix #3009 (iOS default widget background color) #3104
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A bug has slipped past me in #3009. The current implementation sets
backgroundColor = None
as the default background color. The docs also mentions thatNone
ornil
gets the default background color, which is the transparent background color: https://developer.apple.com/documentation/uikit/uiview/backgroundcolor?language=objc:However, contrary to the docs, when

backgroundColor = None
is set as the default background color forUILabel
, 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 toUILabel
on initialization is notNone
/nil
or evenUIColor.clearColor
, but ratherUIExtendedGrayColorSpace 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:So, it seems contrary to the docs, setting
backgroundColor
tonil
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:
PR Checklist: