The React Native @imgly/editor-react-native module is built on top of the native Android and iOS UI implementation and has no dedicated React Native UI.
However, you still have access to the same customization options as for iOS and Android.
To use them you need to configure them natively for both platforms.
An Expo app that generates ios/ and android/ with npx expo prebuild puts this native code into a local Expo module, as Expo Apps with Generated Native Folders shows.
Native Interfaces#
In order to allow intuitive and easily accessible native customization of the editors, we provide dedicated interfaces and convenience functions for both iOS and Android.
This layer is written in Swift and available via the IMGLYEditorModuleSwiftAdapter.shared instance.
The editor that is opened via the IMGLYEditorModuleSwiftAdapter.openEditor() function can be completely customized and exchanged.
For this to work you can use the IMGLYEditorModuleSwiftAdapter.builderClosure which provides an optional EditorPreset and metadata
with which you can provide any prebuilt or custom editor view. The metadata parameter of the openEditor function can be utilized
to provide customization details from the React Native side of your app to the native side:
iOS#
On iOS, we provide fallback functions for our default editors via:
EditorBuilder.design()EditorBuilder.apparel()EditorBuilder.photo()EditorBuilder.video()EditorBuilder.postcard()
In case you want a completely custom UI, you can use the EditorBuilder.custom function that allows you to return a custom View based on a given EditorConfig, an EditorPreset, metadata and an EditorBuilderResult:
1. Import the dependencies:#
import IMGLYEditorModuleimport SwiftUI2. Assign your custom editor:#
IMGLYEditorModuleSwiftAdapter.shared.builderClosure = { _, metadata in // Make decisions based on your own metadata. if metadata?["use_custom_editor"] as? Bool == true { // Return your custom editor. EditorBuilder.custom { settings, _, _, result in CustomEditor(settings: settings, result: result) } } else { // Return a custom or prebuilt editor. EditorBuilder.design() }}Further, we provide convenience extensions both for the OnCreate and OnExport callbacks to reduce the amount of code you need to write. For a detailed example, please take a look at our showcases app.
Android#
On Android, we provide fallback functions for our default editors via
EditorBuilder.design()EditorBuilder.apparel()EditorBuilder.photo()EditorBuilder.postcard()EditorBuilder.video().
In case you want a completely custom UI, you can use the EditorBuilder.custom function that allows you to return a custom @Composable function based on a given EditorConfig, an EditorPreset, metadata and an EditorBuilderResult:
1. Update the android/app/build.gradle file and add the following:#
android { (...) kotlinOptions { jvmTarget = "1.8" }
buildFeatures { compose true }
composeOptions { kotlinCompilerExtensionVersion = "1.5.10" }}
dependencies { implementation "ly.img:editor:1.87.0-rc.3" implementation(platform("androidx.compose:compose-bom:2023.05.01")) implementation "androidx.activity:activity-compose:1.6.1"}2. Import the dependencies:#
import androidx.compose.runtime.Composableimport ly.img.editor.reactnative.module.IMGLYEditorModuleimport ly.img.editor.reactnative.module.builder.EditorBuilderimport ly.img.editor.reactnative.module.builder.EditorBuilderResultimport ly.img.editor.reactnative.module.model.EditorSettings3. Assign your custom editor:#
IMGLYEditorModule.builderClosure = { _, metadata -> if (metadata?.get("custom") == true) { EditorBuilder.custom { CustomEditor(settings, result, onClose) } } else { EditorBuilder.design() }}Further, we provide an object called EditorBuilderDefaults which contains convenience methods for both the onCreate and onExport callbacks to reduce the amount of code you need to write. For a detailed example, please take a look here.
Plugins#
To add a plugin, such as background removal or voice isolation, add its native dependency on both platforms. Then return an editor with the plugin from the builderClosure. The plugins overview for iOS and Android lists the plugins, and each plugin’s guide shows its code. The Plugins entries of our showcases app do this on both platforms.
Add only the plugins that you use. Give them the version of @imgly/editor-react-native on both platforms. On iOS, each plugin requires the editor pod at exactly its own version. On Android, Gradle accepts another version without an error. The plugin or the module then runs against an editor that it was not built for.
On iOS, add the plugin pods to your app target in ios/Podfile:
target 'YourApp' do config = use_native_modules! pod 'IMGLYPluginBackgroundRemoval', '1.87.0-rc.3' pod 'IMGLYPluginVoiceIsolation', '1.87.0-rc.3'The plugin pods come from the IMG.LY spec repository, like the other CE.SDK pods. Your ios/Podfile needs the IMG.LY source from the CocoaPods Spec Repository guide. Then run pod install in the ios/ directory, with bundle exec in a React Native CLI app. When CocoaPods cannot find a compatible version of a plugin pod, add --repo-update.
On Android, add the plugin artifacts to the dependencies of android/app/build.gradle. A plugin needs the Compose setup of step 1 in the Android section above:
dependencies { implementation "ly.img:plugin-background-removal-imgly:1.87.0-rc.3" implementation "ly.img:plugin-voice-isolation-imgly:1.87.0-rc.3"}The Android guides for background removal and voice isolation list the other artifacts of each plugin.
These steps edit ios/ and android/ directly, as the rest of this guide does. An Expo app that generates both folders with npx expo prebuild follows Expo Apps with Generated Native Folders instead.
Expo Apps with Generated Native Folders#
npx expo prebuild --clean generates ios/ and android/ again and removes your edits in them. Put the customization code and the plugin dependencies into a local Expo module instead. Expo links the module into both folders on each prebuild. The steps below add the dependencies of background removal. Add other plugins in the same way.
1. Create a Local Expo Module#
Run this command in your project directory, and keep the suggested names:
npx create-expo-module@latest --local editor-customizationOn Expo SDK 53 to 55, replace @latest with @sdk-55, and on Expo SDK 51 and 52 with @sdk-51. The module is in modules/editor-customization.
2. Add the iOS Dependencies to the Podspec#
The plugin pods take the version of @imgly/editor-react-native, which the podspec reads from the package’s package.json. If :ios in s.platforms is lower than 16.0, set it to '16.0'. Keep s.static_framework = true of the template. Without it, pod install fails when useFrameworks is dynamic, because the plugin pods contain static libraries.
imgly_version = JSON.parse(File.read(`node --print "require.resolve('@imgly/editor-react-native/package.json')"`.strip))['version']
Pod::Spec.new do |s| (...) s.static_framework = true
s.dependency 'ExpoModulesCore' s.dependency 'IMGLYEditorModule' s.dependency 'IMGLYPluginBackgroundRemoval', imgly_versionThe plugin pods come from the IMG.LY spec repository. Add its source with the config plugin of the CocoaPods Spec Repository guide.
3. Set the builderClosure on iOS#
Create an app delegate subscriber in the module. Expo calls it when the app finishes launching, so the closure is set before your JavaScript code calls openEditor:
import ExpoModulesCoreimport IMGLYEditorModule
public class EditorCustomizationAppDelegate: ExpoAppDelegateSubscriber { public func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil ) -> Bool { IMGLYEditorModuleSwiftAdapter.shared.builderClosure = { preset, metadata in // Return your editor with its plugins, as the iOS section and the plugin guides show. EditorBuilder.design() } return true }}Add the subscriber to appDelegateSubscribers, next to modules. On Expo SDK 51, the object is ios:
"apple": { "modules": ["EditorCustomizationModule"] "modules": ["EditorCustomizationModule"], "appDelegateSubscribers": ["EditorCustomizationAppDelegate"]},4. Add the Android Dependencies to build.gradle#
The module needs the React Native module and the plugin artifacts at the version of @imgly/editor-react-native. It also needs the Compose compiler plugin of your app’s Kotlin version:
buildscript { repositories { mavenCentral() } dependencies { classpath("org.jetbrains.kotlin.plugin.compose:org.jetbrains.kotlin.plugin.compose.gradle.plugin:${kotlinVersion}") }}
plugins { id 'com.android.library' id 'expo-module-gradle-plugin'}apply plugin: 'org.jetbrains.kotlin.plugin.compose'
android { (...) buildFeatures { compose true }}
def imglyVersion = new groovy.json.JsonSlurper().parse(new File(["node", "--print", "require.resolve('@imgly/editor-react-native/package.json')"].execute(null, rootDir).text.trim())).version
dependencies { implementation project(':imgly_editor-react-native') implementation "ly.img:plugin-background-removal-imgly:$imglyVersion"}Kotlin 1.9 has no Compose compiler plugin, and Expo SDK 51 and 52 use Kotlin 1.9. On these SDKs, leave out the buildscript block and the apply plugin line. Then add composeOptions { kotlinCompilerExtensionVersion = "1.5.10" } to the android block. Compose compiler 1.5.10 matches Kotlin 1.9.22 of Expo SDK 51. For another Kotlin version, such as on Expo SDK 52, use the Compose to Kotlin compatibility map. A build with a wrong version fails with an error that names your Kotlin version.
5. Set the builderClosure on Android#
Create a package with an application lifecycle listener in the same folder as the module’s Kotlin file. Expo finds the class because its file name ends with Package.kt and matches the class name. Expo calls the listener when the app starts:
package expo.modules.editorcustomization
import android.app.Applicationimport android.content.Contextimport expo.modules.core.interfaces.ApplicationLifecycleListenerimport expo.modules.core.interfaces.Packageimport ly.img.editor.reactnative.module.IMGLYEditorModuleimport ly.img.editor.reactnative.module.builder.EditorBuilder
class EditorCustomizationPackage : Package { override fun createApplicationLifecycleListeners(context: Context): List<ApplicationLifecycleListener> = listOf(EditorCustomizationLifecycleListener())}
class EditorCustomizationLifecycleListener : ApplicationLifecycleListener { override fun onCreate(application: Application) { IMGLYEditorModule.builderClosure = { preset, metadata -> // Return your editor with its plugins, as the Android section and the plugin guides show. EditorBuilder.design() } }}Then generate the native folders again:
npx expo prebuild --clean