chore: rework examples (#4225)
* remove unused examples * init bare example with test app * add react-native-video * add test app suport in expo plugin * expo plugin: skip keys that are already in pod file * fix podfile * add src files * fix metro config * finalize react native test app configuration * init expo example * remove old examples * add guide for example * Add link to examples apps in docs * adopt bare example to CI tests * update CI workflows * CI build lib after node_modules install * fix examples readme * fix iOS CI * Add Example for DRM * Update examples/README.md * fix links * update examples README * sync example code * update README
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
export type ConfigProps = {
|
||||
reactNativeTestApp?: boolean;
|
||||
/**
|
||||
* Whether to require permissions to be able to use notification controls.
|
||||
* @default false
|
||||
|
@@ -8,7 +8,10 @@ import {writeToPodfile} from './writeToPodfile';
|
||||
/**
|
||||
* Sets whether to enable the IMA SDK to use ADS with `react-native-video`.
|
||||
*/
|
||||
export const withAds: ConfigPlugin<boolean> = (c, enableADSExtension) => {
|
||||
export const withAds: ConfigPlugin<{
|
||||
enableADSExtension: boolean;
|
||||
testApp?: boolean;
|
||||
}> = (c, {enableADSExtension, testApp = false}) => {
|
||||
const android_key = 'RNVideo_useExoplayerIMA';
|
||||
const ios_key = 'RNVideoUseGoogleIMA';
|
||||
|
||||
@@ -38,6 +41,7 @@ export const withAds: ConfigPlugin<boolean> = (c, enableADSExtension) => {
|
||||
config.modRequest.projectRoot,
|
||||
ios_key,
|
||||
enableADSExtension.toString(),
|
||||
testApp,
|
||||
);
|
||||
return config;
|
||||
},
|
||||
|
@@ -4,10 +4,10 @@ import {writeToPodfile} from './writeToPodfile';
|
||||
/**
|
||||
* Sets whether to include the cache dependency to use cache on iOS with `react-native-video`.
|
||||
*/
|
||||
export const withCaching: ConfigPlugin<boolean> = (
|
||||
c,
|
||||
enableCachingExtension,
|
||||
) => {
|
||||
export const withCaching: ConfigPlugin<{
|
||||
enableCachingExtension: boolean;
|
||||
testApp?: boolean;
|
||||
}> = (c, {enableCachingExtension, testApp = false}) => {
|
||||
const ios_key = 'RNVideoUseVideoCaching';
|
||||
|
||||
return withDangerousMod(c, [
|
||||
@@ -17,6 +17,7 @@ export const withCaching: ConfigPlugin<boolean> = (
|
||||
config.modRequest.projectRoot,
|
||||
ios_key,
|
||||
enableCachingExtension.toString(),
|
||||
testApp,
|
||||
);
|
||||
return config;
|
||||
},
|
||||
|
@@ -26,11 +26,17 @@ const withRNVideo: ConfigPlugin<ConfigProps> = (config, props = {}) => {
|
||||
}
|
||||
|
||||
if (props.enableADSExtension) {
|
||||
config = withAds(config, props.enableADSExtension);
|
||||
config = withAds(config, {
|
||||
enableADSExtension: props.enableADSExtension,
|
||||
testApp: props.reactNativeTestApp,
|
||||
});
|
||||
}
|
||||
|
||||
if (props.enableCacheExtension) {
|
||||
config = withCaching(config, props.enableCacheExtension);
|
||||
config = withCaching(config, {
|
||||
enableCachingExtension: props.enableCacheExtension,
|
||||
testApp: props.reactNativeTestApp,
|
||||
});
|
||||
}
|
||||
|
||||
if (props.enableBackgroundAudio) {
|
||||
|
@@ -6,10 +6,57 @@ export const writeToPodfile = (
|
||||
projectRoot: string,
|
||||
key: string,
|
||||
value: string,
|
||||
testApp: boolean = false,
|
||||
) => {
|
||||
const podfilePath = path.join(projectRoot, 'ios', 'Podfile');
|
||||
const podfileContent = fs.readFileSync(podfilePath, 'utf8');
|
||||
|
||||
if (podfileContent.includes(`$${key} =`)) {
|
||||
console.warn(
|
||||
`RNV - Podfile already contains a definition for "$${key}". Skipping...`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (testApp) {
|
||||
mergeTestAppPodfile(podfileContent, podfilePath, key, value);
|
||||
} else {
|
||||
mergeExpoPodfile(podfileContent, podfilePath, key, value);
|
||||
}
|
||||
};
|
||||
|
||||
const mergeTestAppPodfile = (
|
||||
podfileContent: string,
|
||||
podfilePath: string,
|
||||
key: string,
|
||||
value: string,
|
||||
) => {
|
||||
// We will try to inject the variable definition above the `use_test_app!` call in the Podfile.
|
||||
const newPodfileContent = mergeContents({
|
||||
tag: `rn-video-set-${key.toLowerCase()}`,
|
||||
src: podfileContent,
|
||||
newSrc: `$${key} = ${value}`,
|
||||
anchor: /use_test_app!/,
|
||||
offset: -1, // Insert the key-value pair just above the `use_test_app!` call.
|
||||
comment: '#',
|
||||
});
|
||||
|
||||
// Write to Podfile only if the merge was successful
|
||||
if (newPodfileContent.didMerge) {
|
||||
fs.writeFileSync(podfilePath, newPodfileContent.contents);
|
||||
} else {
|
||||
console.warn(
|
||||
`RNV - Failed to write "$${key} = ${value}" to Test App Podfile`,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const mergeExpoPodfile = (
|
||||
podfileContent: string,
|
||||
podfilePath: string,
|
||||
key: string,
|
||||
value: string,
|
||||
) => {
|
||||
const newPodfileContent = mergeContents({
|
||||
tag: `rn-video-set-${key.toLowerCase()}`,
|
||||
src: podfileContent,
|
||||
|
Reference in New Issue
Block a user