Stefan Oltmann
09/30/2021, 11:55 AMCasey Brooks
09/30/2021, 2:46 PMModifier.graphicsLayer()
includes a rotationZ
property, so i'd think combining that with Modifier.pointerMoveFilter(onMove = { ... })
and a bit of math should get you pretty closeStefan Oltmann
09/30/2021, 2:49 PMStefan Oltmann
09/30/2021, 6:50 PMrotationX
result in the same angle. 🤷♂️
Other than that I think I'm pretty close to a solution.Stefan Oltmann
09/30/2021, 6:52 PMval offset = remember { mutableStateOf(Offset.Zero) }
val size = remember { mutableStateOf(IntSize.Zero) }
val rotationX = if (offset.value == Offset.Zero)
0f
else
((offset.value.y / size.value.height) - 0.5f) * 90
val rotationY = if (offset.value == Offset.Zero)
0f
else
((offset.value.x / size.value.width) - 0.5f) * 90
Box(
modifier = Modifier
.graphicsLayer(
rotationX = rotationX,
rotationY = rotationY
)
.pointerMoveFilter(
onExit = {
offset.value = Offset.Zero
return@pointerMoveFilter true
},
onMove = {
offset.value = it
return@pointerMoveFilter true
}
)
.onSizeChanged {
size.value = it
}
) {
// The content
}
}
}
My solution so far.Stefan Oltmann
09/30/2021, 6:53 PMseb
09/30/2021, 8:59 PMStefan Oltmann
10/01/2021, 7:42 AMIgor Demin
10/01/2021, 8:30 AMbut there seems to be an bug that negative and positive values torotationX/rotationY currently don't work well: https://github.com/JetBrains/compose-jb/issues/12 Not sure when we will fix it, depends on how important it is to other people in compare to other issues.result in the same anglerotationX
Stefan Oltmann
10/01/2021, 8:30 AMStefan Oltmann
10/01/2021, 8:38 AMIgor Demin
10/01/2021, 8:39 AMStefan Oltmann
10/01/2021, 8:42 AM