Skip to content

Instantly share code, notes, and snippets.

@Composable
fun SaveableLaunchedEffect(
key1: Any?,
block: suspend CoroutineScope.() -> Unit,
) {
var launched by rememberSaveable(key1) {
mutableStateOf(false)
}
if (!launched) {
LaunchedEffect(key1) {
#!/bin/bash
# don't forget to do `chmod +x screencap.sh` in the script location
adb devices | tail -n +2 | while read line
do
deviceId=$(echo $line | awk '{print $1}')
if [ -z "${deviceId}" ]; then
continue
fi
fun Modifier.clickableClipped(
shape: Shape,
enabled: Boolean = true,
onClickLabel: String? = null,
role: Role? = null,
onClick: () -> Unit,
) = composed {
val interactionSource = remember {
MutableInteractionSource()
}
@Composable
fun FpsCounter(
modifier: Modifier = Modifier,
) {
var fps by remember {
mutableStateOf("")
}
LaunchedEffect(Unit) {
val frames = mutableListOf<Long>()
while (true) {
@Composable
inline fun LtrRow(
modifier: Modifier = Modifier,
horizontalArrangement: Arrangement.Horizontal = Arrangement.Start,
verticalAlignment: Alignment.Vertical = Alignment.Top,
crossinline content: @Composable RowScope.() -> Unit
) {
val direction = LocalLayoutDirection.current
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) {
Row(
fun Modifier.swipeableTopBottom(onTop: () -> Unit, onBottom: () -> Unit): Modifier = composed {
var width by rememberSaveable { mutableStateOf(0f) }
val swipeableState = rememberSwipeableState(
SwipeDirection.Initial,
animationSpec = snap()
)
val anchorWidth = remember(width) {
if (width == 0f) {
1f
} else {
fun Modifier.swipeableLeftRight(onLeft: () -> Unit, onRight: () -> Unit): Modifier = composed {
var width by rememberSaveable { mutableStateOf(0f) }
val swipeableState = rememberSwipeableState(
SwipeDirection.Initial,
animationSpec = snap()
)
val anchorWidth = remember(width) {
if (width == 0f) {
1f
} else {
@PhilipDukhov
PhilipDukhov / EmptyNavigationLink.swift
Created September 10, 2021 12:39
NavigationLink with empty content and optional selection Binding
@Composable
fun <I, O> rememberLambda(lambda: (I) -> O) = remember { lambda }
@Composable
fun <I, O> rememberLambda(
key1: Any?,
lambda: (I) -> O
) = remember(key1) { lambda }
@Composable
@PhilipDukhov
PhilipDukhov / MiddleEllipsisText.kt
Created September 7, 2021 10:17
Middle ellipsis in Text for Jetpack Compose
@Composable
fun MiddleEllipsisText(
text: String,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
fontSize: TextUnit = TextUnit.Unspecified,
fontStyle: FontStyle? = null,
fontWeight: FontWeight? = null,
fontFamily: FontFamily? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,