compose/remote/remote-creation/doc/guides/CREATION_DEMO_GUIDE.md
This guide describes how to write procedural drawing demos using the remote-creation APIs (without @Composable). These demos are used to test the core drawing, layout, and expression engine of RemoteCompose.
RemoteComposeWriter.RemoteComposeWriter (or RemoteComposeWriterAndroid) to define constants, expressions, and drawing commands.RemoteComposeWriter.A typical demo consists of:
RcPlatformServices.RemoteComposeWriterAndroid.floatConstant, floatExpression, etc.rc.root(...) to start the component tree.box, column, row, and startCanvas to structure and draw.import static androidx.compose.remote.core.RcProfiles.PROFILE_ANDROIDX;
import static androidx.compose.remote.creation.Rc.FloatExpression.MUL;
import static androidx.compose.remote.creation.Rc.FloatExpression.ADD;
import android.graphics.Color;
import android.graphics.Paint;
import androidx.compose.remote.creation.RemoteComposeWriterAndroid;
import androidx.compose.remote.creation.modifiers.RecordingModifier;
import androidx.compose.remote.creation.platform.AndroidxRcPlatformServices;
import androidx.compose.remote.core.RcPlatformServices;
public class MyDemo {
static RcPlatformServices sPlatform = new AndroidxRcPlatformServices();
public static RemoteComposeWriterAndroid createDemo() {
// 1. Initialize Writer (width, height, name, version, profile, platform)
RemoteComposeWriterAndroid rc = new RemoteComposeWriterAndroid(
500, 500, "MyDemo", 7, PROFILE_ANDROIDX, sPlatform);
// 2. Define dynamic variables
float time = RemoteComposeWriterAndroid.TIME_IN_CONTINUOUS_SEC;
float speed = rc.addFloatConstant(2.0f);
float animatedValue = rc.floatExpression(time, speed, MUL);
// 3. Define the UI Root
rc.root(() -> {
rc.box(new RecordingModifier().fillMaxSize().background(Color.LTGRAY), () -> {
rc.startCanvas(new RecordingModifier().size(200, 200));
// Drawing operations
rc.getPainter()
.setColor(Color.BLUE)
.setStyle(Paint.Style.FILL)
.commit();
rc.drawCircle(100, 100, 50);
rc.endCanvas();
});
});
return rc;
}
}
rc.floatExpression)Expressions allow you to define math that runs on the player (remote side) without re-sending the whole doc.
rc.addFloatConstant(value)rc.floatExpression(a, b, OP) where OP is from Rc.FloatExpression (e.g., ADD, MUL, SIN, COS, PINGPONG).rc.getPainter())The RemotePaint bridge allows you to set standard Android Paint properties which are then serialized.
.commit() after setting properties to sync them to the writer.rc.getPainter().setColor(Color.RED).setStrokeWidth(5).commit();rc.box(modifier, content)rc.column(modifier, horizontalAlign, verticalAlign, content)rc.row(modifier, horizontalAlign, verticalAlign, content)rc.startCanvas(modifier) / rc.endCanvas()RecordingModifier)Modifiers are chained to define layout behavior.
.fillMaxSize(), .fillMaxWidth(), .fillMaxHeight().width(w), .height(h), .size(w, h).padding(p), .background(color).visibility(id) (takes a remote ID)rc.addPathData(remotePath), rc.drawPath(pathId).rc.createTextFromFloat(...), rc.drawTextAnchored(...).rc.startLoopVar(start, step, end), rc.endLoop().To make a demo visible in the Player View Demos app, it must be registered in DemosCreation.java using getp:
// In DemosCreation.java
getp("Category/MyDemoName", MyDemo::createDemo),
getp(path, supplier): Standard procedural demo.getpc(path, supplier): Procedural demo that might need context (like Activity).When asking the agent to create a new demo:
RemoteComposeWriterAndroid and procedural layout."integration-tests/player-view-demos/src/main/java/androidx/compose/remote/integration/view/demos/examples/."DemosCreation.java."