UNPKG

2.04 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const Styles_1 = require("./Styles");
4const Colors_1 = require("./Colors");
5const ANDROID_WINDOW_BACKGROUND = 'android:windowBackground';
6const WINDOW_BACKGROUND_COLOR = 'activityBackground';
7function 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}
16exports.getRootViewBackgroundColor = getRootViewBackgroundColor;
17async 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}
46exports.setRootViewBackgroundColor = setRootViewBackgroundColor;
47//# sourceMappingURL=RootViewBackgroundColor.js.map
\No newline at end of file