https://kotlinlang.org logo
#compose
Title
# compose
w

Wajahat Karim

08/26/2020, 10:29 AM
What is the replacement for
Draw
composable. I can see in previous early versions like dev07 or dev08, there used to be a
Draw
composable through which we could render other composables on Canvas. I want to rotate a
@Composable()
method. Old code is like this:
Copy code
@Composable
      fun Rotate(degree: Float, children: @Composable() () -> Unit) {
          Draw(children = children) { canvas, parent ->
              val halfWidth = parent.width.value / 2
              val halfHeight = parent.height.value / 2

              canvas.save()
              canvas.translate(halfWidth, halfHeight)
              canvas.rotate(degree)
              canvas.translate(-halfWidth, -halfHeight)
              drawChildren()
              canvas.restore()
          }
      }
l

len

08/26/2020, 11:04 AM
You can probably use the
drawLayer
modifier with a
rotationZ
parameter on the view you want to rotate
w

Wajahat Karim

08/26/2020, 12:05 PM
Thanks. This is what I needed.
3 Views