HomeGuidesAPI ReferenceChangelogDiscussions
Hire a ReactVision Expert 🛠️Launch Studio 🖥️Sponsor on GitHub ❤️Log In
Guides

ViroController

UI Control through which the user interacts with the 3D world, enabled by default. In daydream, this would represent the daydream controller and it's laser pointer. In cardboard ios, cardboard Android and GearVR, the controller is effectively the reticle.

The ViroController is also notified of all events that occur within the scene, with the exception of hover. Thus, include this controller in your scene if you would like to register to be always notified of such events. You can also toggle certain UI expects of the controller as well, such as reticle or daydream visibility.

Platform support (3.2.0+)

Every platform takes the same handlers. Each is delivered where the input produces it.

HandleriOSAndroidMeta QuestWeb (3.2.3+)
onClick, onClickState, onFuse✅✅✅✅
onDrag✅✅✅✅
onPinch, onRotate (touch screen)✅✅❌✅
onTouch, onScroll, onSwipe, onControllerStatus❌✅✅❌

Web, 3.2.3+: ViroController reports scene-wide clicks, pinches, rotates, fuses and drags. The controller is the pointer, and the screen centre for fuse. A click that hits nothing reports position [], as Android does. onTouch, onScroll, onSwipe and onControllerStatus warn: those come from a hand controller, which the web does not have. Needs @reactvision/viro-web-renderer 1.3.0.

Example use:
<ViroController
    reticleVisibility={true}
    controllerVisibility={true}
    onClick={this._onClickListenerForAllEvents}
/>

Props

controllerVisibility

TypeDescription
booleanFlag for displaying the daydream controller. True by default. Note: this only applies to Daydream headsets.

onClick

See ViroNode onClick.

3.1.0+: a click on nothing (open passthrough, or a node with no click handler) reaches ViroController's onClick again, as before 3.0.0, with no node and the release's hit position, or no position on the background. No node's click handler receives it. On Meta Quest, the left menu button and the palm menu pinch arrive here as source 13, and no longer exit the scene.

onClickState

See ViroNode onClickState.

onControllerStatus

TypeDescription
(status) => voidCalled when the status of the controller has changed. This is only triggered for wireless controllers, else the return value would always be "Connected".

Unknown (1): The controller state is being initialized and is not yet known.

Connecting (2): The controller is currently scanning and attempting to connect to your device or phone.

Connected (3): The controller is connected to your device.

Disconnected (4): The controller has disconnected from your device.

Error (5): The controller has encountered an internal error and is currently unusable. This is usually triggered upon initialization.

onDrag

See ViroNode onDrag. (dragToPos, source) => void. Setting it enables drag events on the controller.

3.2.0+: delivered on iOS, Android and Quest, with the same payload as a node's onDrag. Android ignored it before 3.2.0.

onFuse

See ViroNode onFuse.

onHover

See ViroNode onHover.

onPinch

See ViroNode onPinch. (pinchState, scaleFactor, source) => void, with the scale relative to the start of the gesture. Setting it enables pinch events on the controller.

3.2.0+: delivered on iOS and Android touch screens, with the same payload as a node's onPinch. Before 3.2.0, iOS never enabled it and Android ignored it. A Quest controller does not pinch.

onRotate

See ViroNode onRotate. (rotateState, rotationFactor, source) => void, with the rotation in degrees since the start of the gesture. Setting it enables rotate events on the controller.

3.2.0+: delivered on iOS and Android touch screens, with the same payload as a node's onRotate. Before 3.2.0, iOS never enabled it and Android ignored it. A Quest controller does not rotate.

onScroll

See ViroNode onScroll.

onSwipe

See ViroNode onSwipe.

onTouch

See ViroNode onTouch.

reticleVisibility

TypeDescription
booleanFlag for displaying the reticle. True by default.

Methods

setNativeProps(nativeProps)

A wrapper function around the native component's setNativeProps which allow users to set values on the native component without changing state/setting props and re-rendering. Refer to the React Native documentation on Direct Manipulation for more information.

ParameterTypeDescription
nativePropsobjectan object where the keys are the properties to set and the values are the values to set
componentRef.setNativeProps({ position: [0, 0, -1] });

getControllerRayAsync(source) (3.1.0+)

Promise<{ origin: Viro3DPoint; forward: Viro3DPoint } | null>. Where the ray that carries source last pointed, in world space, or null when that source has no ray of its own, as with every iOS source. A click that hits nothing reports no position, so use this to find where it was aimed.

const ray = await this.controllerRef.getControllerRayAsync(source);
if (ray) {
  // ray.origin and ray.forward are in world space
}

getControllerForwardAsync()

An async function used to retrieve the forward vector of the current controller used to interact with the 3D scene.For example, grabbing the async could look like this:

this.controllerRef.getControllerForwardAsync().then((forward)=>{
// Do stuff with forward vector array
});