diff --git a/app/src/main/java/hu/bme/kszk/szobatarsch/composable/FindPeople.kt b/app/src/main/java/hu/bme/kszk/szobatarsch/composable/FindPeople.kt index 820cc6c27f73ac0edce3d1fe5907b62f61e80d45..fd9785b98359652afae1816911b3c06b87f34065 100644 --- a/app/src/main/java/hu/bme/kszk/szobatarsch/composable/FindPeople.kt +++ b/app/src/main/java/hu/bme/kszk/szobatarsch/composable/FindPeople.kt @@ -1,7 +1,86 @@ package hu.bme.kszk.szobatarsch.composable -import androidx.compose.runtime.Composable +import androidx.compose.animation.core.animateDpAsState +import androidx.compose.animation.core.animateFloatAsState +import androidx.compose.foundation.gestures.detectDragGestures +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.offset +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.* +import androidx.compose.runtime.* +import androidx.compose.ui.ExperimentalComposeUiApi +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.rotate +import androidx.compose.ui.input.pointer.pointerInput +import androidx.compose.ui.platform.LocalConfiguration +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +@OptIn(ExperimentalComposeUiApi::class, ExperimentalMaterial3Api::class) @Composable fun FindPeople() { + + + val items = remember { mutableStateListOf<Int>() } + + LaunchedEffect(Unit) { + (1..5).forEach { items += it } + } + + val width = LocalConfiguration.current.screenWidthDp.dp + val density = LocalDensity.current + fun Float.pxToDp() = with(density) { this@pxToDp.toDp() } + + val edge = width + 100.dp + val sens = width / 2 + + val degPerDp = 20 / width.value + fun Dp.getRotation() = value * degPerDp + + Box() { + items.forEach { + var offset by remember { mutableStateOf(0.dp) } + + val animatedOffset by animateDpAsState( + targetValue = offset, + finishedListener = { off -> + if (off == edge) { + items -= it + } else if (off == -edge) { + items -= it + } + }, + ) + + Card( + modifier = Modifier + .pointerInput(Unit) { + detectDragGestures( + onDragEnd = { + offset = if (offset > sens) { + edge + } else if (offset < -sens) { + -edge + } else { + 0.dp + } + }, + onDrag = { change, amount -> + offset += amount.x.pxToDp() + change.consume() + }, + ) + } + .offset(x = animatedOffset) + .rotate(animatedOffset.getRotation()) + .fillMaxSize() + .padding(8.dp), + elevation = CardDefaults.cardElevation(defaultElevation = 10.dp) + ) { + Text(it.toString()) + } + } + } } \ No newline at end of file