Class Skeleton
A loading placeholder that stands in for content while it is being fetched.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class Skeleton : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder
Remarks
Skeleton is a plain, muted block that occupies the shape of the content it replaces. Give it the width and height of the thing that is loading, and stack several of them to sketch a paragraph, a card or a list row.
By default it pulses, fading between full and half opacity over a two second cycle. USS has no keyframe animations, so the pulse is driven from C# by a scheduled item that writes the element's opacity every frame. The driver only runs while the Skeleton is attached to a panel and animated is true, and it restores full opacity when it stops. Set animated to false for a static placeholder, for instance when honouring a reduced motion preference.
The Skeleton ignores pointer events, so it never steals input from the content around it.
Examples
A single line placeholder. The Skeleton takes the shape you give it.
var skeleton = new Skeleton();
skeleton.style.width = 200;
skeleton.style.height = 12;
parentElement.Add(skeleton);
Sketching a paragraph out of several placeholders.
var paragraph = new VisualElement();
foreach (var width in new[] { 100f, 80f, 60f })
{
var line = new Skeleton();
line.style.height = 12;
line.style.width = Length.Percent(width);
line.style.marginBottom = 6;
paragraph.Add(line);
}
A static placeholder, with no pulse.
<appui:Skeleton animated="false" />
Constructors
Skeleton()
Default constructor.
Declaration
public Skeleton()
Fields
animatedUssClassName
The styling class applied while the Skeleton pulses.
Declaration
public const string animatedUssClassName = "appui-skeleton--animated"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The Skeleton main styling class.
Declaration
public const string ussClassName = "appui-skeleton"
Field Value
| Type | Description |
|---|---|
| string |
Properties
animated
Whether the Skeleton pulses. True by default.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool animated { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
Set this to false for a static placeholder. Stopping the pulse restores the Skeleton to full opacity rather than leaving it wherever the last frame put it.