android-custom-drawing-canvas
Skill11 starsChanged 8 months agoMITView on GitHub
Use when creating custom UI components, charts, shaders, or hardware-accelerated drawing in Android with Jetpack Compose Canvas.
In this repository40 other files it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
- android-accessibilitySkill
- android-adaptive-layoutsSkill
- android-adb-terminalSkill
- android-background-executionSkill
- android-bluetooth-bleSkill
- android-build-verificationSkill
- android-camerax-mlkitSkill
- android-ci-cd-expertSkill
- android-clean-architectureSkill
- android-code-review-expertSkill
- android-coroutines-expertSkill
- android-design-system-m3Skill
- android-design-to-codeSkill
- android-detekt-expertSkill
- android-enterprise-securitySkill
- android-gemini-nanoSkill
- android-google-workspace-expertSkill
- android-gradle-expertSkill
- android-hardware-testingSkill
- android-jetpack-composeSkill
- android-kmp-compose-uiSkill
- android-kmp-platform-channelsSkill
- android-kmp-sharedSkill
- android-ktlint-formattingSkill
- android-lint-and-qualitySkill
- android-local-stt-ttsSkill
- android-location-mapsSkill
- android-macrobenchmarkSkill
- android-media3-exoplayerSkill
- android-media-and-image-expertSkill
- android-motion-animationsSkill
- android-navigation-expertSkill
- android-offline-firstSkill
- android-performance-auditSkill
- android-rag-localSkill
- android-screenshot-testingSkill
- android-security-hardenedSkill
- android-unit-testingSkill
- android-wear-os-composeSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 4 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 30
Rule: Use Modifier.drawBehind { ...
- Distinctive: line 56
Use for complex shapes (Stars, Polygons, Waves).
- Very specific: line 57
Use Path() and methods like moveTo, lineTo, cubicTo.
- Very specific: line 69
Labels: Don't draw complex text with drawText if you can use Text composables with Layout.
- Very specific: line 70
Interactivity: Use detectDragGestures or detectTapGestures to make your custom drawings interactive.
- Very specific: line 71
Smoothness: Use animateFloatAsState to animate chart values during transitions.
- Distinctive: line 75
Screenshot Testing: ALWAYS use screenshot tests for custom Canvas components to catch pixel-level regressions.
- Distinctive: line 76
Layout Inspector: Verify that your Canvas component isn't causing excessive recompositions.
- Distinctive: line 77
Hardware Profile: Ensure the "GPU rendering" bar doesn't cross the threshold during complex animations.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Android Custom Drawing & Canvas ✏️🎨
Advanced strategies for high-performance, pixel-level custom UI components, data visualization, and creative graphics in Jetpack Compose.
⚡ When to Use
- Custom Charts: Drawing pie, bar, or line charts with precise control.
- Complex UI Elements: Building circular progress bars or custom sliders.
- Graphic Effects: Applying shaders (AGSL), gradients, or masks.
- Dynamic Graphics: Hand-drawn signatures or interactive shapes.
- Particle Systems: Drawing lightweight, dynamic visual effects.
🏗️ Drawing with Canvas
- Rule: Use
Modifier.drawBehind { ... }orCanvas(modifier = ...) { ... }. - Coordinate System: (0,0) is TOP-LEFT.
- Draw Scope: Access built-in methods like
drawRect,drawCircle,drawPath.
1. Drawing a Circular Progress Bar
Canvas(modifier = Modifier.size(100.dp)) {
val strokeWidth = 8.dp.toPx()
drawArc(
color = Color.LightGray,
startAngle = 0f,
sweepAngle = 360f,
useCenter = false,
style = Stroke(width = strokeWidth)
)
drawArc(
color = Color.Blue,
startAngle = -90f,
sweepAngle = progress * 360f,
useCenter = false,
style = Stroke(width = strokeWidth, cap = StrokeCap.Round)
)
}2. The Path API
- Use for complex shapes (Stars, Polygons, Waves).
- Use
Path()and methods likemoveTo,lineTo,cubicTo. - Rule: Reuse the
Pathobject if possible to avoid allocations in the drawing loop.
🚀 Performance & Tips
- Avoid Object Allocation: Never create
Paint,Path, orBrushobjects insidedrawBehind. Create them withrememberoutside. - Use
graphicsLayer: Move drawing into a separate layer for better hardware acceleration and cacheability. - Pixel Conversion: Use
toPx()carefully within theDrawScope. Keep dimensions consistent. - AGSL Shaders: For Android 13+, use
RuntimeShaderfor professional-grade effects (Blur, Wave, Noise).
📐 Chart Design Best Practices
- Labels: Don't draw complex text with
drawTextif you can useTextcomposables withLayout. - Interactivity: Use
detectDragGesturesordetectTapGesturesto make your custom drawings interactive. - Smoothness: Use
animateFloatAsStateto animate chart values during transitions.
🧪 Testing and Verification
- Screenshot Testing: ALWAYS use screenshot tests for custom Canvas components to catch pixel-level regressions.
- Layout Inspector: Verify that your Canvas component isn't causing excessive recompositions.
- Hardware Profile: Ensure the "GPU rendering" bar doesn't cross the threshold during complex animations.
📜 Checklist for Canvas Components
- Accessibility: Does the canvas component have a
clearAndSetSemanticsentry with a proper description? - Theming: Does the drawing use
MaterialTheme.colorSchemecolors? - Density Independence: Does it look correct on both low and high-density screens?
- Performance: Are expensive path calculations cached?
🔗 Related Resources
- Compose Graphics Documentation
- AGSL Shaders Guide
- Screenshot Testing Skill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

