Surface

Functions summary

Unit
@NonRestartableComposable
@Composable
Surface(
    modifier: Modifier,
    tonalElevation: Dp,
    shape: Shape,
    colors: SurfaceColors,
    border: Border,
    glow: Glow,
    content: @Composable BoxScope.() -> Unit
)

The Surface is a building block component that will be used for any element on TV such as buttons, cards, navigation, or a simple background etc.

Unit
@Composable
Surface(
    onClick: () -> Unit,
    modifier: Modifier,
    onLongClick: (() -> Unit)?,
    enabled: Boolean,
    tonalElevation: Dp,
    shape: ClickableSurfaceShape,
    colors: ClickableSurfaceColors,
    scale: ClickableSurfaceScale,
    border: ClickableSurfaceBorder,
    glow: ClickableSurfaceGlow,
    interactionSource: MutableInteractionSource?,
    content: @Composable BoxScope.() -> Unit
)

The Surface is a building block component that will be used for any focusable element on TV such as buttons, cards, navigation, etc.

Unit
@Composable
Surface(
    selected: Boolean,
    onClick: () -> Unit,
    modifier: Modifier,
    enabled: Boolean,
    onLongClick: (() -> Unit)?,
    tonalElevation: Dp,
    shape: SelectableSurfaceShape,
    colors: SelectableSurfaceColors,
    scale: SelectableSurfaceScale,
    border: SelectableSurfaceBorder,
    glow: SelectableSurfaceGlow,
    interactionSource: MutableInteractionSource?,
    content: @Composable BoxScope.() -> Unit
)

The Surface is a building block component that will be used for any focusable element on TV such as buttons, cards, navigation, etc.

Functions

@NonRestartableComposable
@Composable
fun Surface(
    modifier: Modifier = Modifier,
    tonalElevation: Dp = 0.dp,
    shape: Shape = SurfaceDefaults.shape,
    colors: SurfaceColors = SurfaceDefaults.colors(),
    border: Border = SurfaceDefaults.border,
    glow: Glow = SurfaceDefaults.glow,
    content: @Composable BoxScope.() -> Unit
): Unit

The Surface is a building block component that will be used for any element on TV such as buttons, cards, navigation, or a simple background etc. This non-interactive Surface is similar to Compose Material's Surface composable

Parameters
modifier: Modifier = Modifier

Modifier to be applied to the layout corresponding to the surface

tonalElevation: Dp = 0.dp

When colors is ColorScheme.surface, a higher the elevation will result in a darker color in light theme and lighter color in dark theme.

shape: Shape = SurfaceDefaults.shape

Defines the surface's shape.

colors: SurfaceColors = SurfaceDefaults.colors()

Defines the background & content color to be used in this Surface. See SurfaceDefaults.colors.

border: Border = SurfaceDefaults.border

Defines a border around the Surface.

glow: Glow = SurfaceDefaults.glow

Diffused shadow to be shown behind the Surface. Note that glow is disabled for API levels below 28 as it is not supported by the underlying OS

content: @Composable BoxScope.() -> Unit

defines the Composable content inside the surface

@Composable
fun Surface(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    onLongClick: (() -> Unit)? = null,
    enabled: Boolean = true,
    tonalElevation: Dp = 0.dp,
    shape: ClickableSurfaceShape = ClickableSurfaceDefaults.shape(),
    colors: ClickableSurfaceColors = ClickableSurfaceDefaults.colors(),
    scale: ClickableSurfaceScale = ClickableSurfaceDefaults.scale(),
    border: ClickableSurfaceBorder = ClickableSurfaceDefaults.border(),
    glow: ClickableSurfaceGlow = ClickableSurfaceDefaults.glow(),
    interactionSource: MutableInteractionSource? = null,
    content: @Composable BoxScope.() -> Unit
): Unit

The Surface is a building block component that will be used for any focusable element on TV such as buttons, cards, navigation, etc. This clickable Surface is similar to Compose Material's Surface composable but will have more functionality that will make focus management easier. Surface will automatically apply the relevant modifier(s) based on the current interaction state.

Parameters
onClick: () -> Unit

callback to be called when the surface is clicked. Note: DPad Enter button won't work if this value is null

modifier: Modifier = Modifier

Modifier to be applied to the layout corresponding to the surface

onLongClick: (() -> Unit)? = null

callback to be called when the surface is long clicked (long-pressed).

enabled: Boolean = true

Controls the enabled state of the surface. When false, this Surface will not be clickable. A disabled surface will still be focusable (reason: https://issuetracker.google.com/302955429). If you still want it to not be focusable, consider using the Non-interactive variant of the Surface.

tonalElevation: Dp = 0.dp

When colors is ColorScheme.surface, a higher the elevation will result in a darker color in light theme and lighter color in dark theme.

shape: ClickableSurfaceShape = ClickableSurfaceDefaults.shape()

Defines the surface's shape.

colors: ClickableSurfaceColors = ClickableSurfaceDefaults.colors()

Defines the background & content colors to be used in this surface for different interaction states. See ClickableSurfaceDefaults.colors.

scale: ClickableSurfaceScale = ClickableSurfaceDefaults.scale()

Defines size of the Surface relative to its original size.

border: ClickableSurfaceBorder = ClickableSurfaceDefaults.border()

Defines a border around the Surface.

glow: ClickableSurfaceGlow = ClickableSurfaceDefaults.glow()

Diffused shadow to be shown behind the Surface. Note that glow is disabled for API levels below 28 as it is not supported by the underlying OS

interactionSource: MutableInteractionSource? = null

an optional hoisted MutableInteractionSource for observing and emitting Interactions for this surface. You can use this to change the surface's appearance or preview the surface in different states. Note that if null is provided, interactions will still happen internally.

content: @Composable BoxScope.() -> Unit

defines the Composable content inside the surface

@Composable
fun Surface(
    selected: Boolean,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    onLongClick: (() -> Unit)? = null,
    tonalElevation: Dp = Elevation.Level0,
    shape: SelectableSurfaceShape = SelectableSurfaceDefaults.shape(),
    colors: SelectableSurfaceColors = SelectableSurfaceDefaults.colors(),
    scale: SelectableSurfaceScale = SelectableSurfaceDefaults.scale(),
    border: SelectableSurfaceBorder = SelectableSurfaceDefaults.border(),
    glow: SelectableSurfaceGlow = SelectableSurfaceDefaults.glow(),
    interactionSource: MutableInteractionSource? = null,
    content: @Composable BoxScope.() -> Unit
): Unit

The Surface is a building block component that will be used for any focusable element on TV such as buttons, cards, navigation, etc.

This version of Surface is responsible for a toggling its selected state as well as everything else that a regular Surface does:

This version of surface will react to the select toggles, calling onClick lambda, updating the interactionSource when PressInteraction occurs.

To manually retrieve the content color inside a surface, use LocalContentColor.

Parameters
selected: Boolean

whether or not this Surface is selected

onClick: () -> Unit

callback to be invoked when the selectable Surface is clicked.

modifier: Modifier = Modifier

Modifier to be applied to the layout corresponding to the surface

enabled: Boolean = true

Controls the enabled state of the surface. When false, this Surface will not be clickable. A disabled surface will still be focusable (reason: https://issuetracker.google.com/302955429). If you still want it to not be focusable, consider using the Non-interactive variant of the Surface.

onLongClick: (() -> Unit)? = null

callback to be called when the selectable surface is long clicked (long-pressed).

tonalElevation: Dp = Elevation.Level0

When colors is ColorScheme.surface, a higher the elevation will result in a darker color in light theme and lighter color in dark theme.

shape: SelectableSurfaceShape = SelectableSurfaceDefaults.shape()

Defines the surface's shape.

colors: SelectableSurfaceColors = SelectableSurfaceDefaults.colors()

Defines the background & content colors to be used in this surface for different interaction states. See SelectableSurfaceDefaults.colors.

scale: SelectableSurfaceScale = SelectableSurfaceDefaults.scale()

Defines size of the Surface relative to its original size.

border: SelectableSurfaceBorder = SelectableSurfaceDefaults.border()

Defines a border around the Surface.

glow: SelectableSurfaceGlow = SelectableSurfaceDefaults.glow()

Diffused shadow to be shown behind the Surface. Note that glow is disabled for API levels below 28 as it is not supported by the underlying OS

interactionSource: MutableInteractionSource? = null

an optional hoisted MutableInteractionSource for observing and emitting Interactions for this surface. You can use this to change the surface's appearance or preview the surface in different states. Note that if null is provided, interactions will still happen internally.

content: @Composable BoxScope.() -> Unit

defines the Composable content inside the surface