Composable Function

RemoteCanvas

A Composable that provides a RemoteDrawScope for drawing operations in RemoteCompose.

RemoteCanvasSample

@Sampled
@Preview
@PreviewWrapper(RemoteComponentPreviewWrapper::class)
@Composable
fun RemoteCanvasSample() {
    RemoteCanvas(modifier = RemoteModifier.size(100.rdp)) {
        val paint = RemotePaint().apply { color = Color.Red.rc }
        drawCircle(paint = paint, radius = 50.rf)
    }
}

RemoteCanvasAnimationSample

@Sampled
@Preview
@PreviewWrapper(RemoteComponentPreviewWrapper::class)
@Composable
fun RemoteCanvasAnimationSample() {
    // Uses RemoteTimeVariables.continuousSeconds for time-based remote canvas animation.
    RemoteCanvas(modifier = RemoteModifier.size(100.rdp)) {
        val paint = RemotePaint().apply { color = Color.Blue.rc }

        val time = RemoteTimeVariables.continuousSeconds

        // Oscillate radius between 10 and 40
        val sineValue = sin(time)
        val normalizedSine = (sineValue + 1f.rf) / 2f.rf
        val radius = 10f.rf + 30f.rf * normalizedSine

        drawCircle(paint = paint, radius = radius)
    }
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: