Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/expo plugin #242

Merged
merged 4 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading