Skip to content

UIView beta ​

A view node inside a UI panel.

Reach via representation.rootView for the panel's root content, or representation.findView(idOrName) for any descendant. The same class represents every kind (label, button, slider, etc.) – kind reports which one, and setProperty / getProperty accept keys appropriate to that kind. Setting an unsupported key for the kind is a no-op.

Mutations apply live to the existing view (no rebuild – the panel refreshes on the next frame on iOS; on visionOS the change is picked up automatically). For input controls that are bound to a variable, setProperty also writes back to that variable so observers (label ${var} templates, other reactive bindings) update – the same path the user-drag/tap valueChanged action takes. Controls set to a literal value don't write back.

Example:

javascript
const rep = scene.findEntity({ name: "Settings" }).representation;
rep.findView("save-btn").setProperty("title", "Done");
rep.findView({ name: "volume" }).bind("value", "vol");

Properties ​

background ​

  • Type: JSUIView[]
  • The views drawn behind this one, back to front. They never change its size or move its neighbours. Setting a list keeps the views it names that are already there, takes out the others and adds the new ones made with UI.*, for as long as the experience runs. Applies to: any kind.

id read-only ​

  • Type: string
  • Stable view ID set in the experience model.

image ​

  • Type: string
  • The SF Symbol an image shows, such as 'bolt.fill', in the image's colour and size; null when it shows a photo. Applies to: image.

isEnabled ​

  • Type: boolean
  • Interactive flag. Applies to: any kind.

isExpanded ​

  • Type: boolean
  • Whether the card is open. Applies to: annotation.

isHidden ​

  • Type: boolean
  • Visibility flag. Applies to: any kind.

isOn ​

  • Type: boolean
  • On/off state. Applies to: toggle.

kind read-only ​

  • Type: string
  • View kind as a string: "label", "button", "slider", "toggle", "textField", "stepper", "segmentedControl", "progressView", "image", "divider", "shape", "hStack", "vStack", "zStack", "spacer", "webView", "carousel", "annotation".

name read-only ​

  • Type: string
  • Optional human-readable name (mirrors representation.name).

offsetX ​

  • Type: number
  • Points the view moves right, on top of its authored offset, 0 by default. Applies to: any kind.

offsetY ​

  • Type: number
  • Points the view moves down, on top of its authored offset, 0 by default. Applies to: any kind.

opacity ​

  • Type: number
  • View opacity, 0–1. Applies to: any kind.

overlay ​

  • Type: JSUIView[]
  • The views drawn in front of this one, back to front. Set like background. Applies to: any kind.

placeholder ​

  • Type: string
  • Placeholder text. Applies to: textField.

progress ​

rotation ​

  • Type: number
  • Turn about the view's centre in radians, clockwise, 0 by default. Applies to: any kind.

scale ​

  • Type: number
  • Size about the view's centre, 1 by default. The layout keeps the view's own size. Applies to: any kind.

selectedIndex ​

  • Type: number
  • Index of the selected segment or child. Setting it on a carousel scrolls that child to the middle. Applies to: segmentedControl, carousel.

text ​

title ​

  • Type: string
  • Button title. Applies to: button.

value ​

Methods ​

add() ​

javascript
add(view: Object, options?: Object): JSUIView | any

Add a view made with UI.label(…), UI.shape(…) and the rest to this one while the experience runs. The panel keeps every other view as it is, with its state and animations.

Example:

javascript
// A red count badge centred on the button's top trailing corner.
var cart = panel.findView({ name: 'Cart' });
var badge = cart.add(UI.label({
    text: '3',
    padding: { vertical: 2, horizontal: 6 },
    placement: { alignment: 'topTrailing' },
    style: { foregroundColor: '#FFFFFF', backgroundColor: '#FF3B30', shape: 'capsule' }
}), { to: 'overlay' });

Parameters:

  • view (Object) - A view made with UI.*. Its placement sets where it sits in a background or overlay.
  • options (Object) (optional)
  • options.to (string) (optional) - 'children' of a VStack, HStack or ZStack, 'background' or 'overlay'.
  • options.at (number) (optional) - Its position in that list; last when left out.

Returns: JSUIView | any

animateTo() ​

javascript
animateTo(properties: Object, duration: number, options?: Object): Promise

Animate one or more numeric view properties to target values.

Example:

javascript
await label.animateTo({ opacity: 0 }, 0.3, { timingFunction: 'easeOut' });
// Spring a zoomed photo back to its size.
photo.animateTo({ scale: 1, offsetX: 0, offsetY: 0 }, 0.4, { spring: { duration: 0.4, bounce: 0.2 } });
// A ring that grows out of a marker and fades, again and again.
ring.scale = 1;
ring.opacity = 0.6;
ring.animateTo({ scale: 2.2, opacity: 0 }, 1.6, { timingFunction: 'easeOut', repeatCount: -1 });
// Later: ring.stopAnimations();

Parameters:

  • properties (Object) - Map of propertyName → target numeric value.
  • duration (number) - Seconds.
  • options (Object) (optional)
  • options.timingFunction (string) (optional) - 'linear' | 'easeIn' | 'easeOut' | 'easeInOut'
  • options.spring (Object) (optional) - Spring timing instead of duration and timingFunction, as in animateValue.
  • options.spring.duration (number) (optional) - The spring's perceived duration in seconds; it settles a little later.
  • options.spring.bounce (number) (optional) - 0 settles without overshoot, higher values bounce.
  • options.velocity (Object) (optional) - Map of propertyName → speed per second at the start of a spring, such as a gesture's speed when the finger lifts, so the motion carries on from it.
  • options.repeatCount (number) (optional) - Number of times to repeat (-1 for infinite).
  • options.repeatMode (string) (optional) - "default" starts each repeat over, "autoReverse" plays every other one backwards.

Returns: Promise

bind() ​

javascript
bind(propertyName: string, variableName: string, options?: Object): JSUIView

Bind a property to an experience variable. Sugar for bindProperty.

Example:

javascript
panel.findView({ name: 'vol' }).bind('value', 'volume');

Parameters:

  • propertyName (string) - Property to bind ('value', 'isOn', 'text', ...). Kind-specific.
  • variableName (string) - Variable identifier in the experience.
  • options (Object) (optional) - { scope: 'segment' | 'experience' }. Defaults to 'segment'.

Returns: JSUIView

bindProperty() ​

javascript
bindProperty(propertyName: string, variableName: string, options?: any): void

Bind a property to an experience variable at runtime. Variable changes flow into the live view; for input controls, user input flows back into the variable. Calling bindProperty again on the same property replaces the existing binding. Does not mutate the saved model – bindings last as long as the panel, until unbindProperty or a panel rebuild removes them.

Example:

javascript
slider.bindProperty("value", "volume");
slider.bindProperty("value", "globalVol", { scope: "experience" });

Parameters:

  • propertyName (string) - Property to bind ("value", "isOn", "text", etc.). Kind-specific.
  • variableName (string) - Variable identifier in the experience.
  • options (any) (optional) - Optional { scope: "segment" | "experience" }. Defaults to "segment".

Returns: void

copy() ​

javascript
copy(): Object | any

A copy of this view and every view inside it as authored in the editor, ready for add. A script's changes to the original, such as a new text, are not in the copy. Every copy gets new ids and keeps the names and the translations, so find views inside it with row.findView(...).

Use it to build a list from one sample cell authored in the editor: add a copy per item, fill it in, then hide the sample.

Example:

javascript
var sample = panel.findView({ name: 'Row' });
var list = panel.findView({ name: 'Rooms' });
['Kitchen', 'Studio', 'Garden'].forEach(function(room) {
    var row = list.add(sample.copy());
    row.findView({ name: 'Row Name' }).text = room;
    row.on('tap', function() { console.log(room); });
});
sample.isHidden = true;

Returns: Object | any

enablePinchZoom() ​

javascript
enablePinchZoom(options?: Object): any

Let two fingers zoom this view, about the point between them, and move it while zoomed.

Built on on('pinch') and the scale, offsetX and offsetY properties, so it works where those do: panels on the screen on iPhone, iPad and Mac. A new pinch catches the view where a running spring has it.

Example:

javascript
var photo = panel.findView({ name: 'Room photo' });
photo.enablePinchZoom({ maxScale: 3 });

Parameters:

  • options (Object) (optional)
  • options.minScale (number) (optional) - Smallest scale a pinch reaches.
  • options.maxScale (number) (optional) - Largest scale a pinch reaches.
  • options.releaseBehavior (string) (optional) - 'reset' springs back to the view's size and place when the fingers lift, 'stay' keeps the zoom. The same names as the gestures on 3D objects.

Returns: any

fadeIn() ​

javascript
fadeIn(duration?: number): Promise

Fade view to fully opaque.

Parameters:

  • duration (number) (optional)

Returns: Promise

fadeOut() ​

javascript
fadeOut(duration?: number): Promise

Fade view to fully transparent.

Parameters:

  • duration (number) (optional)

Returns: Promise

findView() ​

javascript
findView(query: any): UIView

Find a view inside this one by ID or name, this view included.

Views added from a copy keep the copied names, so search inside the copy rather than the whole panel.

Example:

javascript
var row = group.add(sample.copy());
row.findView({ name: "Row Name" }).text = "Toilets";

Parameters:

  • query (any) - View ID string, or object with { id: "..." } or { name: "..." }

Returns: UIView

getProperty() ​

javascript
getProperty(name: string): any

Read a property by key

Example:

javascript
var title = button.getProperty("title");
var value = slider.getProperty("value");

Parameters:

  • name (string) - Property key (e.g. "text", "value", "isHidden"). Keys are kind-specific.

Returns: any

off() ​

javascript
off(subscriptionId: string): void

Remove an interaction listener by subscription id.

Parameters:

  • subscriptionId (string)

Returns: void

on() ​

javascript
on(type: string, listener: function): string

Subscribe to a UI interaction on this view.

Supported types per kind: - 'tap' → any kind. On a button it fires in every panel; on other kinds in panels on the screen. - 'valueChanged' → slider, segmentedControl, carousel (uiValue is the selected child's index, sent when a scroll or tap settles) - 'scroll' → carousel (uiValue is the position in the middle as a child index, fractional between two children, sent on every scroll step) - 'toggled' → toggle, annotation - 'textChanged' → textField - 'pinch', 'pan', 'rotate' → any kind, in panels on the screen on iPhone, iPad and Mac. A panel placed in 3D and Apple Vision Pro don't deliver them; check environment.features.has('screenGestures'). A view inside a carousel takes 'pinch' and 'rotate' but not 'pan', since the carousel scrolls.

The listener receives { uiNodeId, uiInteractionKind, uiValue? }, matching the payload authored UI-interaction events emit. Gestures add, like the scene's own pan, pinch and rotate events: - phase: 'began', 'changed' or 'ended' (not on 'tap') - position, beganPosition (Vector2): points from where the view's top-left corner sits untransformed, so the view's own scale or offset doesn't change them - size (Vector2): the view's size in points, untransformed - 'pinch': scale since the pinch began and velocity, per second - 'rotate': rotation in radians since it began and velocity, radians per second - 'pan': translation (Vector2) in points since it began and velocity (Vector2), points per second

Example:

javascript
slider.on('valueChanged', function(e) { console.log('slider →', e.uiValue); });
button.on('tap', function() { console.log('clicked'); });
photo.on('pinch', function(e) { console.log(e.phase, e.scale); });

Parameters:

  • type (string) - Interaction type.
  • listener (function) - Callback receiving the event payload.

Returns: string

once() ​

javascript
once(type: string, listener: function): string

Subscribe to a single UI interaction; auto-unsubscribes after first fire.

Parameters:

  • type (string)
  • listener (function)

Returns: string

remove() ​

javascript
remove(): void

Take this view and every view inside it out of the panel while the experience runs, stopping their animations.

Example:

javascript
badge.remove();

Returns: void

scrollTransition() ​

javascript
scrollTransition(effect: { scale, opacity, rotation, tilt, offset: [along, across], clamp }): void

Shrinks, fades, turns or moves carousel children by their distance from the middle. On a carousel it applies to every child; on a view inside a child it applies to that view, which gives parallax. Values are what a child one step from the middle gets (its own length plus the spacing); the middle child gets none, children in between blend.

Example:

javascript
rep.findView({ name: "rooms" }).scrollTransition({ tilt: Math.toRadians(35), scale: 0.85, opacity: 0.5 });
rep.findView({ name: "photo" }).scrollTransition({ offset: [-30, 0] });

Parameters:

  • effect ({ scale, opacity, rotation, tilt, offset: [along, across], clamp }) - rotation and tilt are radians. Children before the middle turn, tilt and move the other way. clamp: false lets children further away keep changing. scale and opacity replace the carousel's Neighbor Scale and Opacity. null removes the effect.

Returns: void

scrollWith() ​

javascript
scrollWith(e: Object): void

Scroll this carousel with a pan that began somewhere else, as a swipe on the carousel itself would: it follows the finger, stretches past the first and last child, coasts after a flick and snaps to a child. Pass every event of a scene.on('pan') or view.on('pan') listener.

A scene pan that began on an object the viewer can drag, or on a panel placed in 3D, moves that instead and doesn't scroll the carousel. Taps on the scene keep working, since a tap is no pan.

Example:

javascript
var rooms = panel.findView({ name: 'Rooms' });
// Swipes on the scene above the carousel scroll it too.
scene.on('pan', { area: [0, 0.45, 1, 0.35] }, function(e) {
    rooms.scrollWith(e);
});

Parameters:

  • e (Object) - The pan event: phase and translation in points. On a scene pan, beganOnDraggable marks a pan that started on an object or a panel in 3D.

Returns: void

setProperty() ​

javascript
setProperty(name: string, value: any): void

Write a property by key. Live-updates the rendered view; for input controls bound via .reference, also writes back to the bound variable so observers see the change. No view tree rebuild.

Example:

javascript
label.setProperty("text", "Hello");
slider.setProperty("value", 0.5);
view.setProperty("isHidden", true);

Parameters:

  • name (string) - Property key (e.g. "text", "value", "isHidden"). Keys are kind-specific.
  • value (any) - New property value. Type must match the property; mismatches are no-ops.

Returns: void

stopAnimations() ​

javascript
stopAnimations(): void

Stop the animations animateTo started on this view. The view keeps the values it has now.

Example:

javascript
ring.stopAnimations();

Returns: void

unbind() ​

javascript
unbind(propertyName: string): JSUIView

Remove a runtime binding installed via bind().

Parameters:

  • propertyName (string)

Returns: JSUIView

unbindProperty() ​

javascript
unbindProperty(propertyName: string): void

Remove a runtime binding installed via bindProperty. The property keeps its current displayed value but no longer reacts to the variable; user input on the property no longer writes back. No-op if no binding exists for propertyName.

Example:

javascript
slider.unbindProperty("value");

Parameters:

  • propertyName (string) - Property previously passed to bindProperty.

Returns: void