From cad03a35665edabbed418832c47bee65ceb9aef9 Mon Sep 17 00:00:00 2001 From: Fredrik Burmester Date: Sun, 5 Jan 2025 20:59:45 +0100 Subject: [PATCH] fix: chromecast --- app.json | 3 ++- plugins/withGoogleCastActivity.js | 34 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 plugins/withGoogleCastActivity.js diff --git a/app.json b/app.json index 8a0f4f54..d0023760 100644 --- a/app.json +++ b/app.json @@ -111,7 +111,8 @@ { "android": { "parentTheme": "Material3" } } ], ["react-native-bottom-tabs"], - ["./plugins/withChangeNativeAndroidTextToWhite.js"] + ["./plugins/withChangeNativeAndroidTextToWhite.js"], + ["./plugins/withGoogleCastActivity.js"] ], "experiments": { "typedRoutes": true diff --git a/plugins/withGoogleCastActivity.js b/plugins/withGoogleCastActivity.js new file mode 100644 index 00000000..1a8c0a30 --- /dev/null +++ b/plugins/withGoogleCastActivity.js @@ -0,0 +1,34 @@ +const { withAndroidManifest } = require("@expo/config-plugins"); + +const withGoogleCastActivity = (config) => + withAndroidManifest(config, async (config) => { + const mainApplication = config.modResults.manifest.application[0]; + + // Initialize activity array if it doesn't exist + if (!mainApplication.activity) { + mainApplication.activity = []; + } + + // Check if the activity already exists + const activityExists = mainApplication.activity.some( + (activity) => + activity.$?.["android:name"] === + "com.reactnative.googlecast.RNGCExpandedControllerActivity" + ); + + // Only add the activity if it doesn't already exist + if (!activityExists) { + mainApplication.activity.push({ + $: { + "android:name": + "com.reactnative.googlecast.RNGCExpandedControllerActivity", + "android:theme": "@style/Theme.MaterialComponents.NoActionBar", + "android:launchMode": "singleTask", + }, + }); + } + + return config; + }); + +module.exports = withGoogleCastActivity;