The Fit Mode
A Rive graphic authored in the editor will not necessarily match the size of the container (canvas, view, widget, or texture) it is rendered into at runtime. We need to determine the behavior for this scenario, as no one size fits all. The solution is choosing the fit mode. This is specified on the container and controls how Rive is scaled.-
Layout: Use the Rive layout engine to apply responsive layout to the artboard, matching the container dimensions. For this to work, the artboard must be designed with layouts in mind. See Responsive Layouts for more information on how to use this option. -
Contain: (Default) Preserve aspect ratio and scale the artboard so that its larger dimension matches the corresponding dimension of the container. If aspect ratios are not identical, this will leave space on the shorter dimension’s axis. -
ScaleDown: Preserve aspect ratio and behave likeContainwhen the artboard is larger than the container. Otherwise, use the artboard’s original dimensions. -
Cover: Preserve aspect ratio and scale the artboard so that its smaller dimension matches the corresponding dimension of the container. If aspect ratios are not identical, this will clip the artboard on the larger dimension’s axis. -
FitWidth: Preserve aspect ratio and scale the artboard width to match the container’s width. If the aspect ratios between the artboard and container do not match, this will result in either vertical clipping or space in the vertical axis. -
FitHeight: Preserve aspect ratio and scale the artboard height to match the container’s height. If the aspect ratios between the artboard and container do not match, this will result in either horizontal clipping or space in the horizontal axis. -
Fill: Do not preserve aspect ratio and stretch to the container’s dimensions. -
None: Do not scale. Use the artboard’s original dimensions. For either dimension, if the artboard’s dimension is larger, it will be clipped. If it is smaller, it will leave space.
Alignment
In all options other thanLayout and Fill, there is the possibility that the Rive graphic is clipped or leaves space within its container. Alignment determines how to align content aligns with within the container. The following options are available.
TopLeftTopCenterTopRightCenterLeftCenter(Default)CenterRightBottomLeftBottomCenterBottomRight
Bounds
Some runtimes expose the option to set the bounding dimensions for the area in which the Rive content will render by providing the minimum and maximum x and y coordinates. These coordinates are relative to the container and all must be provided. These will override alignment settings.minXminYmaxXmaxY
Applying the Fit Mode
- Web
- React
- React Native
- Flutter
- Apple
- Android
Responsive Layouts
Rive’s layout feature lets you design resizable artboards with built-in responsive behavior, configured from the editor. Ensure the fit mode is set to Layout at runtime and the artboard will resize to fill its container according to the constraints defined in the editor. Optionally you may provide a layout scale factor to multiply the scale of the content. This allows fine tuning the visual size within your container. This property only applies when setting the Fit mode to Layout. For more Editor information and how to configure your graphic, see Layouts Overview.- Web
- React
- React Native
- Flutter
- Apple
- Android
Steps
- Set
fittoFit.Layout- this will automatically scale and resize the artboard to match the canvas size when callingresizeDrawingSurfaceToCanvas(). - Optionally set
layoutScaleFactorfor manual control of the artboard size (scale factor). - Subscribe to
window.onresizeand callresizeDrawingSurfaceToCanvas()to adjust the artboard size as the canvas and window changes. - Subscribe to device pixel ratio changes and call
resizeDrawingSurfaceToCanvas()to ensure the artboard updates correctly on various screen densities. For example, when dragging the window between multiple monitors with different device pixel ratios.