The Viro Developer Hub

Welcome to the Viro developer hub. You'll find comprehensive guides and sample code to help you start working with Viro as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started

Input Events

Input events are triggered through controllers like the Daydream Controller or Oculus Gear Touchpad, or through touch input on AR devices. Viro UI controls respond to input events via event handlers in a bubbled up fashion: events are passed up the Node hierarchy until they encounter a Node that can handle and potentially swallow the event.

There are many kinds of events: click, drag, fuse, pinch, rotate, and more. However, not all platforms support all events; it is largely dependent on the controller type. All events originate from a given source. The source identifies which input button is being pressed, and from which controller (for platforms that feature multiple hand-held controllers, for example).

Each Viro event handler callback provides a unique numeric source identifier that corresponds to an input source on the physical controller. You can view a mapping of input source IDs to Gear, Cardboard, and Daydream below.

Event Handlers

These methods are used to register listeners to respond to controller-driven events. Events start at the "hovered" (or focused) Node. If that Node cannot respond to the event (e.g. if it does not have the appropriate listener installed), the event will bubble up the scene graph to that Node's parent, and so on, until a Node that can handle the event is found.

All events are also received by the Controller, which provides a centralized place to respond to all events regardless of what Nodes they targeted.

Node.setClickListener(ClickListener)
Click events are fired when the user taps while focused on a Node.

Node.setDragListener(DragListener)
Drag events are fired when a Node is being dragged by the user; that is, when the user performs a click down on a Node, holds that click, and then physically moves the controller (or tilts the headset). The view will automatically drag in VR, and as it does so, the DragListener event callback is continually triggered with the latest 3D location of the object. It is also important to note that the DragListener must be assigned to a Node to make that Node draggable.

Node.setHoverListener(HoverListener)
Hover events are fired when the user moves his or her reticle over a Node, or stops hovering over a Node.

Node.setFuseListener(FuseListener)
Fuse events are fired when the user hovers his or her reticle over the Node and remain hovered for timeToFuse milliseconds. The timeToFuse parameter is optional and is defaulted to 2000ms. This parameter is set via Node.setTimeToFuse(float)).

Node.setTouchpadTouchListener(TouchpadTouchListener)
Node.setTouchpadSwipeListener(TouchpadSwipeListener)
Node.setTouchpadScrollListener(TouchpadScrollListener)
Touch, swipe, and scroll events are fired a Node is touched, swiped, or scrolled using a touchpad by the user; that is, when the user performs an action on a touchpad while hovering on top of the targeted Node. For the scroll listener, the distance the user has scrolled by is given as a unit ratio of the touch pad from 0.0 to 1.0 for both X and Y coordinates. These events are mainly used by the Gear VR platform, which features a touchpad on the headset.

Node.setGesturePinchListener(GesturePinchListener)
Node.setGestureRotateListener(GestureRotateListener)
Gesture pinch and rotate events are fired when the user uses multitouch to 'pinch' over a Node or 'swivel' over the Node to create a rotation. These events are used by AR platforms, where the controller is the screen.

Supported Controllers

At the very least,Click is guaranteed to be supported across all platforms. However, due to the physical limitations of controllers on each platform, certain events as shown below may not be supported.

Events Daydream GearVR Android Cardboard IOS Cardboard iOS AR Android AR
Click Supported Supported Supported Supported Supported Supported
Hover Supported Supported Supported Supported Supported Supported
Drag Supported Supported Supported Not Supported Supported Supported
Fuse Supported Supported Supported Not Supported Not Supported Not Supported
Scroll Supported Not Supported Not Supported Not Supported Not Supported Not Supported
Swipe Supported Supported Not Supported Not Supported Not Supported Not Supported
Touch Supported Supported Not Supported Not Supported Not Supported Not Supported
Pinch Not Supported Not Supported Not Supported Not Supported Supported Supported
Rotate Not Supported Not Supported Not Supported Not Supported Supported Supported

Different types of controllers may result in different forms of interactivity or UI. For example, users can easily scroll through galleries with Daydream's touch pad, but additional UI buttons may be needed for Cardboard.

Platform Specific Input Source Identifiers

As mentioned above, a unique numeric source identifier that corresponds to an input source on the physical controller. This section will go through the mappings of sources for Cardboard, GearVR and Daydream.

Cardboard (Android & iOS)

Cardboard (Android & iOS)

Input Source Value
Description

1

Main Controller

2

Primary Cardboard Trigger

GearVR

GearVR

Input Source Value
Description

1

Main Controller

2

Gear Touch Pad

3

Gear Back Button

Daydream

Daydream

Input Source Value
Description

1

Main Controller

2

Daydream TouchPad

3

Daydream App Button

4

Daydream Home Button

5

Volume Up Button

6

Volume Down Button

Input Events


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.