Skip to content

Commit

Permalink
Merge pull request #242 from THEOplayer/feature/expo_plugin
Browse files Browse the repository at this point in the history
Feature/expo plugin
  • Loading branch information
tvanlaerhoven authored Dec 20, 2023
2 parents b769e88 + d7ecb99 commit d4815be
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- Added Expo plugin to support Android dependency configuration.

### Changed

- Changed the Android notification channel name to `Notification channel`. It can be renamed by defining the `notification_channel_name` resource string.
Expand Down
57 changes: 57 additions & 0 deletions app.plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Expo plugin for react-native-theoplayer.
*
* Example:
* "plugins": [
* ["react-native-theoplayer", {
* "extensions": ["ima", "dai", "cast"]
* }]
* ]
*/
const {withProjectBuildGradle, withGradleProperties} = require('@expo/config-plugins');

function mapAndroidExtensionKey(ext) {
switch (ext) {
case "ima":
return "THEOplayer_extensionGoogleIMA";
case "dai":
return "THEOplayer_extensionGoogleDAI";
case "cast":
return "THEOplayer_extensionCast";
default:
return undefined;
}
}

const applyAndroidExtensions = (config, extensions) => {
return withGradleProperties(config, (config) => {
extensions?.forEach(ext => {
const key = mapAndroidExtensionKey(ext);
if (key) {
config.modResults.push({type: "property", key, value: true});
}
});
return config;
});
}

const withAndroidTHEOplayer = (config, props) => {
// Apply Android extensions
const {extensions} = props;
config = applyAndroidExtensions(config, extensions);

// Add the localMaven repo to the project's repositories
return withProjectBuildGradle(config, (config) => {
const localMaven = 'maven { url("$rootDir/../node_modules/react-native-theoplayer/android/local") }';
config.modResults.contents = config.modResults.contents.replace(
/allprojects\s*\{\s*repositories\s*\{/,
`$&\n\t\t${localMaven}`
)
return config;
});
};

module.exports = (config, props) => {
// Apply Android modifications
return withAndroidTHEOplayer(config, props);
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"react-native-theoplayer.podspec",
"react-native-theoplayer.json",
"CHANGELOG.md",
"app.plugin.js",
"!lib/typescript/example",
"!android/build",
"!ios/build",
Expand Down

0 comments on commit d4815be

Please sign in to comment.