Rive Canvas Session
An entry point for Rive to render to a hardware accelerated Canvas using hardware bitmaps.
⚠️ This class must be closed when you no longer need it to free its resources. Call this only from the main thread.
The session manages an advance and render loop after calling beginPlaying. While this render loop will produce bitmaps, it is the caller's responsibility to present them on a canvas using draw. Collect frameAvailable to know when new frames are available after rendering.
Callers must pass touch events to the session with onTouchEvent to apply them to the state machine. Coordinates of the events are expected to be in the same space as the destination canvas of draw, and will be mapped into the render region.
All instance methods are expected to be called on Android's main thread. Calling instance methods after close throws IllegalStateException (except repeated close, which remains idempotent).
Call setRegion with the destination rectangle where frames should be presented. The render buffer dimensions are derived from this region's width and height.
If viewModelInstance is supplied, this session binds it eagerly during initialization.
This session is backed by a HardwareRenderBuffer. It owns that buffer's lifecycle and frame loop, but not the supplied Rive resources. These must be created and closed by the caller, and must outlive this session. The session will check that the supplied resources are from the same RiveWorker instance, but does not check that they are valid or properly initialized.
The supplied riveWorker must be polled for messages. This is done separately from this session using RiveWorker.beginPolling, so that the caller can manage the worker lifecycle and share it across multiple sessions.
Parameters
The Rive worker that holds the resources to render. See the note above regarding polling.
The artboard to render. Must be from the supplied riveWorker.
The state machine to advance and render. Must be from the supplied artboard.
An optional view model instance to bind to the state machine. Must be from the supplied riveWorker.
The Fit to use when rendering. This controls how the artboard is scaled to fit the target surface. Defaults to RenderingDefaults.defaultFit.
The color used to clear the draw region before drawing each frame. Defaults to RenderingDefaults.CLEAR_COLOR.
Constructors
Properties
Functions
Runs the advance and render loop while lifecycle is RESUMED.
Draws the latest rendered bitmap into the configured draw region of the canvas, if available.
Forwards touch events to the state machine pointer APIs.
Update the target draw region for rendering. This should be called at least once to initialize the session, and whenever the region changes.