Annotate Composable function with ReadOnlyComposable where it's possible. (#4859)

This commit is contained in:
Benoit Marty 2025-06-11 14:12:54 +02:00 committed by GitHub
parent 558e7b9239
commit f68b411659
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 24 additions and 0 deletions

View file

@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.tooling.preview.Preview
@ -27,6 +28,7 @@ import io.element.android.libraries.designsystem.theme.components.Text
* will be smaller.
*/
@Composable
@ReadOnlyComposable
fun Dp.applyScaleDown(): Dp = with(LocalDensity.current) {
return this@applyScaleDown * fontScale.coerceAtMost(1f)
}
@ -37,6 +39,7 @@ fun Dp.applyScaleDown(): Dp = with(LocalDensity.current) {
* will be bigger.
*/
@Composable
@ReadOnlyComposable
fun Dp.applyScaleUp(): Dp = with(LocalDensity.current) {
return this@applyScaleUp * fontScale.coerceAtLeast(1f)
}

View file

@ -8,6 +8,7 @@
package io.element.android.libraries.designsystem.text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit
@ -17,6 +18,7 @@ import androidx.compose.ui.unit.TextUnit
* Can be used for instance to use Dp unit for text.
*/
@Composable
@ReadOnlyComposable
fun Dp.toSp(): TextUnit = with(LocalDensity.current) { toSp() }
/**
@ -24,22 +26,26 @@ fun Dp.toSp(): TextUnit = with(LocalDensity.current) { toSp() }
* Can be used for instance to use Sp unit for size.
*/
@Composable
@ReadOnlyComposable
fun TextUnit.toDp(): Dp = with(LocalDensity.current) { toDp() }
/**
* Convert Px value to Dp, regarding current density.
*/
@Composable
@ReadOnlyComposable
fun Int.toDp(): Dp = with(LocalDensity.current) { toDp() }
/**
* Convert Dp value to pixels, regarding current density.
*/
@Composable
@ReadOnlyComposable
fun Dp.toPx(): Float = with(LocalDensity.current) { toPx() }
/**
* Convert Dp value to pixels, regarding current density.
*/
@Composable
@ReadOnlyComposable
fun Dp.roundToPx(): Int = with(LocalDensity.current) { roundToPx() }

View file

@ -9,10 +9,12 @@ package io.element.android.libraries.designsystem.utils
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalLayoutDirection
@Composable
@ReadOnlyComposable
fun WindowInsets.copy(
top: Int? = null,
right: Int? = null,