Skip to content

Instantly share code, notes, and snippets.

@Randall71
Created June 27, 2025 10:09
Show Gist options
  • Save Randall71/2bc993b65f1695b6ca40c25b7cf2c611 to your computer and use it in GitHub Desktop.
Save Randall71/2bc993b65f1695b6ca40c25b7cf2c611 to your computer and use it in GitHub Desktop.
Config plugin for @thienmd/react-native-image-editor or the old react-native-photo-editor package
const fs = require('fs');
const path = require('path');
const { withAndroidManifest, withDangerousMod } = require('@expo/config-plugins');
// Function to modify the iOS Podfile properly inside the target block
function modifyPodfile(config) {
return withDangerousMod(config, [
'ios',
async (config) => {
const podfilePath = path.join(config.modRequest.platformProjectRoot, 'Podfile');
if (fs.existsSync(podfilePath)) {
let podfileContent = fs.readFileSync(podfilePath, 'utf-8');
const newPods = `
pod 'RNPhotoEditor', :path => '../node_modules/react-native-photo-editor/ios'
pod 'iOSPhotoEditor', :git => 'https://github.com/prscX/photo-editor', :branch => 'master'
`;
// Ensure it's inside the target block
const targetRegex = /target\s+['"]Maindeck['"]\s+do([\s\S]*?)end/;
const match = podfileContent.match(targetRegex);
if (match) {
const targetBlock = match[0];
if (!targetBlock.includes("pod 'RNPhotoEditor'")) {
const updatedTargetBlock = targetBlock.replace(
/(use_react_native!\([\s\S]*?\))/,
`$1\n${newPods}`,
);
podfileContent = podfileContent.replace(targetBlock, updatedTargetBlock);
fs.writeFileSync(podfilePath, podfileContent, 'utf-8');
}
}
}
return config;
},
]);
}
// Function to modify AndroidManifest.xml
function addExtraActivityToApplication(androidManifest) {
const { manifest } = androidManifest;
if (!Array.isArray(manifest['application'])) {
console.warn('withIntentActivity: No application array in manifest?');
return androidManifest;
}
const application = manifest['application'].find(
(item) => item.$['android:name'] === '.MainApplication',
);
if (!application) {
console.warn('withIntentActivity: No .MainApplication?');
return androidManifest;
}
if (!Array.isArray(application['activity'])) {
console.warn('withIntentActivity: No activity array in .MainApplication?');
return androidManifest;
}
const photoeditorActivity = {
$: {
'android:name': 'com.ahmedadeltito.photoeditor.PhotoEditorActivity',
},
};
application['activity'].push(photoeditorActivity);
return androidManifest;
}
// Main config plugin
module.exports = function withPhotoEditor(config) {
config = withAndroidManifest(config, (config) => {
config.modResults = addExtraActivityToApplication(config.modResults);
return config;
});
config = modifyPodfile(config);
return config;
};
@Randall71
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment