Skip to main content

Architecture

How UI Kit 4.0.0 components combine an Element (logic) and a Visual (appearance) into a VisualElement, using the Button component as the example.

  • Snapchat: not supported
  • SPECS: fully supported
  • Camera Kit Web: not supported
  • Camera Kit Mobile: not supported
  • SnapchatNot supported
  • SPECSFully supported
  • Camera Kit WebNot supported
  • Camera Kit MobileNot supported

Platform details

  • Snapchat — Not supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Not supported.

  • Camera Kit Mobile — Not supported.

Most UI Kit components are built from two halves: an Element, which holds the component's logic, and a Visual, which draws it. This page explains how the two fit together, for developers who want to create a custom visual or extend a component.

How a UI Kit element is built from an Element and a Visual

A UI Kit component is often a combination of a Visual and an Element. The Visual is the graphical representation of the component, while the Element is the logic for the component. The Element creates the underlying colliders and Interaction Kit interactables, and hooks into Interaction Kit events to handle interactions. The Visual animates the component based on the events it receives from the Element.

The combination of the two is called a VisualElement. A VisualElement fuses the Visual and the Element together and handles the connections between the two sides. It also carries the settings every visual component shares, such as Has Shadow and Theme.

The Button component as an example of the UI Kit architecture

The UI Kit Button component shows the typical architecture of a UI Kit element:

Element
└── VisualElement ──────────► Visual
└── BaseButton ├── RoundedRectangleVisual ──► RoundedRectangle
└── Button ─────────────┤ (default)
└── BeveledPrismVisual
(System 3.0 Prism and PrismGhost styles)
  • VisualElement is the base for every visual component and owns a Visual.
  • BaseButton is the VisualElement for buttons: it adds the trigger events and the toggle behavior that every button shares.
  • Button is a specific BaseButton. When you don't assign a visual yourself, it creates a RoundedRectangleVisual by default. On the System 3.0 theme, the Prism and PrismGhost styles create a BeveledPrismVisual instead.

Which style a Visual draws comes from the theme: each theme defines the styles of each component, and the component's Theme setting picks the theme (System 3.0 unless you choose otherwise).

The earlier button classes, RectangleButton, CapsuleButton, and RoundButton, follow the same pattern but are deprecated in UI Kit 4.0.0; use Button with a Shape instead. See Button.