UNPKG

6.29 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 {AccessibilityProps} from '../Components/View/ViewAccessibility';
13import {NativeMethods} from '../../types/public/ReactNativeTypes';
14import {ColorValue, StyleProp} from '../StyleSheet/StyleSheet';
15import {TextStyle} from '../StyleSheet/StyleSheetTypes';
16import {
17 GestureResponderEvent,
18 LayoutChangeEvent,
19 NativeSyntheticEvent,
20 TextLayoutEventData,
21} from '../Types/CoreEventTypes';
22
23export interface TextPropsIOS {
24 /**
25 * Specifies whether font should be scaled down automatically to fit given style constraints.
26 */
27 adjustsFontSizeToFit?: boolean | undefined;
28
29 /**
30 * The Dynamic Type scale ramp to apply to this element on iOS.
31 */
32 dynamicTypeRamp?:
33 | 'caption2'
34 | 'caption1'
35 | 'footnote'
36 | 'subheadline'
37 | 'callout'
38 | 'body'
39 | 'headline'
40 | 'title3'
41 | 'title2'
42 | 'title1'
43 | 'largeTitle'
44 | undefined;
45
46 /**
47 * When `true`, no visual change is made when text is pressed down. By
48 * default, a gray oval highlights the text on press down.
49 */
50 suppressHighlighting?: boolean | undefined;
51
52 /**
53 * Set line break strategy on iOS.
54 */
55 lineBreakStrategyIOS?:
56 | 'none'
57 | 'standard'
58 | 'hangul-word'
59 | 'push-out'
60 | undefined;
61}
62
63export interface TextPropsAndroid {
64 /**
65 * Specifies the disabled state of the text view for testing purposes.
66 */
67 disabled?: boolean | undefined;
68
69 /**
70 * Lets the user select text, to use the native copy and paste functionality.
71 */
72 selectable?: boolean | undefined;
73
74 /**
75 * The highlight color of the text.
76 */
77 selectionColor?: ColorValue | undefined;
78
79 /**
80 * Set text break strategy on Android API Level 23+
81 * default is `highQuality`.
82 */
83 textBreakStrategy?: 'simple' | 'highQuality' | 'balanced' | undefined;
84
85 /**
86 * Determines the types of data converted to clickable URLs in the text element.
87 * By default no data types are detected.
88 */
89 dataDetectorType?:
90 | null
91 | 'phoneNumber'
92 | 'link'
93 | 'email'
94 | 'none'
95 | 'all'
96 | undefined;
97
98 /**
99 * Hyphenation strategy
100 */
101 android_hyphenationFrequency?: 'normal' | 'none' | 'full' | undefined;
102}
103
104// https://reactnative.dev/docs/text#props
105export interface TextProps
106 extends TextPropsIOS,
107 TextPropsAndroid,
108 AccessibilityProps {
109 /**
110 * Specifies whether fonts should scale to respect Text Size accessibility settings.
111 * The default is `true`.
112 */
113 allowFontScaling?: boolean | undefined;
114
115 children?: React.ReactNode | undefined;
116
117 /**
118 * This can be one of the following values:
119 *
120 * - `head` - The line is displayed so that the end fits in the container and the missing text
121 * at the beginning of the line is indicated by an ellipsis glyph. e.g., "...wxyz"
122 * - `middle` - The line is displayed so that the beginning and end fit in the container and the
123 * missing text in the middle is indicated by an ellipsis glyph. "ab...yz"
124 * - `tail` - The line is displayed so that the beginning fits in the container and the
125 * missing text at the end of the line is indicated by an ellipsis glyph. e.g., "abcd..."
126 * - `clip` - Lines are not drawn past the edge of the text container.
127 *
128 * The default is `tail`.
129 *
130 * `numberOfLines` must be set in conjunction with this prop.
131 *
132 * > `clip` is working only for iOS
133 */
134 ellipsizeMode?: 'head' | 'middle' | 'tail' | 'clip' | undefined;
135
136 /**
137 * Used to reference react managed views from native code.
138 */
139 id?: string | undefined;
140
141 /**
142 * Line Break mode. Works only with numberOfLines.
143 * clip is working only for iOS
144 */
145 lineBreakMode?: 'head' | 'middle' | 'tail' | 'clip' | undefined;
146
147 /**
148 * Used to truncate the text with an ellipsis after computing the text
149 * layout, including line wrapping, such that the total number of lines
150 * does not exceed this number.
151 *
152 * This prop is commonly used with `ellipsizeMode`.
153 */
154 numberOfLines?: number | undefined;
155
156 /**
157 * Invoked on mount and layout changes with
158 *
159 * {nativeEvent: { layout: {x, y, width, height}}}.
160 */
161 onLayout?: ((event: LayoutChangeEvent) => void) | undefined;
162
163 /**
164 * Invoked on Text layout
165 */
166 onTextLayout?:
167 | ((event: NativeSyntheticEvent<TextLayoutEventData>) => void)
168 | undefined;
169
170 /**
171 * This function is called on press.
172 * Text intrinsically supports press handling with a default highlight state (which can be disabled with suppressHighlighting).
173 */
174 onPress?: ((event: GestureResponderEvent) => void) | undefined;
175
176 onPressIn?: ((event: GestureResponderEvent) => void) | undefined;
177 onPressOut?: ((event: GestureResponderEvent) => void) | undefined;
178
179 /**
180 * This function is called on long press.
181 * e.g., `onLongPress={this.increaseSize}>``
182 */
183 onLongPress?: ((event: GestureResponderEvent) => void) | undefined;
184
185 /**
186 * @see https://reactnative.dev/docs/text#style
187 */
188 style?: StyleProp<TextStyle> | undefined;
189
190 /**
191 * Used to locate this view in end-to-end tests.
192 */
193 testID?: string | undefined;
194
195 /**
196 * Used to reference react managed views from native code.
197 */
198 nativeID?: string | undefined;
199
200 /**
201 * Specifies largest possible scale a font can reach when allowFontScaling is enabled. Possible values:
202 * - null/undefined (default): inherit from the parent node or the global default (0)
203 * - 0: no max, ignore parent/global default
204 * - >= 1: sets the maxFontSizeMultiplier of this node to this value
205 */
206 maxFontSizeMultiplier?: number | null | undefined;
207
208 /**
209 * Specifies smallest possible scale a font can reach when adjustsFontSizeToFit is enabled. (values 0.01-1.0).
210 */
211 minimumFontScale?: number | undefined;
212}
213
214/**
215 * A React component for displaying text which supports nesting, styling, and touch handling.
216 */
217declare class TextComponent extends React.Component<TextProps> {}
218declare const TextBase: Constructor<NativeMethods> & typeof TextComponent;
219export class Text extends TextBase {}
220
\No newline at end of file