Input Events

TODO:

  • Broken developer.viromedia.com links
  • Is the Events table still accurate?

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.

EventsDaydreamGearVRAndroid CardboardIOS CardboardiOS ARAndroid AR
Click
Hover
Drag
Fuse
Scroll
Swipe
Touch
Pinch
Rotate

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.

800

Cardboard (Android & iOS)

Input Source ValueDescription
1Main Controller
2Primary Cardboard Trigger
800

GearVR

Input Source ValueDescription
1Main Controller
2Gear Touch Pad
3Gear Back Button
800

Daydream

Input Source ValueDescription
1Main Controller
2Daydream TouchPad
3Daydream App Button
4Daydream Home Button
5Volume Up Button
6Volume Down Button