UNPKG

4.67 kBTypeScriptView Raw
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 {Constructor} from '../../../types/private/Utilities';
12import {ColorValue} from '../../StyleSheet/StyleSheet';
13import {TouchableMixin} from './Touchable';
14
15import type {TVProps} from './TouchableOpacity';
16import {TouchableWithoutFeedbackProps} from './TouchableWithoutFeedback';
17
18interface BaseBackgroundPropType {
19 type: string;
20 rippleRadius?: number | null | undefined;
21}
22
23interface RippleBackgroundPropType extends BaseBackgroundPropType {
24 type: 'RippleAndroid';
25 borderless: boolean;
26 color?: number | null | undefined;
27}
28
29interface ThemeAttributeBackgroundPropType extends BaseBackgroundPropType {
30 type: 'ThemeAttrAndroid';
31 attribute: string;
32}
33
34type BackgroundPropType =
35 | RippleBackgroundPropType
36 | ThemeAttributeBackgroundPropType;
37
38/**
39 * @see https://reactnative.dev/docs/touchablenativefeedback#props
40 */
41export interface TouchableNativeFeedbackProps
42 extends TouchableWithoutFeedbackProps,
43 TVProps {
44 /**
45 * Determines the type of background drawable that's going to be used to display feedback.
46 * It takes an object with type property and extra data depending on the type.
47 * It's recommended to use one of the following static methods to generate that dictionary:
48 * 1) TouchableNativeFeedback.SelectableBackground() - will create object that represents android theme's
49 * default background for selectable elements (?android:attr/selectableItemBackground)
50 * 2) TouchableNativeFeedback.SelectableBackgroundBorderless() - will create object that represent android
51 * theme's default background for borderless selectable elements
52 * (?android:attr/selectableItemBackgroundBorderless). Available on android API level 21+
53 * 3) TouchableNativeFeedback.Ripple(color, borderless) - will create object that represents ripple drawable
54 * with specified color (as a string). If property borderless evaluates to true the ripple will render
55 * outside of the view bounds (see native actionbar buttons as an example of that behavior). This background
56 * type is available on Android API level 21+
57 */
58 background?: BackgroundPropType | undefined;
59 useForeground?: boolean | undefined;
60}
61
62/**
63 * A wrapper for making views respond properly to touches (Android only).
64 * On Android this component uses native state drawable to display touch feedback.
65 * At the moment it only supports having a single View instance as a child node,
66 * as it's implemented by replacing that View with another instance of RCTView node with some additional properties set.
67 *
68 * Background drawable of native feedback touchable can be customized with background property.
69 *
70 * @see https://reactnative.dev/docs/touchablenativefeedback#content
71 */
72declare class TouchableNativeFeedbackComponent extends React.Component<TouchableNativeFeedbackProps> {}
73declare const TouchableNativeFeedbackBase: Constructor<TouchableMixin> &
74 typeof TouchableNativeFeedbackComponent;
75export class TouchableNativeFeedback extends TouchableNativeFeedbackBase {
76 /**
77 * Creates an object that represents android theme's default background for
78 * selectable elements (?android:attr/selectableItemBackground).
79 *
80 * @param rippleRadius The radius of ripple effect
81 */
82 static SelectableBackground(
83 rippleRadius?: number | null,
84 ): ThemeAttributeBackgroundPropType;
85
86 /**
87 * Creates an object that represent android theme's default background for borderless
88 * selectable elements (?android:attr/selectableItemBackgroundBorderless).
89 * Available on android API level 21+.
90 *
91 * @param rippleRadius The radius of ripple effect
92 */
93 static SelectableBackgroundBorderless(
94 rippleRadius?: number | null,
95 ): ThemeAttributeBackgroundPropType;
96
97 /**
98 * Creates an object that represents ripple drawable with specified color (as a
99 * string). If property `borderless` evaluates to true the ripple will
100 * render outside of the view bounds (see native actionbar buttons as an
101 * example of that behavior). This background type is available on Android
102 * API level 21+.
103 *
104 * @param color The ripple color
105 * @param borderless If the ripple can render outside it's bounds
106 * @param rippleRadius The radius of ripple effect
107 */
108 static Ripple(
109 color: ColorValue,
110 borderless: boolean,
111 rippleRadius?: number | null,
112 ): RippleBackgroundPropType;
113 static canUseNativeForeground(): boolean;
114}