1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const Styles_1 = require("./Styles");
|
4 | const Colors_1 = require("./Colors");
|
5 | const ANDROID_WINDOW_BACKGROUND = 'android:windowBackground';
|
6 | const WINDOW_BACKGROUND_COLOR = 'activityBackground';
|
7 | function getRootViewBackgroundColor(config) {
|
8 | if (config.android && config.android.backgroundColor) {
|
9 | return config.android.backgroundColor;
|
10 | }
|
11 | if (config.backgroundColor) {
|
12 | return config.backgroundColor;
|
13 | }
|
14 | return null;
|
15 | }
|
16 | exports.getRootViewBackgroundColor = getRootViewBackgroundColor;
|
17 | async function setRootViewBackgroundColor(config, projectDirectory) {
|
18 | let hexString = getRootViewBackgroundColor(config);
|
19 | if (!hexString) {
|
20 | return false;
|
21 | }
|
22 | const stylesPath = await Styles_1.getProjectStylesXMLPathAsync(projectDirectory);
|
23 | const colorsPath = await Colors_1.getProjectColorsXMLPathAsync(projectDirectory);
|
24 | if (!colorsPath || !stylesPath) {
|
25 | return false;
|
26 | }
|
27 | let stylesJSON = await Styles_1.readStylesXMLAsync(stylesPath);
|
28 | let colorsJSON = await Colors_1.readColorsXMLAsync(colorsPath);
|
29 | let colorItemToAdd = [{ _: '', $: { name: '' } }];
|
30 | let styleItemToAdd = [{ _: '', $: { name: '' } }];
|
31 | colorItemToAdd[0]._ = hexString;
|
32 | colorItemToAdd[0].$.name = WINDOW_BACKGROUND_COLOR;
|
33 | styleItemToAdd[0]._ = `@color/${WINDOW_BACKGROUND_COLOR}`;
|
34 | styleItemToAdd[0].$.name = ANDROID_WINDOW_BACKGROUND;
|
35 | colorsJSON = Colors_1.setColorItem(colorItemToAdd, colorsJSON);
|
36 | stylesJSON = Styles_1.setStylesItem(styleItemToAdd, stylesJSON);
|
37 | try {
|
38 | await Colors_1.writeColorsXMLAsync(colorsPath, colorsJSON);
|
39 | await Styles_1.writeStylesXMLAsync(stylesPath, stylesJSON);
|
40 | }
|
41 | catch (e) {
|
42 | throw new Error(`Error setting Android root view background color. Cannot write new styles.xml to ${stylesPath}.`);
|
43 | }
|
44 | return true;
|
45 | }
|
46 | exports.setRootViewBackgroundColor = setRootViewBackgroundColor;
|
47 |
|
\ | No newline at end of file |