UNPKG

expo-plugin-image-crop-picker

Version:
48 lines (47 loc) 2.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.withAndroidImageCropPicker = void 0; const config_plugins_1 = require("@expo/config-plugins"); /** * Adds Android permissions and gradle settings for image crop picker. */ const withAndroidImageCropPicker = (config) => { config = (0, config_plugins_1.withProjectBuildGradle)(config, (config) => { const mavenRepos = `maven { url 'https://maven.google.com' }\nmaven { url 'https://www.jitpack.io' }`; if (!config.modResults.contents.includes(mavenRepos)) { config.modResults.contents = config.modResults.contents.replace(/allprojects[\s\S]*?repositories[\s\S]*?\{/, (match) => `${match}\n // Added by plugin\n ${mavenRepos}`); } config.modResults.contents = config.modResults.contents .replace(/compileSdkVersion\s*=\s*\d+/g, 'compileSdkVersion = 33') .replace(/targetSdkVersion\s*=\s*\d+/g, 'targetSdkVersion = 33'); return config; }); config = (0, config_plugins_1.withAppBuildGradle)(config, (config) => { if (!config.modResults.contents.includes('vectorDrawables.useSupportLibrary = true')) { config.modResults.contents = config.modResults.contents.replace(/defaultConfig\s*\{/, `defaultConfig {\n // Added by plugin\n vectorDrawables.useSupportLibrary = true`); } return config; }); config = (0, config_plugins_1.withAndroidManifest)(config, (config) => { var _a, _b; var _c, _d; const manifest = config.modResults; (_a = (_c = manifest.manifest)['uses-permission']) !== null && _a !== void 0 ? _a : (_c['uses-permission'] = []); const permissions = manifest.manifest['uses-permission']; if (!permissions.some((item) => item.$['android:name'] === 'android.permission.CAMERA')) { permissions.push({ $: { 'android:name': 'android.permission.CAMERA' } }); } (_b = (_d = manifest.manifest)['uses-feature']) !== null && _b !== void 0 ? _b : (_d['uses-feature'] = []); const features = manifest.manifest['uses-feature']; const ensureFeature = (name) => { if (!features.some((f) => f.$['android:name'] === name)) { features.push({ $: { 'android:name': name, 'android:required': 'false' } }); } }; ensureFeature('android.hardware.camera'); ensureFeature('android.hardware.camera.front'); return config; }); return config; }; exports.withAndroidImageCropPicker = withAndroidImageCropPicker;