diff --git a/app.json b/app.json index e6babcb7..d4e5e08f 100644 --- a/app.json +++ b/app.json @@ -77,6 +77,7 @@ "com.reactnative.googlecast.RNGCExpandedControllerActivity": true } ], + ["./plugins/withExpandedController.js"], [ "expo-build-properties", { diff --git a/plugins/withExpandedController.js b/plugins/withExpandedController.js new file mode 100644 index 00000000..9ea30dcd --- /dev/null +++ b/plugins/withExpandedController.js @@ -0,0 +1,20 @@ +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;