1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const Styles_1 = require("./Styles");
|
4 | const Colors_1 = require("./Colors");
|
5 | const COLOR_PRIMARY_DARK_KEY = 'colorPrimaryDark';
|
6 | const WINDOW_TRANSLUCENT_STATUS = 'android:windowTranslucentStatus';
|
7 | const WINDOW_LIGHT_STATUS_BAR = 'android:windowLightStatusBar';
|
8 | function getStatusBarColor(config) {
|
9 | var _a;
|
10 | return ((_a = config.androidStatusBar) === null || _a === void 0 ? void 0 : _a.backgroundColor) || 'translucent';
|
11 | }
|
12 | exports.getStatusBarColor = getStatusBarColor;
|
13 | function getStatusBarStyle(config) {
|
14 | var _a;
|
15 | return ((_a = config.androidStatusBar) === null || _a === void 0 ? void 0 : _a.barStyle) || 'light-content';
|
16 | }
|
17 | exports.getStatusBarStyle = getStatusBarStyle;
|
18 | async function setStatusBarConfig(config, projectDirectory) {
|
19 | let hexString = getStatusBarColor(config);
|
20 | let statusBarStyle = getStatusBarStyle(config);
|
21 | const stylesPath = await Styles_1.getProjectStylesXMLPathAsync(projectDirectory);
|
22 | const colorsPath = await Colors_1.getProjectColorsXMLPathAsync(projectDirectory);
|
23 | if (!colorsPath || !stylesPath) {
|
24 | return false;
|
25 | }
|
26 | let stylesJSON = await Styles_1.readStylesXMLAsync(stylesPath);
|
27 | let colorsJSON = await Colors_1.readColorsXMLAsync(colorsPath);
|
28 | let styleItemToAdd = [{ _: '', $: { name: '' } }];
|
29 | if (hexString === 'translucent') {
|
30 |
|
31 | styleItemToAdd[0]._ = 'true';
|
32 | styleItemToAdd[0].$.name = WINDOW_TRANSLUCENT_STATUS;
|
33 | }
|
34 | else {
|
35 |
|
36 | let colorItemToAdd = [{ _: hexString, $: { name: COLOR_PRIMARY_DARK_KEY } }];
|
37 | colorsJSON = Colors_1.setColorItem(colorItemToAdd, colorsJSON);
|
38 | styleItemToAdd[0]._ = `@color/${COLOR_PRIMARY_DARK_KEY}`;
|
39 | styleItemToAdd[0].$.name = COLOR_PRIMARY_DARK_KEY;
|
40 | }
|
41 |
|
42 | if (statusBarStyle === 'dark-content') {
|
43 | let statusBarStyleItem = [{ _: 'true', $: { name: WINDOW_LIGHT_STATUS_BAR } }];
|
44 | stylesJSON = Styles_1.setStylesItem(statusBarStyleItem, stylesJSON);
|
45 | }
|
46 | stylesJSON = Styles_1.setStylesItem(styleItemToAdd, stylesJSON);
|
47 | try {
|
48 | await Colors_1.writeColorsXMLAsync(colorsPath, colorsJSON);
|
49 | await Styles_1.writeStylesXMLAsync(stylesPath, stylesJSON);
|
50 | }
|
51 | catch (e) {
|
52 | throw new Error(`Error setting Android status bar config. Cannot write colors.xml to ${colorsPath}, or styles.xml to ${stylesPath}.`);
|
53 | }
|
54 | return true;
|
55 | }
|
56 | exports.setStatusBarConfig = setStatusBarConfig;
|
57 |
|
\ | No newline at end of file |