UNPKG

3.88 kBTypeScriptView Raw
1/// <reference types="react" />
2import { ColorValue, AccessibilityProps, ViewProps, Insets, StyleProp, ViewStyle } from 'react-native';
3export interface PressableStateCallbackType {
4 readonly pressed: boolean;
5}
6export interface PressableAndroidRippleConfig {
7 color?: null | ColorValue | undefined;
8 borderless?: null | boolean | undefined;
9 radius?: null | number | undefined;
10 foreground?: null | boolean | undefined;
11}
12export type InnerPressableEvent = {
13 changedTouches: InnerPressableEvent[];
14 identifier: number;
15 locationX: number;
16 locationY: number;
17 pageX: number;
18 pageY: number;
19 target: number;
20 timestamp: number;
21 touches: InnerPressableEvent[];
22 force?: number;
23};
24export type PressableEvent = {
25 nativeEvent: InnerPressableEvent;
26};
27export interface PressableProps extends AccessibilityProps, Omit<ViewProps, 'children' | 'style' | 'hitSlop'> {
28 /**
29 * Called when the hover is activated to provide visual feedback.
30 */
31 onHoverIn?: null | ((event: PressableEvent) => void);
32 /**
33 * Called when the hover is deactivated to undo visual feedback.
34 */
35 onHoverOut?: null | ((event: PressableEvent) => void);
36 /**
37 * Called when a single tap gesture is detected.
38 */
39 onPress?: null | ((event: PressableEvent) => void);
40 /**
41 * Called when a touch is engaged before `onPress`.
42 */
43 onPressIn?: null | ((event: PressableEvent) => void);
44 /**
45 * Called when a touch is released before `onPress`.
46 */
47 onPressOut?: null | ((event: PressableEvent) => void);
48 /**
49 * Called when a long-tap gesture is detected.
50 */
51 onLongPress?: null | ((event: PressableEvent) => void);
52 /**
53 * Either children or a render prop that receives a boolean reflecting whether
54 * the component is currently pressed.
55 */
56 children?: React.ReactNode | ((state: PressableStateCallbackType) => React.ReactNode);
57 /**
58 * Whether a press gesture can be interrupted by a parent gesture such as a
59 * scroll event. Defaults to true.
60 */
61 cancelable?: null | boolean;
62 /**
63 * Duration to wait after hover in before calling `onHoverIn`.
64 * @platform web macos
65 *
66 * NOTE: not present in RN docs
67 */
68 delayHoverIn?: number | null;
69 /**
70 * Duration to wait after hover out before calling `onHoverOut`.
71 * @platform web macos
72 *
73 * NOTE: not present in RN docs
74 */
75 delayHoverOut?: number | null;
76 /**
77 * Duration (in milliseconds) from `onPressIn` before `onLongPress` is called.
78 */
79 delayLongPress?: null | number;
80 /**
81 * Whether the press behavior is disabled.
82 */
83 disabled?: null | boolean;
84 /**
85 * Additional distance outside of this view in which a press is detected.
86 */
87 hitSlop?: null | Insets | number;
88 /**
89 * Additional distance outside of this view in which a touch is considered a
90 * press before `onPressOut` is triggered.
91 */
92 pressRetentionOffset?: null | Insets | number;
93 /**
94 * If true, doesn't play system sound on touch.
95 * @platform android
96 */
97 android_disableSound?: null | boolean;
98 /**
99 * Enables the Android ripple effect and configures its color.
100 * @platform android
101 */
102 android_ripple?: null | PressableAndroidRippleConfig;
103 /**
104 * Used only for documentation or testing (e.g. snapshot testing).
105 */
106 testOnly_pressed?: null | boolean;
107 /**
108 * Either view styles or a function that receives a boolean reflecting whether
109 * the component is currently pressed and returns view styles.
110 */
111 style?: StyleProp<ViewStyle> | ((state: PressableStateCallbackType) => StyleProp<ViewStyle>);
112 /**
113 * Duration (in milliseconds) to wait after press down before calling onPressIn.
114 */
115 unstable_pressDelay?: number;
116}
117
\No newline at end of file