PreviewLab
Parameters
Factory for creating the default PreviewLabState. Controls state persistence and initialization. By default, uses rememberSaveable for automatic state persistence across recompositions.
Usage examples:
// Default behavior - state persists across recompositions
PreviewLab() // Uses rememberSaveable internally
// Non-persistent state - resets on every recomposition
PreviewLab(
defaultState = { remember { PreviewLabState() } }
)
// Custom retained state (requires Rin library)
PreviewLab(
defaultState = { remember { PreviewLabState() } }
)List of screen sizes to display in the preview. Controls which device form factors are available for testing. Defaults to ScreenSize.SmartphoneAndDesktops.
Usage examples:
// Default - smartphone and desktop sizes
PreviewLab() // Uses ScreenSize.SmartphoneAndDesktops
// All available presets including tablets
PreviewLab(
defaultScreenSizes = ScreenSize.AllPresets
)
// Only mobile devices for focused testing
PreviewLab(
defaultScreenSizes = listOf(ScreenSize.Phone, ScreenSize.Tablet)
)
// Custom screen sizes for specific requirements
PreviewLab(
defaultScreenSizes = listOf(
ScreenSize(360.dp, 640.dp, "Small Phone"),
ScreenSize(1920.dp, 1080.dp, "Full HD Desktop")
)
)Wrapper composable that surrounds the entire PreviewLab UI. Useful for providing custom themes, composition locals, or other global configuration.
Usage examples:
// Default - no wrapper, uses PreviewLabTheme only
PreviewLab() // Uses { it() }
// Apply custom Material3 theme like customizedPreviewLab
PreviewLab(
contentRoot = { content ->
MaterialTheme(
colorScheme = lightColorScheme(
primary = Color.Red,
onPrimary = Color.Yellow
)
) {
content()
}
}
)
// Provide composition locals for your design system
PreviewLab(
contentRoot = { content ->
MyDesignSystem {
CompositionLocalProvider(
LocalCustomTypography provides customTypography,
LocalBranding provides myBranding
) {
content()
}
}
}
)
// Add global error boundary and logging
PreviewLab(
contentRoot = { content ->
ErrorBoundary(onError = { error -> logError(error) }) {
content()
}
}
)Controls whether the PreviewLab header is visible. When set to false, hides the header controls (scale, inspector panel toggle, etc.) to provide a cleaner preview view. Defaults to true.
Usage examples:
// Default - header is visible
PreviewLab() // Header shown
// Hide header for embedded preview
PreviewLab(
isHeaderShow = false
) {
MyComponent()
}List of tabs to display in the inspector panel. Defaults to InspectorTab.defaults which shows the built-in Fields and Events tabs.
Usage examples:
// Default - Fields and Events tabs only
PreviewLab() // Uses InspectorTab.defaults
// Add custom tabs alongside default tabs
val myPreviewLab = PreviewLab(
defaultInspectorTabs = { InspectorTab.defaults + listOf(DebugTab) }
)
// Only custom tabs (no default Fields/Events)
val customOnlyPreviewLab = PreviewLab(
defaultInspectorTabs = { listOf(CustomTab1, CustomTab2) }
)
// No tabs at all
val noTabsPreviewLab = PreviewLab(
defaultInspectorTabs = { emptyList() }
)Technical parameter to prevent the invoke method from being treated as a trailing lambda. Always null and has no functional purpose.
Usage example:
// This parameter is always null - you don't need to specify it
PreviewLab(
defaultScreenSizes = ScreenSize.AllPresets
// disableTrailingLambda is automatically null
) {
// Preview content
}