In this example, we will show you how to make overlay configurations for the mobile editor.
Explore a full code sample on GitHub.
Configuration#
There are situations when you want to create UI that is drawn over the editor (a.k.a Overlay). A great example would be showing a loading indicator when the editor is being loaded or showing a custom dialog asking for export configurations when your customer taps on the Export button. This is when overlay configuration comes to help. In this example, we are going to demonstrate how to show your own loading dialog when the editor is being loaded upon opening it.
- Add a new mutable compose state
isLoading. - Update it in the
onCreatecallback. As the state is updated, the updated state is received in the composable callback of overlayEditorComponentto be rendered. - Render your own loading. In this example, tapping on the button of the loading dialog closes the dialog and the editor.
Full Code#
Here’s the full code:
import androidx.compose.material3.AlertDialogimport androidx.compose.material3.Textimport androidx.compose.material3.TextButtonimport androidx.compose.runtime.Composableimport androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.rememberimport androidx.compose.runtime.setValueimport androidx.compose.ui.window.DialogPropertiesimport androidx.navigation.NavHostControllerimport ly.img.editor.Editorimport ly.img.editor.core.component.EditorComponentimport ly.img.editor.core.component.rememberimport ly.img.editor.core.configuration.EditorConfigurationimport ly.img.editor.core.configuration.rememberimport ly.img.editor.core.event.EditorEventimport ly.img.engine.DesignBlockType
// Add this composable to your NavHost@Composablefun OverlayEditorSolution(navController: NavHostController) { var isLoading by remember { mutableStateOf(false) } Editor( license = null, // pass null or empty for evaluation mode with watermark configuration = { EditorConfiguration.remember { onCreate = { isLoading = true try { val scene = editorContext.engine.scene.create() val page = editorContext.engine.block.create(DesignBlockType.Page) editorContext.engine.block.setWidth(block = page, value = 1080F) editorContext.engine.block.setHeight(block = page, value = 1080F) editorContext.engine.block.appendChild(parent = scene, child = page) } finally { isLoading = false } } overlay = { EditorComponent.remember { decoration = { if (isLoading) { AlertDialog( onDismissRequest = { }, title = { Text(text = "Please wait. If you want to close the editor, click the button.") }, confirmButton = { TextButton( onClick = { isLoading = false editorContext.eventHandler.send(EditorEvent.CloseEditor()) }, ) { Text(text = "Close Editor") } }, properties = DialogProperties(dismissOnBackPress = false, dismissOnClickOutside = false), ) } } } } } }, ) { // You can set result here navController.popBackStack() }}