---
title: "preferredFrameRate"
description: "Set a requested frame rate on Composable

You can set the preferred frame rate (frames per second) for a Composable using a non-negative
number. This API should only be used when a specific frame rate is needed for your Composable.
For example, 24 or 30 for video play.

If multiple frame rates are requested, they will be aggregated to determine a feasible frame
rate.

If you no longer want this modifier to influence the frame rate, clear the preference by setting
it to 0.

Keep in mind that the preferred frame rate affects the frame rate for the next frame, so use this
method carefully. It's important to note that the preference is valid as long as the Composable
is drawn."
type: "modifier"
---

<div class='type'>Compose Modifier</div>

<a id='references'></a>
<div class='sourceset sourceset-common'>Common</div>


```kotlin
fun Modifier.preferredFrameRate(@FloatRange(from = 0.0, to = 360.0) frameRate: Float) =
    this.graphicsLayer().frameRate(frameRate)
```


Set a requested frame rate on Composable

You can set the preferred frame rate (frames per second) for a Composable using a non-negative
number. This API should only be used when a specific frame rate is needed for your Composable.
For example, 24 or 30 for video play.

If multiple frame rates are requested, they will be aggregated to determine a feasible frame
rate.

If you no longer want this modifier to influence the frame rate, clear the preference by setting
it to 0.

Keep in mind that the preferred frame rate affects the frame rate for the next frame, so use this
method carefully. It's important to note that the preference is valid as long as the Composable
is drawn.

#### Parameters

| | |
| --- | --- |
| frameRate | The preferred frame rate the content should be rendered at. Default value is 0. |




<div class='sourceset sourceset-common'>Common</div>


```kotlin
fun Modifier.preferredFrameRate(frameRateCategory: FrameRateCategory) =
    this.graphicsLayer().frameRate(frameRateCategory.value)
```


Set a requested frame rate on Composable

You can set the preferred frame rate (frames per second) for a Composable using a frame rate
category see: `FrameRateCategory`.

For increased frame rates, please consider using FrameRateCategory.High.

Keep in mind that the preferred frame rate affects the frame rate for the next frame, so use this
method carefully. It's important to note that the preference is valid as long as the Composable
is drawn.

#### Parameters

| | |
| --- | --- |
| frameRateCategory | The preferred frame rate category the content should be rendered at. |




## Code Examples
### SetFrameRateCategorySample
```kotlin
@Composable
fun SetFrameRateCategorySample() {
    var targetAlpha by remember { mutableFloatStateOf(1f) }
    val context = LocalContext.current
    val activity: Activity? = findOwner(context)
    DisposableEffect(activity) {
        activity?.window?.frameRateBoostOnTouchEnabled = false
        onDispose { activity?.window?.frameRateBoostOnTouchEnabled = true }
    }
    val alpha by
        animateFloatAsState(targetValue = targetAlpha, animationSpec = tween(durationMillis = 5000))
    Column(modifier = Modifier.size(300.dp)) {
        Button(
            onClick = { targetAlpha = if (targetAlpha == 1f) 0.2f else 1f },
            modifier =
                Modifier.testTag("frameRateTag")
                    .background(LocalContentColor.current.copy(alpha = alpha)),
        ) {
            Text(
                text = "Click Me for alpha change with frame rate category High",
                color = LocalContentColor.current.copy(alpha = alpha),
                modifier = Modifier.preferredFrameRate(FrameRateCategory.High),
            )
        }
    }
}
```
### SetFrameRateSample
```kotlin
@Composable
fun SetFrameRateSample() {
    var targetAlpha by remember { mutableFloatStateOf(1f) }
    val context = LocalContext.current
    val activity: Activity? = findOwner(context)
    DisposableEffect(activity) {
        activity?.window?.frameRateBoostOnTouchEnabled = false
        onDispose { activity?.window?.frameRateBoostOnTouchEnabled = true }
    }
    val alpha by
        animateFloatAsState(targetValue = targetAlpha, animationSpec = tween(durationMillis = 5000))
    Column(modifier = Modifier.size(300.dp)) {
        Button(
            onClick = { targetAlpha = if (targetAlpha == 1f) 0.2f else 1f },
            modifier =
                Modifier.testTag("frameRateTag")
                    .background(LocalContentColor.current.copy(alpha = alpha)),
        ) {
            Text(
                text = "Click Me for alpha change with 30 Hz frame rate",
                color = LocalContentColor.current.copy(alpha = alpha), // Adjust text alpha
                modifier = Modifier.preferredFrameRate(30f),
            )
        }
    }
}
```

