From bb949e4f44c4ed1e19c7bddc5779515b419a7022 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Mon, 11 Aug 2025 18:37:39 +0300 Subject: Fix translations on Android using PROCESS_TEXT intent (#8486) * use intents to translate text on android * clean up config plugins * restore day night plugin just to be safe * leave a comment for why we can't open translate directly * add todo * fix lockfile lint --- plugins/withAndroidManifestIntentQueriesPlugin.js | 30 +++++++++++++++++++++++ plugins/withAndroidManifestLargeHeapPlugin.js | 14 +++++++++++ plugins/withAndroidManifestPlugin.js | 14 ----------- 3 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 plugins/withAndroidManifestIntentQueriesPlugin.js create mode 100644 plugins/withAndroidManifestLargeHeapPlugin.js delete mode 100644 plugins/withAndroidManifestPlugin.js (limited to 'plugins') diff --git a/plugins/withAndroidManifestIntentQueriesPlugin.js b/plugins/withAndroidManifestIntentQueriesPlugin.js new file mode 100644 index 000000000..04237b059 --- /dev/null +++ b/plugins/withAndroidManifestIntentQueriesPlugin.js @@ -0,0 +1,30 @@ +const {withAndroidManifest} = require('@expo/config-plugins') + +const withProcessTextQuery = config => + // eslint-disable-next-line no-shadow + withAndroidManifest(config, config => { + const manifest = config.modResults.manifest + + // Ensure stub exists + if (!manifest.queries) manifest.queries = [{}] + const queries = manifest.queries[0] + + queries.intent = queries.intent || [] + + const exists = queries.intent.some( + i => + i.action?.[0]?.$?.['android:name'] === + 'android.intent.action.PROCESS_TEXT', + ) + + if (!exists) { + queries.intent.push({ + action: [{$: {'android:name': 'android.intent.action.PROCESS_TEXT'}}], + data: [{$: {'android:mimeType': 'text/plain'}}], + }) + } + + return config + }) + +module.exports = withProcessTextQuery diff --git a/plugins/withAndroidManifestLargeHeapPlugin.js b/plugins/withAndroidManifestLargeHeapPlugin.js new file mode 100644 index 000000000..55fd3f5ca --- /dev/null +++ b/plugins/withAndroidManifestLargeHeapPlugin.js @@ -0,0 +1,14 @@ +const {withAndroidManifest} = require('expo/config-plugins') + +module.exports = function withAndroidManifestPlugin(appConfig) { + return withAndroidManifest(appConfig, function (decoratedAppConfig) { + try { + decoratedAppConfig.modResults.manifest.application[0].$[ + 'android:largeHeap' + ] = 'true' + } catch (e) { + console.error(`withAndroidManifestPlugin failed`, e) + } + return decoratedAppConfig + }) +} diff --git a/plugins/withAndroidManifestPlugin.js b/plugins/withAndroidManifestPlugin.js deleted file mode 100644 index 55fd3f5ca..000000000 --- a/plugins/withAndroidManifestPlugin.js +++ /dev/null @@ -1,14 +0,0 @@ -const {withAndroidManifest} = require('expo/config-plugins') - -module.exports = function withAndroidManifestPlugin(appConfig) { - return withAndroidManifest(appConfig, function (decoratedAppConfig) { - try { - decoratedAppConfig.modResults.manifest.application[0].$[ - 'android:largeHeap' - ] = 'true' - } catch (e) { - console.error(`withAndroidManifestPlugin failed`, e) - } - return decoratedAppConfig - }) -} -- cgit 1.4.1