diff --git a/app.json b/app.json index 9e227a49..00b060b9 100644 --- a/app.json +++ b/app.json @@ -66,13 +66,6 @@ } } ], - [ - "./plugins/withAndroidMainActivityAttributes", - { - "com.reactnative.googlecast.RNGCExpandedControllerActivity": true - } - ], - ["./plugins/withExpandedController.js"], [ "expo-build-properties", { diff --git a/bun.lockb b/bun.lockb index a101897e..29413a9f 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/components/Chromecast.tsx b/components/Chromecast.tsx index ff88767c..6ba0e089 100644 --- a/components/Chromecast.tsx +++ b/components/Chromecast.tsx @@ -1,8 +1,9 @@ import { Feather } from "@expo/vector-icons"; import { BlurView } from "expo-blur"; -import React, { useEffect } from "react"; +import React, { useCallback, useEffect } from "react"; import { Platform, TouchableOpacity, ViewProps } from "react-native"; import GoogleCast, { + CastButton, CastContext, useCastDevice, useDevices, @@ -39,18 +40,32 @@ export const Chromecast: React.FC = ({ })(); }, [client, devices, castDevice, sessionManager, discoveryManager]); + // Android requires the cast button to be present for startDiscovery to work + const AndroidCastButton = useCallback( + () => + Platform.OS === "android" ? ( + + ) : ( + <> + ), + [Platform.OS] + ); + if (background === "transparent") return ( - { - if (mediaStatus?.currentItemId) CastContext.showExpandedControls(); - else CastContext.showCastDialog(); - }} - className="rounded-full h-10 w-10 flex items-center justify-center b" - {...props} - > - - + <> + { + if (mediaStatus?.currentItemId) CastContext.showExpandedControls(); + else CastContext.showCastDialog(); + }} + className="rounded-full h-10 w-10 flex items-center justify-center b" + {...props} + > + + + + ); if (Platform.OS === "android") @@ -82,6 +97,7 @@ export const Chromecast: React.FC = ({ > + ); }; diff --git a/components/PlayButton.tsx b/components/PlayButton.tsx index f87eebf8..1393a8c1 100644 --- a/components/PlayButton.tsx +++ b/components/PlayButton.tsx @@ -10,6 +10,7 @@ import { useAtom } from "jotai"; import { useEffect, useMemo } from "react"; import { Linking, TouchableOpacity, View } from "react-native"; import CastContext, { + CastButton, PlayServicesState, useMediaStatus, useRemoteMediaClient, @@ -318,6 +319,7 @@ export const PlayButton: React.FC = ({ item, url, ...props }) => { {client && ( + )} {!client && settings?.openInVLC && ( diff --git a/plugins/withAndroidMainActivityAttributes.js b/plugins/withAndroidMainActivityAttributes.js deleted file mode 100644 index c5764408..00000000 --- a/plugins/withAndroidMainActivityAttributes.js +++ /dev/null @@ -1,42 +0,0 @@ -const { withAndroidManifest } = require("@expo/config-plugins"); - -function addAttributesToMainActivity(androidManifest, attributes) { - const { manifest } = androidManifest; - - if (!Array.isArray(manifest["application"])) { - console.warn("withAndroidMainActivityAttributes: No application array in manifest?"); - return androidManifest; - } - - const application = manifest["application"].find( - (item) => item.$["android:name"] === ".MainApplication" - ); - if (!application) { - console.warn("withAndroidMainActivityAttributes: No .MainApplication?"); - return androidManifest; - } - - if (!Array.isArray(application["activity"])) { - console.warn("withAndroidMainActivityAttributes: No activity array in .MainApplication?"); - return androidManifest; - } - - const activity = application["activity"].find( - (item) => item.$["android:name"] === ".MainActivity" - ); - if (!activity) { - console.warn("withAndroidMainActivityAttributes: No .MainActivity?"); - return androidManifest; - } - - activity.$ = { ...activity.$, ...attributes }; - - return androidManifest; -} - -module.exports = function withAndroidMainActivityAttributes(config, attributes) { - return withAndroidManifest(config, (config) => { - config.modResults = addAttributesToMainActivity(config.modResults, attributes); - return config; - }); -}; diff --git a/plugins/withExpandedController.js b/plugins/withExpandedController.js deleted file mode 100644 index 9ea30dcd..00000000 --- a/plugins/withExpandedController.js +++ /dev/null @@ -1,20 +0,0 @@ -const { withAppDelegate } = require("@expo/config-plugins"); - -const withExpandedController = (config) => { - return withAppDelegate(config, async (config) => { - const contents = config.modResults.contents; - - // Looking for the initialProps string inside didFinishLaunchingWithOptions, - // and injecting expanded controller config. - // Should be updated once there is an expo config option - see https://github.com/react-native-google-cast/react-native-google-cast/discussions/537 - const injectionIndex = contents.indexOf("self.initialProps = @{};"); - config.modResults.contents = - contents.substring(0, injectionIndex) + - `\n [GCKCastContext sharedInstance].useDefaultExpandedMediaControls = true; \n` + - contents.substring(injectionIndex); - - return config; - }); -}; - -module.exports = withExpandedController;