@react-native-tvos/config-tv
Version:
Config plugin to reconfigure native directories for Apple TV and Android TV development if needed
58 lines (57 loc) • 2.73 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.withTVAndroidIconImage = void 0;
const config_plugins_1 = require("expo/config-plugins");
const fs_1 = require("fs");
const path_1 = __importDefault(require("path"));
const utils_1 = require("./utils");
const drawableDirectoryNames = [
"drawable",
"mipmap",
"mipmap-hdpi",
"mipmap-mdpi",
"mipmap-xhdpi",
"mipmap-xxhdpi",
"mipmap-xxxhdpi",
];
/** Copies TV Icon image to the Android resources drawable folders. If image does not exist, throw an exception. */
const withTVAndroidIconImage = (c, params = {}) => {
const androidTVIconPath = (0, utils_1.androidTVIcon)(params);
return (0, config_plugins_1.withDangerousMod)(c, [
"android",
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async (config) => {
if (!androidTVIconPath) {
return config;
}
(0, utils_1.verboseLog)(`adding TV Icon image ${androidTVIconPath} to Android resources`, {
params,
platform: "android",
property: "manifest",
});
for (const drawableDirectoryName of drawableDirectoryNames) {
const drawableDirectoryPath = path_1.default.join(config.modRequest.platformProjectRoot, "app", "src", "main", "res", drawableDirectoryName);
if (!(0, fs_1.existsSync)(drawableDirectoryPath)) {
await fs_1.promises.mkdir(drawableDirectoryPath);
}
if (drawableDirectoryName === "drawable") {
await fs_1.promises.copyFile(androidTVIconPath, path_1.default.join(drawableDirectoryPath, "tv_icon.png"));
}
else {
// SDK 52 adds a webp ic_launcher, which could lead to duplicate resource build error
if (!(0, fs_1.existsSync)(path_1.default.join(drawableDirectoryPath, "ic_launcher.webp"))) {
await fs_1.promises.copyFile(androidTVIconPath, path_1.default.join(drawableDirectoryPath, "ic_launcher.png"));
}
if (!(0, fs_1.existsSync)(path_1.default.join(drawableDirectoryPath, "ic_launcher_round.webp"))) {
await fs_1.promises.copyFile(androidTVIconPath, path_1.default.join(drawableDirectoryPath, "ic_launcher_round.png"));
}
}
}
return config;
},
]);
};
exports.withTVAndroidIconImage = withTVAndroidIconImage;