1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @format
8 */
9
10import type * as React from 'react';
11import {Insets} from '../../../types/public/Insets';
12import {GestureResponderEvent} from '../../Types/CoreEventTypes';
13
14/**
15 * //FIXME: need to find documentation on which component is a TTouchable and can implement that interface
16 * @see React.DOMAtributes
17 */
18export interface Touchable {
19  onTouchStart?: ((event: GestureResponderEvent) => void) | undefined;
20  onTouchMove?: ((event: GestureResponderEvent) => void) | undefined;
21  onTouchEnd?: ((event: GestureResponderEvent) => void) | undefined;
22  onTouchCancel?: ((event: GestureResponderEvent) => void) | undefined;
23  onTouchEndCapture?: ((event: GestureResponderEvent) => void) | undefined;
24}
25
26export const Touchable: {
27  TOUCH_TARGET_DEBUG: boolean;
28  renderDebugView: (config: {
29    color: string | number;
30    hitSlop?: Insets | undefined;
31  }) => React.ReactElement | null;
32};
33
34/**
35 * @see https://github.com/facebook/react-native/blob/0.34-stable\Libraries\Components\Touchable\Touchable.js
36 */
37interface TouchableMixin {
38  /**
39   * Invoked when the item should be highlighted. Mixers should implement this
40   * to visually distinguish the `VisualRect` so that the user knows that
41   * releasing a touch will result in a "selection" (analog to click).
42   */
43  touchableHandleActivePressIn(e: GestureResponderEvent): void;
44
45  /**
46   * Invoked when the item is "active" (in that it is still eligible to become
47   * a "select") but the touch has left the `PressRect`. Usually the mixer will
48   * want to unhighlight the `VisualRect`. If the user (while pressing) moves
49   * back into the `PressRect` `touchableHandleActivePressIn` will be invoked
50   * again and the mixer should probably highlight the `VisualRect` again. This
51   * event will not fire on an `touchEnd/mouseUp` event, only move events while
52   * the user is depressing the mouse/touch.
53   */
54  touchableHandleActivePressOut(e: GestureResponderEvent): void;
55
56  /**
57   * Invoked when the item is "selected" - meaning the interaction ended by
58   * letting up while the item was either in the state
59   * `RESPONDER_ACTIVE_PRESS_IN` or `RESPONDER_INACTIVE_PRESS_IN`.
60   */
61  touchableHandlePress(e: GestureResponderEvent): void;
62
63  /**
64   * Invoked when the item is long pressed - meaning the interaction ended by
65   * letting up while the item was in `RESPONDER_ACTIVE_LONG_PRESS_IN`. If
66   * `touchableHandleLongPress` is *not* provided, `touchableHandlePress` will
67   * be called as it normally is. If `touchableHandleLongPress` is provided, by
68   * default any `touchableHandlePress` callback will not be invoked. To
69   * override this default behavior, override `touchableLongPressCancelsPress`
70   * to return false. As a result, `touchableHandlePress` will be called when
71   * lifting up, even if `touchableHandleLongPress` has also been called.
72   */
73  touchableHandleLongPress(e: GestureResponderEvent): void;
74
75  /**
76   * Returns the amount to extend the `HitRect` into the `PressRect`. Positive
77   * numbers mean the size expands outwards.
78   */
79  touchableGetPressRectOffset(): Insets;
80
81  /**
82   * Returns the number of millis to wait before triggering a highlight.
83   */
84  touchableGetHighlightDelayMS(): number;
85
86  // These methods are undocumented but still being used by TouchableMixin internals
87  touchableGetLongPressDelayMS(): number;
88  touchableGetPressOutDelayMS(): number;
89  touchableGetHitSlop(): Insets;
90}
91