@tamagui/core 1.0.0-alpha.21 → 1.0.0-alpha.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/cjs/helpers/getStylesAtomic.js.map +2 -2
  2. package/dist/esm/helpers/getStylesAtomic.js.map +2 -2
  3. package/package.json +8 -9
  4. package/types/helpers/createMediaStyle.d.ts +1 -0
  5. package/types/helpers/createMediaStyle.d.ts.map +1 -1
  6. package/types/helpers/getStylesAtomic.d.ts +1 -0
  7. package/types/helpers/getStylesAtomic.d.ts.map +1 -1
  8. package/src/constants/constants.ts +0 -12
  9. package/src/constants/platform.ts +0 -15
  10. package/src/constants/pseudos.ts +0 -14
  11. package/src/constants/rnw.tsx +0 -20
  12. package/src/createComponent.tsx +0 -614
  13. package/src/createFont.ts +0 -31
  14. package/src/createShorthands.ts +0 -5
  15. package/src/createTamagui.ts +0 -218
  16. package/src/createTheme.ts +0 -22
  17. package/src/createTokens.ts +0 -88
  18. package/src/createVariable.ts +0 -26
  19. package/src/helpers/addStylesUsingClassname.tsx +0 -60
  20. package/src/helpers/createMediaStyle.ts +0 -46
  21. package/src/helpers/createPropMapper.ts +0 -192
  22. package/src/helpers/createTamaguiProvider.tsx +0 -22
  23. package/src/helpers/extendStaticConfig.ts +0 -68
  24. package/src/helpers/fixNativeShadow.native.tsx +0 -27
  25. package/src/helpers/fixNativeShadow.tsx +0 -2
  26. package/src/helpers/getSplitStyles.tsx +0 -200
  27. package/src/helpers/getStylesAtomic.native.ts +0 -3
  28. package/src/helpers/getStylesAtomic.ts +0 -103
  29. package/src/helpers/insertStyleRule.tsx +0 -18
  30. package/src/helpers/isObj.ts +0 -1
  31. package/src/helpers/isTamaguiElement.tsx +0 -5
  32. package/src/helpers/matchMedia.native.ts +0 -6
  33. package/src/helpers/matchMedia.ts +0 -17
  34. package/src/helpers/themeable.tsx +0 -42
  35. package/src/helpers/validate.ts +0 -59
  36. package/src/hooks/useConstant.tsx +0 -10
  37. package/src/hooks/useFeatures.tsx +0 -79
  38. package/src/hooks/useMedia.tsx +0 -196
  39. package/src/hooks/usePressable.tsx +0 -9
  40. package/src/hooks/useTheme.tsx +0 -107
  41. package/src/index.ts +0 -32
  42. package/src/static/postProcessStyles.tsx +0 -20
  43. package/src/static.ts +0 -22
  44. package/src/styled.ts +0 -82
  45. package/src/types.tsx +0 -562
  46. package/src/views/Animated.tsx +0 -121
  47. package/src/views/Stack.tsx +0 -21
  48. package/src/views/Text.tsx +0 -67
  49. package/src/views/TextAncestorContext.tsx +0 -11
  50. package/src/views/Theme.tsx +0 -94
  51. package/src/views/ThemeContext.tsx +0 -5
  52. package/src/views/ThemeInverse.tsx +0 -22
  53. package/src/views/ThemeManagerContext.tsx +0 -62
  54. package/src/views/ThemeProvider.tsx +0 -52
package/src/types.tsx DELETED
@@ -1,562 +0,0 @@
1
- import React, { RefObject } from 'react'
2
- import { TextProps as ReactTextProps, TextStyle } from 'react-native'
3
- import { GestureResponderEvent, View, ViewProps, ViewStyle } from 'react-native'
4
-
5
- import { Variable } from './createVariable'
6
- import { ThemeProviderProps } from './views/ThemeProvider'
7
-
8
- // to prevent things from going circular, hoisting some types in this file
9
- // to generally order them as building up towards TamaguiConfig
10
-
11
- export interface CreateTokens<Val extends number | string | Variable = number | string | Variable> {
12
- font: { [key: string]: GenericFont }
13
- color: { [key: string]: Val }
14
- space: { [key: string]: Val }
15
- size: { [key: string]: Val }
16
- radius: { [key: string]: Val }
17
- zIndex: { [key: string]: Val }
18
- }
19
-
20
- type GenericTokens = CreateTokens
21
- type GenericThemes = {
22
- [key: string]: {
23
- // defined for our tamagui kit , we could do this inside `tamagui`
24
- // but maybe helpful to have some sort of universally shared things +
25
- // + enforce if they want their own, redefine in their design sys
26
- bg: string | Variable
27
- bg2: string | Variable
28
- bg3: string | Variable
29
- bg4: string | Variable
30
- color: string | Variable
31
- color2: string | Variable
32
- color3: string | Variable
33
- color4: string | Variable
34
- borderColor: string | Variable
35
- borderColor2: string | Variable
36
- shadowColor: string | Variable
37
- shadowColor2: string | Variable
38
- }
39
- }
40
- type GenericShorthands = {}
41
- type GenericMedia<K extends string = string> = {
42
- // name => media shorthand name (camelCase) => value
43
- [key in K]: {
44
- [key: string]: number | string
45
- }
46
- }
47
-
48
- // this is the "main" typed object, which users re-define
49
- // (internal) keep all types directly on this object and reference them from elsewhere
50
- //
51
- // const config = createTamagui(...)
52
- // type MyConfig = typeof config
53
- // declare module 'tamagui' {
54
- // export interface TamaguiCustomConfig extends MyConfig {}
55
- // }
56
- // now your whole app/kit should be typed correctly
57
- //
58
- export interface TamaguiCustomConfig {}
59
-
60
- export interface TamaguiConfig
61
- extends Omit<GenericTamaguiConfig, keyof TamaguiCustomConfig>,
62
- TamaguiCustomConfig {}
63
-
64
- export type CreateTamaguiConfig<
65
- A extends GenericTokens,
66
- B extends GenericThemes,
67
- C extends GenericShorthands,
68
- D extends GenericMedia
69
- > = Partial<Pick<ThemeProviderProps, 'defaultTheme' | 'disableRootThemeClass'>> & {
70
- tokens: A
71
- themes: B
72
- shorthands: C
73
- media: D
74
- }
75
-
76
- // for use in creation functions so it doesnt get overwrtitten
77
- export type GenericTamaguiConfig = CreateTamaguiConfig<
78
- GenericTokens,
79
- GenericThemes,
80
- GenericShorthands,
81
- GenericMedia
82
- >
83
-
84
- // since TamaguiConfig will be re-declared, these will all be typed globally
85
- export type ThemeObject = TamaguiConfig['themes'][keyof TamaguiConfig['themes']]
86
- export type Tokens = TamaguiConfig['tokens']
87
- export type Shorthands = TamaguiConfig['shorthands']
88
- export type Media = TamaguiConfig['media']
89
- export type Themes = TamaguiConfig['themes']
90
- // themes
91
- export type ThemeName = keyof Themes extends `${infer Prefix}-${string}`
92
- ? Prefix | keyof Themes
93
- : keyof Themes
94
- export type ThemeKeys = keyof ThemeObject
95
- export type ThemeKeyVariables = `$${ThemeKeys}`
96
- // export type Spaces = TamaguiConfig['tokens']['spaces'][keyof TamaguiConfig['tokens']['spaces']]
97
- // export type FontSizes = TamaguiConfig['tokens']['fontSizes'][keyof TamaguiConfig['tokens']['fontSizes']]
98
- // export type Colors = TamaguiConfig['tokens']['colors'][keyof TamaguiConfig['tokens']['colors']]
99
-
100
- // this is the config generated via createTamagui()
101
- export type TamaguiInternalConfig<
102
- A extends GenericTokens = GenericTokens,
103
- B extends GenericThemes = GenericThemes,
104
- C extends GenericShorthands = GenericShorthands,
105
- D extends GenericMedia = GenericMedia
106
- > = CreateTamaguiConfig<A, B, C, D> & {
107
- Provider: (props: TamaguiProviderProps) => any
108
- // with $ prefixes for fast lookups (one time cost at startup vs every render)
109
- themeParsed: { [key: string]: Variable }
110
- tokensParsed: CreateTokens<Variable>
111
- themeConfig: any
112
- getCSS: () => string
113
- parsed: boolean
114
- }
115
-
116
- // prevents const intersections from being clobbered into string, keeping the consts
117
- export type UnionableString = string & {}
118
- export type UnionableNumber = number & {}
119
- export type PropTypes<A extends StaticComponent> = A extends React.FunctionComponent<infer Props>
120
- ? Props
121
- : unknown
122
-
123
- export type GenericFont = {
124
- size: { [key: string | number]: number | Variable }
125
- lineHeight: { [key: string | number]: number | Variable }
126
- letterSpacing: { [key: string | number]: number | Variable }
127
- weight: { [key: string | number]: string | Variable }
128
- family: string | Variable
129
- }
130
-
131
- // media
132
- export type MediaKeys = keyof Media
133
- export type MediaQueryObject = { [key: string]: string | number | string }
134
- export type MediaQueryState = {
135
- [key in string]: boolean
136
- }
137
- export type MediaQueryKey = keyof Media
138
- export type MediaProps<A> = {
139
- [key in `$${MediaQueryKey}`]?: A
140
- }
141
- export type MediaQueries = {
142
- [key in MediaQueryKey]: MediaQueryObject
143
- }
144
- export type ConfigureMediaQueryOptions = {
145
- queries?: MediaQueries
146
- defaultActive?: MediaQueryKey[]
147
- }
148
-
149
- export type TransformStyleProps = {
150
- x?: number
151
- y?: number
152
- perspective?: number
153
- scale?: number
154
- scaleX?: number
155
- scaleY?: number
156
- skewX?: string
157
- skewY?: string
158
- matrix?: number[]
159
- rotate?: string
160
- rotateY?: string
161
- rotateX?: string
162
- rotateZ?: string
163
- }
164
-
165
- // createComponent props helpers
166
-
167
- //
168
- // base props that are accepted by createComponent (additional to react-native-web)
169
- //
170
- type ComponentPropsBase = {
171
- className?: string
172
- tag?: string
173
- animated?: boolean
174
- onHoverIn?: (e: MouseEvent) => any
175
- onHoverOut?: (e: MouseEvent) => any
176
- onPress?: (e: GestureResponderEvent) => any
177
- onPressIn?: (e: GestureResponderEvent) => any
178
- onPressOut?: (e: GestureResponderEvent) => any
179
- // WEB ONLY
180
- onMouseEnter?: (e: GestureResponderEvent) => any
181
- // WEB ONLY
182
- onMouseLeave?: (e: GestureResponderEvent) => any
183
- space?: Tokens['space'][keyof Tokens['space']] | boolean | string | number
184
- pointerEvents?: string
185
- }
186
-
187
- type GetTokenFontKeysFor<A extends 'size' | 'weight' | 'letterSpacing' | 'family' | 'lineHeight'> =
188
- keyof Tokens['font'][keyof Tokens['font']][A]
189
-
190
- export type SpaceTokens = `$${keyof Tokens['space']}`
191
-
192
- //
193
- // adds in theme short values to relevant props
194
- //
195
- type ThemeValue<A> = Omit<A, string> | UnionableString | Variable
196
- export type WithThemeValues<T extends object> = {
197
- [K in keyof T]:
198
- | ThemeValue<T[K]>
199
- | (K extends ColorableKeys
200
- ? ThemeKeyVariables
201
- : K extends SizeKeys
202
- ? `$${keyof Tokens['size']}`
203
- : K extends FontKeys
204
- ? `$${keyof Tokens['font']}`
205
- : K extends FontSizeKeys
206
- ? `$${GetTokenFontKeysFor<'size'>}`
207
- : K extends SpaceKeys
208
- ? `$${keyof Tokens['space']}`
209
- : K extends ColorKeys
210
- ? `$${keyof Tokens['color']}`
211
- : K extends ZIndexKeys
212
- ? `$${keyof Tokens['zIndex']}`
213
- : K extends LineHeightKeys
214
- ? `$${GetTokenFontKeysFor<'lineHeight'>}`
215
- : K extends FontWeightKeys
216
- ? `$${GetTokenFontKeysFor<'weight'>}`
217
- : K extends FontLetterSpacingKeys
218
- ? `$${GetTokenFontKeysFor<'letterSpacing'>}`
219
- : {})
220
- }
221
-
222
- //
223
- // adds in shorthand props
224
- //
225
- type WithShorthands<StyleProps> = {
226
- [Key in keyof Shorthands]?: Shorthands[Key] extends keyof StyleProps
227
- ? StyleProps[Shorthands[Key]] | null
228
- : undefined
229
- }
230
-
231
- //
232
- // add both theme and shorthands
233
- //
234
- type WithThemeAndShorthands<A extends object> = WithThemeValues<A> &
235
- WithShorthands<WithThemeValues<A>>
236
-
237
- //
238
- // adds theme and shorthands + pseudo styles with both
239
- //
240
- type WithThemeShorthandsAndPseudos<A extends object> = WithThemeAndShorthands<A> & {
241
- hoverStyle?: WithThemeAndShorthands<A> | null
242
- pressStyle?: WithThemeAndShorthands<A> | null
243
- }
244
-
245
- //
246
- // adds theme, shorthands, psuedos, then all the previous to media queries
247
- //
248
- type WithThemeShorthandsPseudosAndMedia<A extends object> = WithThemeShorthandsAndPseudos<A> &
249
- MediaProps<WithThemeShorthandsAndPseudos<A>>
250
-
251
- //
252
- // Stack
253
- //
254
-
255
- type WebOnlyStyleProps = {
256
- // WEB ONLY
257
- cursor?: string
258
- // WEB ONLY
259
- contain?: 'none' | 'strict' | 'content' | 'size' | 'layout' | 'paint' | string
260
- // WEB ONLY values: inherit, inline, block, content
261
- display?: 'inherit' | 'none' | 'inline' | 'block' | 'contents' | 'flex' | 'inline-flex'
262
- // WEB ONLY pointerEvents can be a style prop
263
- pointerEvents?: ViewProps['pointerEvents']
264
- }
265
-
266
- export type StackStylePropsBase = Omit<ViewStyle, 'display' | 'backfaceVisibility' | 'elevation'> &
267
- TransformStyleProps &
268
- WebOnlyStyleProps
269
-
270
- export type StackStyleProps = WithThemeShorthandsPseudosAndMedia<StackStylePropsBase>
271
-
272
- export type StackProps = Omit<RNWInternalProps, 'children'> &
273
- Omit<ViewProps, 'display' | 'children'> &
274
- StackStyleProps &
275
- ComponentPropsBase & {
276
- ref?: RefObject<View | HTMLElement> | ((node: View | HTMLElement) => any)
277
- children?: any | any[]
278
- }
279
-
280
- //
281
- // Text props
282
- //
283
-
284
- // type EnhancedTextStyleProps = WithThemeValues<
285
- // Omit<TextStyle, 'display' | 'backfaceVisibility'> & TransformStyleProps
286
- // >
287
- // export type TextStylePropsBase = EnhancedTextStyleProps
288
- // export type TextStyleProps<S = TextStylePropsBase> = S & {
289
- // hoverStyle?: S | null
290
- // pressStyle?: S | null
291
- // }
292
-
293
- type TextStyleProps = WithThemeShorthandsPseudosAndMedia<
294
- Omit<TextStyle, 'display' | 'backfaceVisibility'> & TransformStyleProps & WebOnlyStyleProps
295
- >
296
-
297
- export type TextProps = Omit<ReactTextProps, 'style'> &
298
- TextStyleProps &
299
- ComponentPropsBase & {
300
- ellipse?: boolean
301
- selectable?: boolean
302
- textDecorationDistance?: number
303
- }
304
-
305
- //
306
- // StaticComponent
307
- //
308
-
309
- export type StaticComponent<
310
- Props = any,
311
- VariantProps = any,
312
- StaticConfParsed = StaticConfigParsed,
313
- ParentVariantProps = any
314
- > = React.FunctionComponent<Props> & {
315
- staticConfig: StaticConfParsed
316
- variantProps?: VariantProps
317
-
318
- /*
319
- * Only needed for more complex components
320
- * If you create a styled frame component this is a HoC to extract
321
- * styles from all parents.
322
- */
323
- extractable: <X>(a: X, opts?: StaticConfig) => X
324
- }
325
-
326
- export type TamaguiProviderProps = Partial<Omit<ThemeProviderProps, 'children'>> & {
327
- initialWindowMetrics?: any
328
- fallback?: any
329
- children?: any
330
- }
331
-
332
- export type RNWInternalProps = {
333
- accessibilityState?: {
334
- busy?: boolean
335
- checked?: boolean | 'mixed'
336
- disabled?: boolean
337
- expanded?: boolean
338
- grabbed?: boolean
339
- hidden?: boolean
340
- invalid?: boolean
341
- modal?: boolean
342
- pressed?: boolean
343
- readonly?: boolean
344
- required?: boolean
345
- selected?: boolean
346
- }
347
- accessibilityValue?: {
348
- max?: number
349
- min?: number
350
- now?: number
351
- text?: string
352
- }
353
- children?: any
354
- focusable?: boolean
355
- nativeID?: string
356
- onBlur?: (e: any) => void
357
- onClick?: (e: any) => void
358
- onClickCapture?: (e: any) => void
359
- onContextMenu?: (e: any) => void
360
- onFocus?: (e: any) => void
361
- onKeyDown?: (e: any) => void
362
- onKeyUp?: (e: any) => void
363
- onMoveShouldSetResponder?: (e: any) => boolean
364
- onMoveShouldSetResponderCapture?: (e: any) => boolean
365
- onResponderEnd?: (e: any) => void
366
- onResponderGrant?: (e: any) => void
367
- onResponderMove?: (e: any) => void
368
- onResponderReject?: (e: any) => void
369
- onResponderRelease?: (e: any) => void
370
- onResponderStart?: (e: any) => void
371
- onResponderTerminate?: (e: any) => void
372
- onResponderTerminationRequest?: (e: any) => boolean
373
- onScrollShouldSetResponder?: (e: any) => boolean
374
- onScrollShouldSetResponderCapture?: (e: any) => boolean
375
- onSelectionChangeShouldSetResponder?: (e: any) => boolean
376
- onSelectionChangeShouldSetResponderCapture?: (e: any) => boolean
377
- onStartShouldSetResponder?: (e: any) => boolean
378
- onStartShouldSetResponderCapture?: (e: any) => boolean
379
- pointerEvents?: 'box-none' | 'none' | 'box-only' | 'auto'
380
- testID?: string
381
- // unstable
382
- dataSet?: Object
383
- onMouseDown?: (e: any) => void
384
- onMouseEnter?: (e: any) => void
385
- onMouseLeave?: (e: any) => void
386
- onMouseMove?: (e: any) => void
387
- onMouseOver?: (e: any) => void
388
- onMouseOut?: (e: any) => void
389
- onMouseUp?: (e: any) => void
390
- onScroll?: (e: any) => void
391
- onTouchCancel?: (e: any) => void
392
- onTouchCancelCapture?: (e: any) => void
393
- onTouchEnd?: (e: any) => void
394
- onTouchEndCapture?: (e: any) => void
395
- onTouchMove?: (e: any) => void
396
- onTouchMoveCapture?: (e: any) => void
397
- onTouchStart?: (e: any) => void
398
- onTouchStartCapture?: (e: any) => void
399
- onWheel?: (e: any) => void
400
- href?: string
401
- hrefAttrs?: { download?: boolean; rel?: string; target?: string }
402
- }
403
-
404
- export type StaticConfigParsed = StaticConfig & {
405
- parsed: true
406
- propMapper: (
407
- key: string,
408
- value: any,
409
- theme: ThemeObject,
410
- props: any
411
- ) => undefined | boolean | { [key: string]: any }
412
- variantsParsed?: {
413
- [key: string]: {
414
- [key: string]: any
415
- }
416
- }
417
- }
418
-
419
- export type StaticConfig = {
420
- Component?: StaticComponent
421
-
422
- variants?: {
423
- [key: string]: {
424
- [key: string]:
425
- | ((a: any, b: any) => any)
426
- | {
427
- [key: string]: any
428
- }
429
- }
430
- }
431
-
432
- /*
433
- * If you need to pass context or something, prevents from ever
434
- * flattening. The 'jsx' option means it will never flatten. if you
435
- * pass JSX as a children (if its purely string, it will still flatten).
436
- */
437
- neverFlatten?: boolean | 'jsx'
438
-
439
- /*
440
- * Determines ultimate output tag (Text vs View)
441
- */
442
- isText?: boolean
443
-
444
- /*
445
- * Which style keys are allowed to be extracted.
446
- */
447
- validStyles?: { [key: string]: boolean }
448
-
449
- /*
450
- * Allows for defining extra valid props to be extracted beyond
451
- * the default ones.
452
- */
453
- validPropsExtra?: { [key: string]: any }
454
-
455
- /*
456
- * Same as React.defaultProps, be sure to sync
457
- */
458
- defaultProps?: any
459
-
460
- /*
461
- * If this prop is encountered, bail on all optimization.
462
- */
463
- deoptProps?: Set<string>
464
-
465
- /*
466
- * A bit odd, only for more advanced heirarchies.
467
- * Indicates that the component will set this prop so the
468
- * static extraction can ensure it sets them to ={undefined}
469
- * so they get overriddent. In the future, this can be smarter.
470
- */
471
- ensureOverriddenProp?: { [key: string]: boolean }
472
-
473
- /*
474
- * We need to wrap children
475
- */
476
- isZStack?: boolean
477
- }
478
-
479
- type ColorableKeys =
480
- | 'color'
481
- | 'backgroundColor'
482
- | 'borderColor'
483
- | 'borderTopColor'
484
- | 'borderBottomColor'
485
- | 'borderLeftColor'
486
- | 'borderRightColor'
487
- | 'shadowColor'
488
-
489
- type SizeKeys = 'width' | 'height' | 'minWidth' | 'minHeight' | 'maxWidth' | 'maxHeight'
490
-
491
- type FontKeys = 'fontFamily'
492
-
493
- type FontSizeKeys = 'fontSize'
494
-
495
- type FontWeightKeys = 'fontWeight'
496
-
497
- type FontLetterSpacingKeys = 'letterSpacing'
498
-
499
- type LineHeightKeys = 'lineHeight'
500
-
501
- type ZIndexKeys = 'zIndex'
502
-
503
- type ColorKeys =
504
- | 'color'
505
- | 'backgroundColor'
506
- | 'borderColor'
507
- | 'borderBottomColor'
508
- | 'borderTopColor'
509
- | 'borderLeftColor'
510
- | 'borderRightColor'
511
-
512
- type SpaceKeys =
513
- | 'padding'
514
- | 'paddingHorizontal'
515
- | 'paddingVertical'
516
- | 'paddingLeft'
517
- | 'paddingTop'
518
- | 'paddingBottom'
519
- | 'paddingLeft'
520
- | 'paddingRight'
521
- | 'paddingEnd'
522
- | 'paddingStart'
523
- | 'margin'
524
- | 'marginHorizontal'
525
- | 'marginVertical'
526
- | 'marginLeft'
527
- | 'marginTop'
528
- | 'marginBottom'
529
- | 'marginLeft'
530
- | 'marginRight'
531
- | 'marginEnd'
532
- | 'marginStart'
533
- | 'x'
534
- | 'y'
535
- | 'scale'
536
- | 'scaleX'
537
- | 'scaleY'
538
- | 'borderTopEndRadius'
539
- | 'borderTopLeftRadius'
540
- | 'borderTopRightRadius'
541
- | 'borderTopStartRadius'
542
- | 'borderBottomEndRadius'
543
- | 'borderBottomLeftRadius'
544
- | 'borderBottomRightRadius'
545
- | 'borderBottomStartRadius'
546
- | 'borderBottomWidth'
547
- | 'borderLeftWidth'
548
- | 'borderRadius'
549
- | 'borderRightWidth'
550
- | 'borderTopEndRadius'
551
- | 'borderTopLeftRadius'
552
- | 'borderTopRightRadius'
553
- | 'borderEndWidth'
554
- | 'borderStartWidth'
555
- | 'borderTopStartRadius'
556
- | 'borderTopWidth'
557
- | 'borderWidth'
558
- | 'left'
559
- | 'top'
560
- | 'right'
561
- | 'bottom'
562
- | 'shadowOffset'
@@ -1,121 +0,0 @@
1
- import React, { useMemo } from 'react'
2
- import {
3
- Animated,
4
- PerpectiveTransform,
5
- RotateTransform,
6
- RotateXTransform,
7
- RotateYTransform,
8
- RotateZTransform,
9
- ScaleTransform,
10
- ScaleXTransform,
11
- ScaleYTransform,
12
- SkewXTransform,
13
- SkewYTransform,
14
- TranslateXTransform,
15
- TranslateYTransform,
16
- } from 'react-native'
17
-
18
- import { useIsomorphicLayoutEffect } from '../constants/platform'
19
- import { useConstant } from '../hooks/useConstant'
20
- import { StackProps } from '../types'
21
- import { Stack } from './Stack'
22
-
23
- const defaultAnimation = {
24
- from: {
25
- opacity: 0,
26
- translateY: 12,
27
- },
28
- to: {
29
- opacity: 1,
30
- translateY: 0,
31
- },
32
- }
33
-
34
- type AnimatableProps = Partial<
35
- Pick<StackProps, 'backgroundColor' | 'borderColor' | 'opacity'> &
36
- PerpectiveTransform &
37
- RotateTransform &
38
- RotateXTransform &
39
- RotateYTransform &
40
- RotateZTransform &
41
- ScaleTransform &
42
- ScaleXTransform &
43
- ScaleYTransform &
44
- TranslateXTransform &
45
- TranslateYTransform &
46
- SkewXTransform &
47
- SkewYTransform
48
- >
49
-
50
- const styleKeys = {
51
- opacity: true,
52
- backgroundColor: true,
53
- borderColor: true,
54
- }
55
-
56
- export type AnimatedStackProps = StackProps & {
57
- animateState?: 'in' | 'out'
58
- velocity?: number
59
- animation?: {
60
- from: AnimatableProps
61
- to: AnimatableProps
62
- }
63
- }
64
-
65
- export const AnimatedStack = ({
66
- animateState = 'in',
67
- animation = defaultAnimation,
68
- velocity = 6,
69
- children,
70
- animated,
71
- ...props
72
- }: AnimatedStackProps) => {
73
- const driver = useConstant(() => {
74
- return new Animated.Value(0)
75
- })
76
-
77
- const animatedProps = useMemo(() => {
78
- if (!animated) {
79
- return null
80
- }
81
-
82
- const styleProps = {}
83
- const transform: any = []
84
-
85
- for (const key in animation.from) {
86
- const fromVal = animation.from[key]
87
- const toVal = animation.to[key]
88
- const interpolatedVal = driver.interpolate({
89
- inputRange: [0, 1],
90
- outputRange: [fromVal, toVal],
91
- })
92
- if (styleKeys[key]) {
93
- styleProps[key] = interpolatedVal
94
- } else {
95
- transform.push({
96
- [key]: interpolatedVal,
97
- })
98
- }
99
- }
100
- return { transform, ...styleProps }
101
- }, [animated, animateState])
102
-
103
- useIsomorphicLayoutEffect(() => {
104
- if (!animated) {
105
- return
106
- }
107
- Animated.spring(driver, {
108
- useNativeDriver: true,
109
- velocity,
110
- toValue: animateState === 'in' ? 1 : 0,
111
- }).start()
112
- }, [animated, animateState])
113
-
114
- const childrenMemo = useMemo(() => children, [children])
115
-
116
- return (
117
- <Stack animated={animated} {...props} {...animatedProps}>
118
- {childrenMemo}
119
- </Stack>
120
- )
121
- }
@@ -1,21 +0,0 @@
1
- import { stackDefaultStyles } from '../constants/constants'
2
- import { createComponent } from '../createComponent'
3
- import { StackProps } from '../types'
4
-
5
- export const Stack = createComponent<StackProps>({
6
- defaultProps: {
7
- ...stackDefaultStyles,
8
- flexDirection: 'column',
9
- },
10
- })
11
-
12
- // test types
13
- // export const YStack = styled(Stack, {
14
- // flexDirection: 'column',
15
- // })
16
- // // test types
17
- // const x00 = <Stack missing={0} /> // should err
18
- // const x0 = <YStack missing={0} /> // should err
19
- // const x1 = (props: StackProps) => <YStack {...props} />
20
- // type ys = typeof YStack
21
- // type ysv = ys extends StaticComponent<any, infer V> ? V : unknown