Mehdi Haghgoo
05/17/2022, 4:27 AMChris Sinco [G]
05/17/2022, 4:33 AMMehdi Haghgoo
05/17/2022, 4:46 AMKirill Grouchnikov
05/17/2022, 4:47 AMMehdi Haghgoo
05/17/2022, 4:48 AMvar offsetX by remember{mutableStateOf(0f)}
var offsetY by remember{mutableStateOf(0f)}
Canvas(
Modifier
.pointerInput(Unit){
detectDragGestures{change,dragAmount->
offsetX += dragAmount.x
offsetY += dragAmount.y
}
}
.offset{IntOffset(x=offsetX.roundToInt(), y = offsetY.roundToInt())}
.padding(8.dp)
.size(100.dp)
.border(1.dp, Color.Blue)
.background(Color.Cyan)
.drawBehind {
drawCircle(Color.Red, size.minDimension/3)
}
){
Chris Sinco [G]
05/17/2022, 5:06 AMMehdi Haghgoo
05/17/2022, 5:17 AMChris Sinco [G]
05/17/2022, 5:23 AM@Preview
@Composable
fun DragTest() {
MaterialTheme {
var offsetX by remember{ mutableStateOf(0f) }
var offsetY by remember{ mutableStateOf(0f) }
Surface {
Box(Modifier.fillMaxSize()) {
Canvas(
Modifier
.size(60.dp)
.border(4.dp, Color.Green)
.pointerInput(Unit) {
detectDragGestures{ change, dragAmount->
offsetX += dragAmount.x
offsetY += dragAmount.y
}
}
.offset { IntOffset(x = offsetX.roundToInt(), y = offsetY.roundToInt()) }
.padding(8.dp)
.size(100.dp)
.border(1.dp, Color.Blue)
.background(Color.Cyan)
.drawBehind {
drawCircle(Color.Red, size.minDimension/3)
}
) {}
}
}
}
}