PreviewWrapperProvider


Interface used to define custom rendering logic for Compose Previews in Android Studio.

Implementations of this interface allow developers to wrap the content of a Preview to provide specific environments, themes, or containers (such as a Remote Compose) without requiring repetitive code in every preview function.

Usage: Implementations are applied to previews using the PreviewWrapper annotation.

See also
PreviewWrapper

Summary

Public functions

Unit
@Composable
Wrap(content: @Composable () -> Unit)

Wraps the provided content with custom UI logic or containers.

Cmn

Public functions

Wrap

@Composable
fun Wrap(content: @Composable () -> Unit): Unit

Wraps the provided content with custom UI logic or containers.

Example usage for applying a Theme:

import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewWrapper
import androidx.compose.ui.tooling.preview.PreviewWrapperProvider

class CustomThemeWrapper : PreviewWrapperProvider {
    @Composable
    override fun Wrap(content: @Composable () -> Unit) {
        // Apply your custom theme or environment here
        // MyTheme {
        content()
        // }
    }
}
Parameters
content: @Composable () -> Unit

The original composable content of the function annotated with Preview.