PreviewParameterProvider

interface PreviewParameterProvider<T : Any?>


Interface to be implemented by any provider of values that you want to be injected as @Preview parameters. This allows providing sample information for previews.

Summary

Public functions

open String?

Returns a descriptive display name for the value at a given index from the values.

Public properties

open Int

Returns the number of elements in the values.

Sequence<T>

Sequence of values of type T to be passed as @Preview parameter.

Public functions

getDisplayName

open fun getDisplayName(index: Int): String?

Returns a descriptive display name for the value at a given index from the values.

This name is used in the preview UI to help identify individual preview cases generated by this provider. This allows for position-based naming schemes (e.g., "Step 1", "Step 2"). To create a name based on the value's content, the value would need to be retrieved from the values sequence within this method's implementation.

For example, for a PreviewParameterProvider representing steps in a flow, you might return "Step ${index + 1}".

If null or an empty string is returned, the preview UI will fall back to a default name determined by Android Studio.

Parameters
index: Int

The position of the value in the values.

Returns
String?

A custom name for the preview for the value at the given index, or null or an empty string to use the default.

Public properties

count

Added in 1.0.0
open val countInt

Returns the number of elements in the values.

values

Added in 1.0.0
val valuesSequence<T>

Sequence of values of type T to be passed as @Preview parameter.