1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const Styles_1 = require("./Styles");
|
4 | const Colors_1 = require("./Colors");
|
5 | const WarningAggregator_1 = require("../WarningAggregator");
|
6 | const NAVIGATION_BAR_COLOR = 'navigationBarColor';
|
7 | const WINDOW_LIGHT_NAVIGATION_BAR = 'android:windowLightNavigationBar';
|
8 | function getNavigationBarImmersiveMode(config) {
|
9 | var _a;
|
10 | return ((_a = config.androidNavigationBar) === null || _a === void 0 ? void 0 : _a.visible) || null;
|
11 | }
|
12 | exports.getNavigationBarImmersiveMode = getNavigationBarImmersiveMode;
|
13 | function getNavigationBarColor(config) {
|
14 | var _a;
|
15 | return ((_a = config.androidNavigationBar) === null || _a === void 0 ? void 0 : _a.backgroundColor) || null;
|
16 | }
|
17 | exports.getNavigationBarColor = getNavigationBarColor;
|
18 | function getNavigationBarStyle(config) {
|
19 | var _a;
|
20 | return ((_a = config.androidNavigationBar) === null || _a === void 0 ? void 0 : _a.barStyle) || 'light-content';
|
21 | }
|
22 | exports.getNavigationBarStyle = getNavigationBarStyle;
|
23 | async function setNavigationBarConfig(config, projectDirectory) {
|
24 | const immersiveMode = getNavigationBarImmersiveMode(config);
|
25 | const hexString = getNavigationBarColor(config);
|
26 | const barStyle = getNavigationBarStyle(config);
|
27 | const stylesPath = await Styles_1.getProjectStylesXMLPathAsync(projectDirectory);
|
28 | const colorsPath = await Colors_1.getProjectColorsXMLPathAsync(projectDirectory);
|
29 | if (!colorsPath || !stylesPath) {
|
30 | return false;
|
31 | }
|
32 | let stylesJSON = await Styles_1.readStylesXMLAsync(stylesPath);
|
33 | let colorsJSON = await Colors_1.readColorsXMLAsync(colorsPath);
|
34 | if (immersiveMode) {
|
35 |
|
36 | WarningAggregator_1.addWarningAndroid('androidNavigationBar.visible', 'Hiding the navigation bar must be done programmatically. Refer to the Android documentation - https://developer.android.com/training/system-ui/immersive - for instructions.');
|
37 | }
|
38 | if (hexString) {
|
39 | let colorItemToAdd = [{ _: hexString, $: { name: NAVIGATION_BAR_COLOR } }];
|
40 | colorsJSON = Colors_1.setColorItem(colorItemToAdd, colorsJSON);
|
41 | let styleItemToAdd = [
|
42 | { _: `@color/${NAVIGATION_BAR_COLOR}`, $: { name: `android:${NAVIGATION_BAR_COLOR}` } },
|
43 | ];
|
44 | stylesJSON = Styles_1.setStylesItem(styleItemToAdd, stylesJSON);
|
45 | }
|
46 | if (barStyle === 'dark-content') {
|
47 | let navigationBarStyleItem = [
|
48 | { _: 'true', $: { name: WINDOW_LIGHT_NAVIGATION_BAR } },
|
49 | ];
|
50 | stylesJSON = Styles_1.setStylesItem(navigationBarStyleItem, stylesJSON);
|
51 | }
|
52 | try {
|
53 | await Colors_1.writeColorsXMLAsync(colorsPath, colorsJSON);
|
54 | await Styles_1.writeStylesXMLAsync(stylesPath, stylesJSON);
|
55 | }
|
56 | catch (e) {
|
57 | throw new Error(`Error setting Android navigation bar color. Cannot write colors.xml to ${colorsPath}, or styles.xml to ${stylesPath}.`);
|
58 | }
|
59 | return true;
|
60 | }
|
61 | exports.setNavigationBarConfig = setNavigationBarConfig;
|
62 |
|
\ | No newline at end of file |