In this example, we will show you how to make theming configurations for the mobile editor.
2 mins
estimated time Configuration#
The uiMode setting is passed directly to Editor.
uiMode- the UI mode of the editor. The default value isEditorUiMode.SYSTEM. These are the available values:EditorUiMode.SYSTEM- editor will use the light color scheme if the system is in light mode and will use the dark color scheme if the system is in dark mode.EditorUiMode.LIGHT- editor will always use the light color scheme.EditorUiMode.DARK- editor will always use the dark color scheme.
Full Code#
This full sample adds a dock button labeled Switch Theme to toggle between EditorUiMode.LIGHT and EditorUiMode.DARK at runtime.
import androidx.compose.foundation.layout.Arrangementimport androidx.compose.runtime.Composableimport androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.rememberimport androidx.compose.runtime.setValueimport ly.img.editor.Editorimport ly.img.editor.EditorUiModeimport ly.img.editor.core.component.Dockimport ly.img.editor.core.component.rememberimport ly.img.editor.core.configuration.EditorConfigurationimport ly.img.editor.core.configuration.rememberimport ly.img.editor.core.iconpack.IconPackimport ly.img.editor.core.iconpack.Replace
// Add this composable to your NavHost@Composablefun ThemingEditorSolution( license: String, onClose: (Throwable?) -> Unit,) { var uiMode by remember { mutableStateOf(EditorUiMode.LIGHT) } Editor( license = license, // pass null or empty for evaluation mode with watermark uiMode = uiMode, configuration = { EditorConfiguration.remember { dock = { rememberDock( onSwitchClick = { uiMode = if (uiMode == EditorUiMode.LIGHT) { EditorUiMode.DARK } else { EditorUiMode.LIGHT } }, ) } } }, onClose = onClose, )}
@Composableprivate fun rememberDock(onSwitchClick: () -> Unit) = Dock.remember { horizontalArrangement = { Arrangement.Center } listBuilder = { Dock.ListBuilder.remember { add { Dock.Button.remember { textString = { "Switch Theme" } vectorIcon = { IconPack.Replace } onClick = { onSwitchClick() } } } } }}