breautek commented on issue #1967:
URL:
https://github.com/apache/cordova-android/issues/1967#issuecomment-4908298099
> Yes, exactly. I'm not sure if it's the right approach, but I think the
simplest solution would be to add a new option that prevents the built-in
plugin from modifying the status bar.
Yah maybe -- but I think that would have to be a conditional. I think the
builtin implementation is fine if the app isn't relying on any external
statusbar plugin. But if the statusbar plugin is used, then statusbar
management should delegated to it. Just not sure if there any other negative
repercussions that will cause.
In the meantime though, you can use this hook:
<details>
<summary>Hook Code</summary>
```javascript
const FileSystem = require('fs');
const Path = require('path');
// The colour to force cdv_background_color to across all resource variants.
const TARGET_COLOR = '#000000';
// cordova-android generates cdv_colors.xml in several resource-qualifier
// directories. Each may define cdv_background_color with a different value
// (light / dark / Android 14+ dynamic), so we rewrite them all.
const VARIANT_DIRS = [
'values',
'values-night',
'values-v34',
'values-night-v34'
];
// Matches: <color name="cdv_background_color">ANYTHING</color>
// - handles single/double quotes and arbitrary inner whitespace
// - captures the opening tag so we can preserve its exact formatting
const COLOR_REGEX =
/(<color\s+name=(?:"|')cdv_background_color(?:"|')\s*>)([\s\S]*?)(<\/color>)/g;
module.exports = function (context) {
const projectRoot = (context && context.opts &&
context.opts.projectRoot) || process.cwd();
const resRoot = Path.join(projectRoot, 'platforms', 'android', 'app',
'src', 'main', 'res');
VARIANT_DIRS.forEach((dir) => {
const file = Path.join(resRoot, dir, 'cdv_colors.xml');
if (!FileSystem.existsSync(file)) {
return;
}
const original = FileSystem.readFileSync(file, 'utf8');
const updated = original.replace(COLOR_REGEX, `$1${TARGET_COLOR}$3`);
if (updated !== original) {
FileSystem.writeFileSync(file, updated, 'utf8');
console.log(`[overrideCdvBackgroundColor] set
cdv_background_color=${TARGET_COLOR} in ${Path.join('res', dir,
'cdv_colors.xml')}`);
}
});
};
```
</details>
and reference it in your `config.xml`:
```xml
<hook type="after_prepare" src="path/to/hook.js" />
```
The `edit-config` I guess doesn't do replacement of node text, just node
attributes -- so it isn't actually usable to replace the color content. This
allows the app to choose a status bar appearance based on the target color --
if it's a darker color it will produce a light appearance for constrast and
vice versa.
Then you should be able to use the old statusbar plugin API to control the
appearance style during runtime.
For a proper fix moving forward I'll probably have to talk to some people
but hopefully the above could be a stopgap solution for the time being.
--
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]