Skip to content

fix(android): reset background color when it becomes transparent or is removed - #9

Merged
farfromrefug merged 1 commit into
mainfrom
fix/android-background-color-reset
Oct 8, 2026
Merged

farfromrefug merged 1 commit into
mainfrom
fix/android-background-color-reset

Conversation

@farfromrefug

Copy link
Copy Markdown

Problem

On Android, when a view can use the outline provider (no border width, image, clip-path or box shadow — e.g. a label with only a border-radius), _applyBackground only applied the background color if its native value was truthy:

  • transparent is native int 0, so setBackgroundColor was skipped and the previous ColorDrawable stayed.
  • A removed color is undefined, and the CLEAR_BACKGROUND_COLOR handling only existed in the BorderDrawable branch, so nothing was reset either.

Seen in oss-weather on Android 16: a segmented control of labels toggling modernSegment / modernSegmentSelected classes kept the selected tile background after the selection moved. Views without a border-radius also take this path, so they were affected as well.

Fix

  • Apply any defined color, including transparent.
  • When the color is removed, restore the default background (or clear the drawable fill for views with needsNativeDrawableFill, e.g. Button / ActionBar).

Verification

Scratch app on an API 36 emulator using published @akylas/nativescript 9.0.23, labels with border-radius: 8 and a background from a CSS variable, toggling classes:

before after
unselected rule background-color: transparent ColorDrawable(ffff0000) ColorDrawable(0)
no unselected background rule ColorDrawable(ffff0000) null (default)

Added two on-device tests in apps/automated/src/ui/view/view-tests.android.ts (transparent then unset on a label with border-radius; class toggle with a CSS-variable background). The automated suite was not run locally.

🤖 Generated with Claude Code

…s removed

When a view can use the outline provider (no border width, image,
clip-path or box shadow, e.g. a label with only a border-radius),
`_applyBackground` only applied the color when its native value was
truthy. `transparent` is 0 and a removed color is undefined, so the
previously set ColorDrawable was kept: toggling a class that sets a
background-color left the old color on screen.

Apply any defined color (including transparent) and restore the default
background (or clear the drawable fill) when the color is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@farfromrefug
farfromrefug merged commit 107bd84 into main Oct 8, 2026
1 of 3 checks passed
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.

1 participant