I'm currently experimenting with the new Jetpack Compose UI toolkit and for now I really love it. With the following code I can draw any shape on the screen, make it clickable and move it around:
@Composable fun Shape( color: Color, @FloatRange(from = 0.0, to = 1.0) transparency: Float, strokeWidth: Dp, onMoveShape: (dragAmount: Offset) -> Unit, builder: Path.(size: Size, layoutDirection: LayoutDirection) -> Unit ) { val fillColor = color.copy(transparency) val drawingShape = GenericShape(builder) val position = Modifier.fillMaxSize() val border = Modifier.border(strokeWidth, color, drawingShape) val background = Modifier.background(fillColor, drawingShape) val clip = Modifier.clip(drawingShape) val clickListener = Modifier.clickable { /* ... */ } val dragListener = Modifier.draggable { change, dragAmount -> change.consumeAllChanges() onMoveShape(dragAmount) } Box(position + border + background + clip + clickListener + dragListener) } The onMoveShape callback moves the points used in the builder around which triggers a recomposition which works great. My problem here is that the area from where I can start the drag and click events does not update when I move the shape. I think it's best to explain that in this screenshot:
I removed the code for the red dots above since it is not important for the question. I guess since the click and drag listeners do not depend on the drawingShape they don't get recomposed and that's why the area is not updated. Any ideas how I can archive this?
The + for Modifier and the draggable Modifier are extension functions btw.
