GitToTheHub commented on code in PR #1955:
URL: https://github.com/apache/cordova-android/pull/1955#discussion_r3398178856
##########
cordova-js-src/plugin/android/statusbar.js:
##########
@@ -60,25 +60,24 @@ Object.defineProperty(statusBar, 'setBackgroundColor', {
statusBarScript.style.color = value;
var rgbStr =
window.getComputedStyle(statusBarScript).getPropertyValue('color');
- if (!rgbStr.match(/^rgb/)) { return; }
-
- var rgbVals = rgbStr.match(/\d+/g).map(function (v) { return
parseInt(v, 10); });
+ if (!rgbStr.match(/^rgb/)) {
+ return;
+ }
Review Comment:
Could this be written as a one-liner?
```js
if (!rgbStr.match(/^rgb/)) return;
```
Or should this always be encapsulated?
##########
framework/src/org/apache/cordova/SystemBarPlugin.java:
##########
@@ -121,19 +121,17 @@ private void setStatusBarVisible(final boolean visible) {
* If the supplied ARGB is invalid or fails to parse, it will silently
ignore
* the change request.
*
- * @param argbVals {A, R, G, B}
+ * @param argbVals {R, G, B, A}
*/
private void setStatusBarBackgroundColor(JSONArray argbVals) {
try {
Review Comment:
The try-catch can be removed and is not needed. A `JSONException` will not
be thrown here.
##########
cordova-js-src/plugin/android/statusbar.js:
##########
@@ -60,25 +60,24 @@ Object.defineProperty(statusBar, 'setBackgroundColor', {
statusBarScript.style.color = value;
var rgbStr =
window.getComputedStyle(statusBarScript).getPropertyValue('color');
- if (!rgbStr.match(/^rgb/)) { return; }
-
- var rgbVals = rgbStr.match(/\d+/g).map(function (v) { return
parseInt(v, 10); });
+ if (!rgbStr.match(/^rgb/)) {
+ return;
+ }
+ var rgbVals = rgbStr.match(/[\d.]+/g).map(function (v, i) { return (i
< 3) ? parseInt(v, 10) : parseFloat(v); });
if (rgbVals.length < 3) {
return;
- } else if (rgbVals.length === 3) {
- rgbVals = [255].concat(rgbVals);
}
// TODO: Use `padStart(2, '0')` once SDK 24 is dropped.
const padRgb = (val) => {
const hex = val.toString(16);
return hex.length === 1 ? '0' + hex : hex;
};
- const a = padRgb(rgbVals[0]);
- const r = padRgb(rgbVals[1]);
- const g = padRgb(rgbVals[2]);
- const b = padRgb(rgbVals[3]);
+ const r = padRgb(rgbVals[0]);
+ const g = padRgb(rgbVals[1]);
+ const b = padRgb(rgbVals[2]);
+ const a = padRgb(255 * (rgbVals[3] !== undefined ? rgbVals[3] : 1.0));
Review Comment:
Since this code is only used for `if (window.StatusBar)` this could be moved
in the code block there
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]