CLEAR

TouchGesturesModule


The TouchGesturesModule class enables touch gesture detection.

Example

const Reactive = require('Reactive');
const Scene = require('Scene');
const TouchGestures = require('TouchGestures');
const Materials = require('Materials');

const plButton1 = Scene.root.find('plButton1');
const plButton2 = Scene.root.find('plButton2');
const plButton3 = Scene.root.find('plButton3');
const matRed = Materials.get('matRed');

// Long press on the screen to show the first button
TouchGestures.onLongPress().subscribe(function () { plButton1.hidden = false; });

// Tap on the first button to make the second button appear
TouchGestures.onTap(plButton1).subscribe(function () { plButton2.hidden = false; });

// Pinch the screen to rescale the second button
TouchGestures.onPinch().subscribe(function (e) {
  const sx = plButton2.transform.scaleX.lastValue;
  plButton2.transform.scaleX = Reactive.mul(sx, e.scale);

  const sy = plButton2.transform.scaleY.lastValue;
  plButton2.transform.scaleY = Reactive.mul(sy, e.scale);
});

// Tap on the second button to have the third button appear
TouchGestures.onTap(plButton2).subscribe(function () { plButton3.hidden = false; });

// Rotate the third button around z axis, interacting with it directly
TouchGestures.onRotate(plButton3).subscribe(function (e) {
  plButton3.transform.rotationZ = Reactive.add(plButton3.transform.rotationZ.lastValue, Reactive.mul(-1, e.rotation));
});

// Pan on the screen
TouchGestures.onPan().subscribe(function (e) {
  if (!plButton3.hidden) {
    matRed.opacity = e.translation.y.div(200).add(matRed.opacity.lastValue);
  }
});

Properties

This class exposes no properties.

Methods

MethodDescription

onLongPress

onLongPress(): EventSource onLongPress(object: SceneObjectBase): EventSource onLongPress(options: {object?: SceneObjectBase, normalizeCoordinates?: boolean}): EventSource

Returns an EventSource, to which you may subscribe, that emits a LongPressGesture object for each long-press interaction.

When object is specified, only events for the specified object are emitted.

onPan

onPan(): EventSource onPan(object: SceneObjectBase): EventSource onPan(options: {object?: SceneObjectBase, normalizeCoordinates?: boolean}): EventSource

Returns an EventSource, to which you may subscribe, that emits a PanGesture object for each pan interaction.

When object is specified, only events for the specified object are emitted.

onPinch

onPinch(): EventSource onPinch(object: SceneObjectBase): EventSource onPinch(options: {object?: SceneObjectBase, normalizeCoordinates?: boolean}): EventSource

Returns an EventSource, to which you may subscribe, that emits a PinchGesture object for each pinch interaction.

When object is specified, only events for the specified object are emitted.

onRotate

onRotate(): EventSource onRotate(object: SceneObjectBase): EventSource onRotate(options: {object?: SceneObjectBase, normalizeCoordinates?: boolean}): EventSource

Returns an EventSource, to which you may subscribe, that emits a RotateGesture object for each rotate interaction.

When object is specified, only events for the specified object are emitted.

onTap

onTap(): EventSource onTap(object: SceneObjectBase): EventSource onTap(options: {object?: SceneObjectBase, normalizeCoordinates?: boolean}): EventSource

Returns an EventSource, to which you may subscribe, that emits a TapGesture object for each tap interaction.

When object is specified, only events for the specified object are emitted.

Classes

ClassDescription

Gesture

The Gesture class encapsulates details of a detected gesture.

LongPressGesture

The LongPressGesture class contains the details of a detected long-press gesture.

PanGesture

The PanGesture class contains the details of a detected pan gesture.

PinchGesture

The PinchGesture class contains the details of a detected pinch gesture.

RawTouchGesture

The RawTouchGesture class encapsulates raw touch data.

RotateGesture

The RotateGesture class contains the details of a detected rotate gesture.

TapGesture

The TapGesture class contains the details of a detected tap gesture.