Skip to content

fix(statusbar): round alpha before converting it to hex - #2049

Merged
GitToTheHub merged 1 commit into
apache:masterfrom
thelastbackspace:fix/2048-statusbar-alpha-hex
Nov 20, 2026
Merged

GitToTheHub merged 1 commit into
apache:masterfrom
thelastbackspace:fix/2048-statusbar-alpha-hex

Conversation

@thelastbackspace

Copy link
Copy Markdown
Contributor

Platforms affected

Android

Motivation and Context

Fixes #2048

When cordova-plugin-statusbar is installed, window.statusbar.setBackgroundColor() forwards an #AARRGGBB string to StatusBar.backgroundColorByHexString. The alpha byte was 255 * alpha passed straight to toString(16), so any fractional alpha produced an invalid color: rgba(255, 0, 153, 0.5) became #7f.8ff0099, which the plugin can't parse, and the previous color stays.

Description

Round the alpha byte with Math.round before converting it to hex, as suggested in the issue. This matches the native path in SystemBarPlugin, which already does Math.round(255 * alpha).

Testing

Added spec/unit/cordova-js-src/statusbar.spec.js. There were no specs for cordova-js-src yet, so it loads statusbar.js in a vm context with stubbed window, document and cordova/exec, and checks the string passed to backgroundColorByHexString for an opaque color, 0.5 alpha (#80ff0099) and a small alpha that needs zero-padding (0.02 -> #05ff0099).

  • Before the fix, the two fractional cases fail with #7f.8ff0099 and #5.199999999999cff0099.
  • After the fix, all three pass.
  • npm run lint passes.
  • npm run unit-tests: the only failures are 5 AndroidCommandLineTools / Api listTargets specs, which fail the same way on master locally because there's no Android SDK.

I didn't test on a device.

Checklist

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

When cordova-plugin-statusbar is installed, setBackgroundColor builds an
#AARRGGBB string for StatusBar.backgroundColorByHexString. The alpha byte
was computed as 255 * alpha and passed to toString(16) without rounding,
so a fractional alpha like 0.5 produced "#7f.8ff0099", which the plugin
fails to parse. Round it first, the same way SystemBarPlugin does on the
native path.
@GitToTheHub

Copy link
Copy Markdown
Contributor

If this is AI generated add a Generated-by: <Name of Tool> <Version> trailer to the git commit message according to the ASF guidelines. Also add this in the description for the sake of completeness.

@codecov-commenter

codecov-commenter commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.20%. Comparing base (cf74435) to head (679c752).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2049   +/-   ##
=======================================
  Coverage   63.20%   63.20%           
=======================================
  Files          24       24           
  Lines        4922     4922           
=======================================
  Hits         3111     3111           
  Misses       1811     1811           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@GitToTheHub
GitToTheHub merged commit 9ceacf5 into apache:master Nov 20, 2026
15 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.

statusbar: fractional alpha produces invalid hex when forwarding to cordova-plugin-statusbar

4 participants