UNPKG

3.06 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const Styles_1 = require("./Styles");
4const Colors_1 = require("./Colors");
5const WarningAggregator_1 = require("../WarningAggregator");
6const NAVIGATION_BAR_COLOR = 'navigationBarColor';
7const WINDOW_LIGHT_NAVIGATION_BAR = 'android:windowLightNavigationBar';
8function getNavigationBarImmersiveMode(config) {
9 var _a;
10 return ((_a = config.androidNavigationBar) === null || _a === void 0 ? void 0 : _a.visible) || null;
11}
12exports.getNavigationBarImmersiveMode = getNavigationBarImmersiveMode;
13function getNavigationBarColor(config) {
14 var _a;
15 return ((_a = config.androidNavigationBar) === null || _a === void 0 ? void 0 : _a.backgroundColor) || null;
16}
17exports.getNavigationBarColor = getNavigationBarColor;
18function getNavigationBarStyle(config) {
19 var _a;
20 return ((_a = config.androidNavigationBar) === null || _a === void 0 ? void 0 : _a.barStyle) || 'light-content';
21}
22exports.getNavigationBarStyle = getNavigationBarStyle;
23async 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 // Immersive mode needs to be set programatically
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}
61exports.setNavigationBarConfig = setNavigationBarConfig;
62//# sourceMappingURL=NavigationBar.js.map
\No newline at end of file