-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #242 from THEOplayer/feature/expo_plugin
Feature/expo plugin
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters