Jetpack Compose Generative Canvas State Matrix
Design a rock-solid state management and gesture matrix for interactive, generative inpainting and multimodal canvas UI.
Use this template when designing interactive Android UI components that handle multimodal image prompts, live masking, and generative feedback loops. It establishes a complete state-machine matrix across Compose lifecycles and background diffusion tasks.
Role: Staff Android UI Systems Engineer specializing in Jetpack Compose architecture, custom graphics rendering, and generative UI workflows.
Context
- UI Framework Version: {{compose_version}}
- Generation Latency Threshold: {{inpainting_latency_threshold}}
- Canvas Mask Resolution: {{brush_mask_resolution}}
- Backend Generation Route: {{diffusion_backend_endpoint}}
- State Restoration Pattern: {{state_restoration_strategy}}
- Android Minimum SDK: {{target_api_level}}
Task
Produce an exhaustive declarative UI state matrix and gesture dispatch specification for a multimodal generative canvas, ensuring deterministic transitions between user sketching, prompt submission, asynchronous diffusion, and final rendering.
Method
- Map user touch and stylus interactions (brush strokes, mask erasure, bounding boxes) to declarative state holders within {{compose_version}}.
- Define bitmap mask serialization pathways supporting {{brush_mask_resolution}} without blocking the Android main thread.
- Model lifecycle transitions (configuration changes, app backgrounding) using {{state_restoration_strategy}} during active generation.
- Design perceptual latency mitigations (shimmer overlays, progressive tile reveals) for operations taking up to {{inpainting_latency_threshold}}.
- Formulate network and on-device fallback dispatch logic targeting {{diffusion_backend_endpoint}}.
- Evaluate low-memory event handling and graphics memory reclaiming across devices on {{target_api_level}}.
- Construct a state-to-event dispatch matrix linking every UI event to ViewModel mutations and side effects.
Constraints
- State definitions MUST obey strict unidirectional data flow (UDF) conventions.
- MUST NOT perform synchronous bitmap allocations or tensor preprocessing on the main UI thread.
- Canvas rendering logic MUST be fully functional across all versions supported by {{target_api_level}}.
- Every intermediate generative state MUST define explicit error and retry transitions.
Output format
Provide the architectural specification organized as:
- Section 1: Canvas Interaction & Gesture State Matrix (Markdown table mapping Gestures, Compose State, Pointer Events, and Redraw Triggers)
- Section 2: Generation Lifecycle & Async Pipeline Matrix (Markdown table mapping Task Status, UI Feedback, Network Event, and Error Boundary)
- Section 3: State Restoration & Memory Eviction Matrix (Markdown table detailing Process Death, Configuration Change, and Low-Memory Scenarios)
- Section 4: Jetpack Compose State Interface Blueprint (Kotlin pseudo-code, under 40 lines)
Self-review
- Ensure all variables are properly interpolated in the method and constraints.
- Check that the gesture matrix accounts for high-frequency stylus input without frame drops.
- Confirm clear distinction between local mask rendering and remote generation dispatch.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.