UNPKG

16.2 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 {Animated} from '../Animated/Animated';
11import {ImageResizeMode} from '../Image/ImageResizeMode';
12import {ColorValue} from './StyleSheet';
13
14type FlexAlignType =
15 | 'flex-start'
16 | 'flex-end'
17 | 'center'
18 | 'stretch'
19 | 'baseline';
20
21export type DimensionValue =
22 | number
23 | 'auto'
24 | `${number}%`
25 | Animated.AnimatedNode
26 | null;
27type AnimatableNumericValue = number | Animated.AnimatedNode;
28type AnimatableStringValue = string | Animated.AnimatedNode;
29
30export type CursorValue = 'auto' | 'pointer';
31
32/**
33 * Flex Prop Types
34 * @see https://reactnative.dev/docs/flexbox
35 * @see https://reactnative.dev/docs/layout-props
36 */
37export interface FlexStyle {
38 alignContent?:
39 | 'flex-start'
40 | 'flex-end'
41 | 'center'
42 | 'stretch'
43 | 'space-between'
44 | 'space-around'
45 | 'space-evenly'
46 | undefined;
47 alignItems?: FlexAlignType | undefined;
48 alignSelf?: 'auto' | FlexAlignType | undefined;
49 aspectRatio?: number | string | undefined;
50 borderBottomWidth?: number | undefined;
51 borderEndWidth?: number | undefined;
52 borderLeftWidth?: number | undefined;
53 borderRightWidth?: number | undefined;
54 borderStartWidth?: number | undefined;
55 borderTopWidth?: number | undefined;
56 borderWidth?: number | undefined;
57 bottom?: DimensionValue | undefined;
58 boxSizing?: 'border-box' | 'content-box' | undefined;
59 display?: 'none' | 'flex' | 'contents' | undefined;
60 end?: DimensionValue | undefined;
61 flex?: number | undefined;
62 flexBasis?: DimensionValue | undefined;
63 flexDirection?:
64 | 'row'
65 | 'column'
66 | 'row-reverse'
67 | 'column-reverse'
68 | undefined;
69 rowGap?: number | string | undefined;
70 gap?: number | string | undefined;
71 columnGap?: number | string | undefined;
72 flexGrow?: number | undefined;
73 flexShrink?: number | undefined;
74 flexWrap?: 'wrap' | 'nowrap' | 'wrap-reverse' | undefined;
75 height?: DimensionValue | undefined;
76 justifyContent?:
77 | 'flex-start'
78 | 'flex-end'
79 | 'center'
80 | 'space-between'
81 | 'space-around'
82 | 'space-evenly'
83 | undefined;
84 left?: DimensionValue | undefined;
85 margin?: DimensionValue | undefined;
86 marginBottom?: DimensionValue | undefined;
87 marginEnd?: DimensionValue | undefined;
88 marginHorizontal?: DimensionValue | undefined;
89 marginLeft?: DimensionValue | undefined;
90 marginRight?: DimensionValue | undefined;
91 marginStart?: DimensionValue | undefined;
92 marginTop?: DimensionValue | undefined;
93 marginVertical?: DimensionValue | undefined;
94 maxHeight?: DimensionValue | undefined;
95 maxWidth?: DimensionValue | undefined;
96 minHeight?: DimensionValue | undefined;
97 minWidth?: DimensionValue | undefined;
98 overflow?: 'visible' | 'hidden' | 'scroll' | undefined;
99 padding?: DimensionValue | undefined;
100 paddingBottom?: DimensionValue | undefined;
101 paddingEnd?: DimensionValue | undefined;
102 paddingHorizontal?: DimensionValue | undefined;
103 paddingLeft?: DimensionValue | undefined;
104 paddingRight?: DimensionValue | undefined;
105 paddingStart?: DimensionValue | undefined;
106 paddingTop?: DimensionValue | undefined;
107 paddingVertical?: DimensionValue | undefined;
108 position?: 'absolute' | 'relative' | 'static' | undefined;
109 right?: DimensionValue | undefined;
110 start?: DimensionValue | undefined;
111 top?: DimensionValue | undefined;
112 width?: DimensionValue | undefined;
113 zIndex?: number | undefined;
114 direction?: 'inherit' | 'ltr' | 'rtl' | undefined;
115
116 /**
117 * Equivalent to `top`, `bottom`, `right` and `left`
118 */
119 inset?: DimensionValue | undefined;
120
121 /**
122 * Equivalent to `top`, `bottom`
123 */
124 insetBlock?: DimensionValue | undefined;
125
126 /**
127 * Equivalent to `bottom`
128 */
129 insetBlockEnd?: DimensionValue | undefined;
130
131 /**
132 * Equivalent to `top`
133 */
134 insetBlockStart?: DimensionValue | undefined;
135
136 /**
137 * Equivalent to `right` and `left`
138 */
139 insetInline?: DimensionValue | undefined;
140
141 /**
142 * Equivalent to `right` or `left`
143 */
144 insetInlineEnd?: DimensionValue | undefined;
145
146 /**
147 * Equivalent to `right` or `left`
148 */
149 insetInlineStart?: DimensionValue | undefined;
150
151 /**
152 * Equivalent to `marginVertical`
153 */
154 marginBlock?: DimensionValue | undefined;
155
156 /**
157 * Equivalent to `marginBottom`
158 */
159 marginBlockEnd?: DimensionValue | undefined;
160
161 /**
162 * Equivalent to `marginTop`
163 */
164 marginBlockStart?: DimensionValue | undefined;
165
166 /**
167 * Equivalent to `marginHorizontal`
168 */
169 marginInline?: DimensionValue | undefined;
170
171 /**
172 * Equivalent to `marginEnd`
173 */
174 marginInlineEnd?: DimensionValue | undefined;
175
176 /**
177 * Equivalent to `marginStart`
178 */
179 marginInlineStart?: DimensionValue | undefined;
180
181 /**
182 * Equivalent to `paddingVertical`
183 */
184 paddingBlock?: DimensionValue | undefined;
185
186 /**
187 * Equivalent to `paddingBottom`
188 */
189 paddingBlockEnd?: DimensionValue | undefined;
190
191 /**
192 * Equivalent to `paddingTop`
193 */
194 paddingBlockStart?: DimensionValue | undefined;
195
196 /**
197 * Equivalent to `paddingHorizontal`
198 */
199 paddingInline?: DimensionValue | undefined;
200
201 /**
202 * Equivalent to `paddingEnd`
203 */
204 paddingInlineEnd?: DimensionValue | undefined;
205
206 /**
207 * Equivalent to `paddingStart`
208 */
209 paddingInlineStart?: DimensionValue | undefined;
210}
211
212export interface ShadowStyleIOS {
213 shadowColor?: ColorValue | undefined;
214 shadowOffset?: Readonly<{width: number; height: number}> | undefined;
215 shadowOpacity?: AnimatableNumericValue | undefined;
216 shadowRadius?: number | undefined;
217}
218
219interface PerspectiveTransform {
220 perspective: AnimatableNumericValue;
221}
222
223interface RotateTransform {
224 rotate: AnimatableStringValue;
225}
226
227interface RotateXTransform {
228 rotateX: AnimatableStringValue;
229}
230
231interface RotateYTransform {
232 rotateY: AnimatableStringValue;
233}
234
235interface RotateZTransform {
236 rotateZ: AnimatableStringValue;
237}
238
239interface ScaleTransform {
240 scale: AnimatableNumericValue;
241}
242
243interface ScaleXTransform {
244 scaleX: AnimatableNumericValue;
245}
246
247interface ScaleYTransform {
248 scaleY: AnimatableNumericValue;
249}
250
251interface TranslateXTransform {
252 translateX: AnimatableNumericValue | `${number}%`;
253}
254
255interface TranslateYTransform {
256 translateY: AnimatableNumericValue | `${number}%`;
257}
258
259interface SkewXTransform {
260 skewX: AnimatableStringValue;
261}
262
263interface SkewYTransform {
264 skewY: AnimatableStringValue;
265}
266
267interface MatrixTransform {
268 matrix: AnimatableNumericValue[];
269}
270
271type MaximumOneOf<T, K extends keyof T = keyof T> = K extends keyof T
272 ? {[P in K]: T[K]} & {[P in Exclude<keyof T, K>]?: never}
273 : never;
274
275export interface TransformsStyle {
276 transform?:
277 | Readonly<
278 MaximumOneOf<
279 PerspectiveTransform &
280 RotateTransform &
281 RotateXTransform &
282 RotateYTransform &
283 RotateZTransform &
284 ScaleTransform &
285 ScaleXTransform &
286 ScaleYTransform &
287 TranslateXTransform &
288 TranslateYTransform &
289 SkewXTransform &
290 SkewYTransform &
291 MatrixTransform
292 >[]
293 >
294 | string
295 | undefined;
296 transformOrigin?: Array<string | number> | string | undefined;
297
298 /**
299 * @deprecated Use matrix in transform prop instead.
300 */
301 transformMatrix?: Array<number> | undefined;
302 /**
303 * @deprecated Use rotate in transform prop instead.
304 */
305 rotation?: AnimatableNumericValue | undefined;
306 /**
307 * @deprecated Use scaleX in transform prop instead.
308 */
309 scaleX?: AnimatableNumericValue | undefined;
310 /**
311 * @deprecated Use scaleY in transform prop instead.
312 */
313 scaleY?: AnimatableNumericValue | undefined;
314 /**
315 * @deprecated Use translateX in transform prop instead.
316 */
317 translateX?: AnimatableNumericValue | undefined;
318 /**
319 * @deprecated Use translateY in transform prop instead.
320 */
321 translateY?: AnimatableNumericValue | undefined;
322}
323
324export type FilterFunction =
325 | {brightness: number | string}
326 | {blur: number | string}
327 | {contrast: number | string}
328 | {grayscale: number | string}
329 | {hueRotate: number | string}
330 | {invert: number | string}
331 | {opacity: number | string}
332 | {saturate: number | string}
333 | {sepia: number | string}
334 | {dropShadow: DropShadowValue | string};
335
336export type DropShadowValue = {
337 offsetX: number | string;
338 offsetY: number | string;
339 standardDeviation?: number | string | undefined;
340 color?: ColorValue | number | undefined;
341};
342
343export type BoxShadowValue = {
344 offsetX: number | string;
345 offsetY: number | string;
346 color?: string | undefined;
347 blurRadius?: ColorValue | number | undefined;
348 spreadDistance?: number | string | undefined;
349 inset?: boolean | undefined;
350};
351
352export type BlendMode =
353 | 'normal'
354 | 'multiply'
355 | 'screen'
356 | 'overlay'
357 | 'darken'
358 | 'lighten'
359 | 'color-dodge'
360 | 'color-burn'
361 | 'hard-light'
362 | 'soft-light'
363 | 'difference'
364 | 'exclusion'
365 | 'hue'
366 | 'saturation'
367 | 'color'
368 | 'luminosity';
369
370export type GradientValue = {
371 type: 'linearGradient';
372 // Angle or direction enums
373 direction?: string | undefined;
374 colorStops: ReadonlyArray<{
375 color: ColorValue;
376 positions?: ReadonlyArray<string[]> | undefined;
377 }>;
378};
379
380/**
381 * @see https://reactnative.dev/docs/view#style
382 */
383export interface ViewStyle extends FlexStyle, ShadowStyleIOS, TransformsStyle {
384 backfaceVisibility?: 'visible' | 'hidden' | undefined;
385 backgroundColor?: ColorValue | undefined;
386 borderBlockColor?: ColorValue | undefined;
387 borderBlockEndColor?: ColorValue | undefined;
388 borderBlockStartColor?: ColorValue | undefined;
389 borderBottomColor?: ColorValue | undefined;
390 borderBottomEndRadius?: AnimatableNumericValue | string | undefined;
391 borderBottomLeftRadius?: AnimatableNumericValue | string | undefined;
392 borderBottomRightRadius?: AnimatableNumericValue | string | undefined;
393 borderBottomStartRadius?: AnimatableNumericValue | string | undefined;
394 borderColor?: ColorValue | undefined;
395 /**
396 * On iOS 13+, it is possible to change the corner curve of borders.
397 * @platform ios
398 */
399 borderCurve?: 'circular' | 'continuous' | undefined;
400 borderEndColor?: ColorValue | undefined;
401 borderEndEndRadius?: AnimatableNumericValue | string | undefined;
402 borderEndStartRadius?: AnimatableNumericValue | string | undefined;
403 borderLeftColor?: ColorValue | undefined;
404 borderRadius?: AnimatableNumericValue | string | undefined;
405 borderRightColor?: ColorValue | undefined;
406 borderStartColor?: ColorValue | undefined;
407 borderStartEndRadius?: AnimatableNumericValue | string | undefined;
408 borderStartStartRadius?: AnimatableNumericValue | string | undefined;
409 borderStyle?: 'solid' | 'dotted' | 'dashed' | undefined;
410 borderTopColor?: ColorValue | undefined;
411 borderTopEndRadius?: AnimatableNumericValue | string | undefined;
412 borderTopLeftRadius?: AnimatableNumericValue | string | undefined;
413 borderTopRightRadius?: AnimatableNumericValue | string | undefined;
414 borderTopStartRadius?: AnimatableNumericValue | string | undefined;
415 outlineColor?: ColorValue | undefined;
416 outlineOffset?: AnimatableNumericValue | undefined;
417 outlineStyle?: 'solid' | 'dotted' | 'dashed' | undefined;
418 outlineWidth?: AnimatableNumericValue | undefined;
419 opacity?: AnimatableNumericValue | undefined;
420 /**
421 * Sets the elevation of a view, using Android's underlying
422 * [elevation API](https://developer.android.com/training/material/shadows-clipping.html#Elevation).
423 * This adds a drop shadow to the item and affects z-order for overlapping views.
424 * Only supported on Android 5.0+, has no effect on earlier versions.
425 *
426 * @platform android
427 */
428 elevation?: number | undefined;
429 /**
430 * Controls whether the View can be the target of touch events.
431 */
432 pointerEvents?: 'box-none' | 'none' | 'box-only' | 'auto' | undefined;
433 isolation?: 'auto' | 'isolate' | undefined;
434 cursor?: CursorValue | undefined;
435 boxShadow?: ReadonlyArray<BoxShadowValue> | string | undefined;
436 filter?: ReadonlyArray<FilterFunction> | string | undefined;
437
438 mixBlendMode?: BlendMode | undefined;
439 experimental_backgroundImage?:
440 | ReadonlyArray<GradientValue>
441 | string
442 | undefined;
443}
444
445export type FontVariant =
446 | 'small-caps'
447 | 'oldstyle-nums'
448 | 'lining-nums'
449 | 'tabular-nums'
450 | 'common-ligatures'
451 | 'no-common-ligatures'
452 | 'discretionary-ligatures'
453 | 'no-discretionary-ligatures'
454 | 'historical-ligatures'
455 | 'no-historical-ligatures'
456 | 'contextual'
457 | 'no-contextual'
458 | 'proportional-nums'
459 | 'stylistic-one'
460 | 'stylistic-two'
461 | 'stylistic-three'
462 | 'stylistic-four'
463 | 'stylistic-five'
464 | 'stylistic-six'
465 | 'stylistic-seven'
466 | 'stylistic-eight'
467 | 'stylistic-nine'
468 | 'stylistic-ten'
469 | 'stylistic-eleven'
470 | 'stylistic-twelve'
471 | 'stylistic-thirteen'
472 | 'stylistic-fourteen'
473 | 'stylistic-fifteen'
474 | 'stylistic-sixteen'
475 | 'stylistic-seventeen'
476 | 'stylistic-eighteen'
477 | 'stylistic-nineteen'
478 | 'stylistic-twenty';
479export interface TextStyleIOS extends ViewStyle {
480 fontVariant?: FontVariant[] | undefined;
481 textDecorationColor?: ColorValue | undefined;
482 textDecorationStyle?: 'solid' | 'double' | 'dotted' | 'dashed' | undefined;
483 writingDirection?: 'auto' | 'ltr' | 'rtl' | undefined;
484}
485
486export interface TextStyleAndroid extends ViewStyle {
487 textAlignVertical?: 'auto' | 'top' | 'bottom' | 'center' | undefined;
488 verticalAlign?: 'auto' | 'top' | 'bottom' | 'middle' | undefined;
489 includeFontPadding?: boolean | undefined;
490}
491
492// @see https://reactnative.dev/docs/text#style
493export interface TextStyle extends TextStyleIOS, TextStyleAndroid, ViewStyle {
494 color?: ColorValue | undefined;
495 fontFamily?: string | undefined;
496 fontSize?: number | undefined;
497 fontStyle?: 'normal' | 'italic' | undefined;
498 /**
499 * Specifies font weight. The values 'normal' and 'bold' are supported
500 * for most fonts. Not all fonts have a variant for each of the numeric
501 * values, in that case the closest one is chosen.
502 */
503 fontWeight?:
504 | 'normal'
505 | 'bold'
506 | '100'
507 | '200'
508 | '300'
509 | '400'
510 | '500'
511 | '600'
512 | '700'
513 | '800'
514 | '900'
515 | 100
516 | 200
517 | 300
518 | 400
519 | 500
520 | 600
521 | 700
522 | 800
523 | 900
524 | 'ultralight'
525 | 'thin'
526 | 'light'
527 | 'medium'
528 | 'regular'
529 | 'semibold'
530 | 'condensedBold'
531 | 'condensed'
532 | 'heavy'
533 | 'black'
534 | undefined;
535 letterSpacing?: number | undefined;
536 lineHeight?: number | undefined;
537 textAlign?: 'auto' | 'left' | 'right' | 'center' | 'justify' | undefined;
538 textDecorationLine?:
539 | 'none'
540 | 'underline'
541 | 'line-through'
542 | 'underline line-through'
543 | undefined;
544 textDecorationStyle?: 'solid' | 'double' | 'dotted' | 'dashed' | undefined;
545 textDecorationColor?: ColorValue | undefined;
546 textShadowColor?: ColorValue | undefined;
547 textShadowOffset?: {width: number; height: number} | undefined;
548 textShadowRadius?: number | undefined;
549 textTransform?: 'none' | 'capitalize' | 'uppercase' | 'lowercase' | undefined;
550 userSelect?: 'auto' | 'none' | 'text' | 'contain' | 'all' | undefined;
551}
552
553/**
554 * Image style
555 * @see https://reactnative.dev/docs/image#style
556 */
557export interface ImageStyle extends FlexStyle, ShadowStyleIOS, TransformsStyle {
558 resizeMode?: ImageResizeMode | undefined;
559 backfaceVisibility?: 'visible' | 'hidden' | undefined;
560 borderBottomLeftRadius?: AnimatableNumericValue | string | undefined;
561 borderBottomRightRadius?: AnimatableNumericValue | string | undefined;
562 backgroundColor?: ColorValue | undefined;
563 borderColor?: ColorValue | undefined;
564 borderRadius?: AnimatableNumericValue | string | undefined;
565 borderTopLeftRadius?: AnimatableNumericValue | string | undefined;
566 borderTopRightRadius?: AnimatableNumericValue | string | undefined;
567 overflow?: 'visible' | 'hidden' | undefined;
568 overlayColor?: ColorValue | undefined;
569 tintColor?: ColorValue | undefined;
570 opacity?: AnimatableNumericValue | undefined;
571 objectFit?: 'cover' | 'contain' | 'fill' | 'scale-down' | 'none' | undefined;
572 cursor?: CursorValue | undefined;
573}