@tamagui/core 1.0.1-beta.147 → 1.0.1-beta.150
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.
- package/dist/cjs/constants/platform.js.map +2 -2
- package/dist/cjs/createComponent.js +133 -48
- package/dist/cjs/createComponent.js.map +2 -2
- package/dist/cjs/helpers/getSplitStyles.js +57 -50
- package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
- package/dist/cjs/helpers/mergeTransform.js.map +2 -2
- package/dist/cjs/hooks/useFeatures.js +0 -120
- package/dist/cjs/hooks/useFeatures.js.map +2 -2
- package/dist/cjs/hooks/useTheme.js +3 -2
- package/dist/cjs/hooks/useTheme.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/constants/platform.js.map +2 -2
- package/dist/esm/createComponent.js +141 -51
- package/dist/esm/createComponent.js.map +2 -2
- package/dist/esm/helpers/getSplitStyles.js +57 -50
- package/dist/esm/helpers/getSplitStyles.js.map +2 -2
- package/dist/esm/helpers/mergeTransform.js.map +2 -2
- package/dist/esm/hooks/useFeatures.js +0 -120
- package/dist/esm/hooks/useFeatures.js.map +2 -2
- package/dist/esm/hooks/useTheme.js +3 -2
- package/dist/esm/hooks/useTheme.js.map +2 -2
- package/package.json +10 -9
- package/src/constants/platform.ts +1 -0
- package/src/createComponent.tsx +218 -57
- package/src/helpers/getSplitStyles.tsx +70 -65
- package/src/helpers/mergeTransform.ts +2 -0
- package/src/hooks/useTheme.tsx +4 -4
- package/src/types.tsx +3 -2
- package/types/helpers/getSplitStyles.d.ts +1 -0
- package/types/hooks/useFeatures.d.ts +0 -1
- package/types/types.d.ts +3 -2
- package/src/hooks/useFeatures.tsx +0 -289
package/types/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Properties } from 'csstype';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { RefObject } from 'react';
|
|
3
3
|
import { GestureResponderEvent, Image, PressableProps, TextProps as ReactTextProps, Text, TextInput, TextStyle, View, ViewProps, ViewStyle } from 'react-native';
|
|
4
4
|
import { Variable } from './createVariable';
|
|
5
5
|
import { ResolveVariableTypes } from './helpers/createPropMapper';
|
|
@@ -492,6 +492,7 @@ export declare type AnimationDriver<A extends AnimationConfig = AnimationConfig>
|
|
|
492
492
|
};
|
|
493
493
|
export declare type UseAnimationProps = TamaguiComponentPropsBase & Record<string, any>;
|
|
494
494
|
export declare type UseAnimationHelpers = {
|
|
495
|
+
hostRef: RefObject<HTMLElement | View>;
|
|
495
496
|
staticConfig: StaticConfigParsed;
|
|
496
497
|
getStyle: (props?: {
|
|
497
498
|
isEntering?: boolean;
|
|
@@ -504,7 +505,7 @@ export declare type UseAnimationHelpers = {
|
|
|
504
505
|
onDidAnimate?: any;
|
|
505
506
|
delay?: number;
|
|
506
507
|
};
|
|
507
|
-
export declare type UseAnimationHook = (props: UseAnimationProps, helpers: UseAnimationHelpers) => {
|
|
508
|
+
export declare type UseAnimationHook = (props: UseAnimationProps, helpers: UseAnimationHelpers) => null | {
|
|
508
509
|
style?: StackStylePropsBase | StackStylePropsBase[];
|
|
509
510
|
};
|
|
510
511
|
export {};
|
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { RefObject } from 'react'
|
|
3
|
-
import { View, ViewStyle } from 'react-native'
|
|
4
|
-
|
|
5
|
-
import { getConfig } from '../config'
|
|
6
|
-
import { useIsomorphicLayoutEffect } from '../constants/platform'
|
|
7
|
-
import { getSubStyle } from '../helpers/getSplitStyles'
|
|
8
|
-
import {
|
|
9
|
-
PseudoStyles,
|
|
10
|
-
SplitStyleState,
|
|
11
|
-
StaticConfigParsed,
|
|
12
|
-
TamaguiComponentState,
|
|
13
|
-
TamaguiInternalConfig,
|
|
14
|
-
UseAnimationHook,
|
|
15
|
-
UseAnimationProps,
|
|
16
|
-
} from '../types'
|
|
17
|
-
import { addMediaQueryListener, mediaState, removeMediaQueryListener } from './useMedia'
|
|
18
|
-
|
|
19
|
-
type FeatureDefinition = {
|
|
20
|
-
isEnabled: (props: any) => boolean
|
|
21
|
-
Component: any
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
type FeatureUtils = {
|
|
25
|
-
forceUpdate: Function
|
|
26
|
-
state: SplitStyleState
|
|
27
|
-
setStateShallow: (next: Partial<TamaguiComponentState>) => void
|
|
28
|
-
useAnimations?: UseAnimationHook
|
|
29
|
-
pseudos: PseudoStyles
|
|
30
|
-
style: ViewStyle | null | undefined
|
|
31
|
-
staticConfig: StaticConfigParsed
|
|
32
|
-
theme: any
|
|
33
|
-
onDidAnimate?: () => void
|
|
34
|
-
hostRef: RefObject<HTMLElement | View>
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const createDefinition = ({
|
|
38
|
-
Component,
|
|
39
|
-
propNames,
|
|
40
|
-
}: {
|
|
41
|
-
Component: (props: { _utils: FeatureUtils; [key: string]: any }) => void
|
|
42
|
-
propNames: string[]
|
|
43
|
-
}): FeatureDefinition => ({
|
|
44
|
-
isEnabled: (props: any) => propNames.some((name) => !!props[name]),
|
|
45
|
-
Component,
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
let featureDefinitions: Record<string, FeatureDefinition> | null = null
|
|
49
|
-
let tamaguiConfig: TamaguiInternalConfig
|
|
50
|
-
|
|
51
|
-
type FeatureKeys = keyof ReturnType<typeof loadFeatures>
|
|
52
|
-
|
|
53
|
-
export const useFeatures = (props: any, utils?: FeatureUtils) => {
|
|
54
|
-
if (!featureDefinitions) {
|
|
55
|
-
featureDefinitions = loadFeatures()
|
|
56
|
-
}
|
|
57
|
-
const elements: JSX.Element[] = []
|
|
58
|
-
const enabled: { [key in FeatureKeys]?: boolean } = {}
|
|
59
|
-
for (const name in featureDefinitions) {
|
|
60
|
-
const { isEnabled, Component } = featureDefinitions[name]
|
|
61
|
-
if (isEnabled(props) && Component) {
|
|
62
|
-
enabled[name] = true
|
|
63
|
-
elements.push(<Component key={name} {...props} _utils={utils} />)
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return {
|
|
67
|
-
elements,
|
|
68
|
-
enabled,
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function loadFeatures() {
|
|
73
|
-
return {
|
|
74
|
-
// loads animations and sets state with the results
|
|
75
|
-
animation: loadAnimationFeature(),
|
|
76
|
-
|
|
77
|
-
// will update the parent whenever media query changes
|
|
78
|
-
// no need on web, media queries are inserted and run in css
|
|
79
|
-
mediaQuery: loadMediaQueryFeature(),
|
|
80
|
-
} as const
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function loadAnimationFeature() {
|
|
84
|
-
tamaguiConfig = tamaguiConfig || getConfig()
|
|
85
|
-
|
|
86
|
-
return createDefinition({
|
|
87
|
-
Component: ({ _utils, ...props }) => {
|
|
88
|
-
const {
|
|
89
|
-
state,
|
|
90
|
-
useAnimations,
|
|
91
|
-
pseudos,
|
|
92
|
-
style: inStyle,
|
|
93
|
-
setStateShallow,
|
|
94
|
-
staticConfig,
|
|
95
|
-
theme,
|
|
96
|
-
onDidAnimate,
|
|
97
|
-
} = _utils
|
|
98
|
-
|
|
99
|
-
if (!useAnimations) {
|
|
100
|
-
// eslint-disable-next-line no-console
|
|
101
|
-
console.error('no useAnimations hook provided')
|
|
102
|
-
return null
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// we always have .animation set
|
|
106
|
-
const propsWithAnimation = props as UseAnimationProps
|
|
107
|
-
|
|
108
|
-
const res = useAnimations(propsWithAnimation, {
|
|
109
|
-
state,
|
|
110
|
-
pseudos,
|
|
111
|
-
onDidAnimate,
|
|
112
|
-
staticConfig,
|
|
113
|
-
getStyle({ isExiting, isEntering, exitVariant, enterVariant } = {}) {
|
|
114
|
-
// we have to merge such that transforms keys all exist
|
|
115
|
-
const style = inStyle || {}
|
|
116
|
-
|
|
117
|
-
const enterStyle = isEntering
|
|
118
|
-
? enterVariant && staticConfig.variants?.[enterVariant]['true']
|
|
119
|
-
? getSubStyle(
|
|
120
|
-
'',
|
|
121
|
-
staticConfig.variants?.[enterVariant]['true'],
|
|
122
|
-
staticConfig,
|
|
123
|
-
theme,
|
|
124
|
-
props,
|
|
125
|
-
state,
|
|
126
|
-
tamaguiConfig
|
|
127
|
-
) || pseudos.enterStyle
|
|
128
|
-
: null || pseudos.enterStyle
|
|
129
|
-
: null
|
|
130
|
-
|
|
131
|
-
const exitStyle = isExiting
|
|
132
|
-
? exitVariant && staticConfig.variants?.[exitVariant]['true']
|
|
133
|
-
? getSubStyle(
|
|
134
|
-
'',
|
|
135
|
-
staticConfig.variants?.[exitVariant]['true'],
|
|
136
|
-
staticConfig,
|
|
137
|
-
theme,
|
|
138
|
-
props,
|
|
139
|
-
state,
|
|
140
|
-
tamaguiConfig
|
|
141
|
-
) || pseudos.exitStyle
|
|
142
|
-
: null || pseudos.exitStyle
|
|
143
|
-
: null
|
|
144
|
-
|
|
145
|
-
// if you have hoverStyle={{ scale: 1.1 }} and don't have scale set on the base style
|
|
146
|
-
// no animation will run! this is really confusing. this will look at all variants,
|
|
147
|
-
// and fill in base styles if they don't exist. eg:
|
|
148
|
-
// input:
|
|
149
|
-
// base: {}
|
|
150
|
-
// hoverStyle: { scale: 2 }
|
|
151
|
-
// enterStyle: { x: 100 }
|
|
152
|
-
// output:
|
|
153
|
-
// base: { x: 0, scale: 1 }
|
|
154
|
-
ensureBaseHasDefaults(
|
|
155
|
-
style,
|
|
156
|
-
enterStyle,
|
|
157
|
-
pseudos.hoverStyle,
|
|
158
|
-
pseudos.focusStyle,
|
|
159
|
-
pseudos.pressStyle,
|
|
160
|
-
pseudos.pressStyle
|
|
161
|
-
)
|
|
162
|
-
|
|
163
|
-
enterStyle && merge(style, enterStyle)
|
|
164
|
-
state.hover && pseudos.hoverStyle && merge(style, pseudos.hoverStyle)
|
|
165
|
-
state.focus && pseudos.focusStyle && merge(style, pseudos.focusStyle)
|
|
166
|
-
state.press && pseudos.pressStyle && merge(style, pseudos.pressStyle)
|
|
167
|
-
exitStyle && merge(style, exitStyle)
|
|
168
|
-
|
|
169
|
-
if (process.env.NODE_ENV === 'development') {
|
|
170
|
-
if (props['debug']) {
|
|
171
|
-
// eslint-disable-next-line no-console
|
|
172
|
-
console.log('animation style', style)
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return style
|
|
177
|
-
},
|
|
178
|
-
//, delay
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
useIsomorphicLayoutEffect(() => {
|
|
182
|
-
setStateShallow({
|
|
183
|
-
animation: res,
|
|
184
|
-
})
|
|
185
|
-
}, [res])
|
|
186
|
-
|
|
187
|
-
return null
|
|
188
|
-
},
|
|
189
|
-
propNames: ['animation'],
|
|
190
|
-
})
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const defaults = {
|
|
194
|
-
left: 0,
|
|
195
|
-
right: 0,
|
|
196
|
-
top: 0,
|
|
197
|
-
bottom: 0,
|
|
198
|
-
opacity: 1,
|
|
199
|
-
translateX: 0,
|
|
200
|
-
translateY: 0,
|
|
201
|
-
skew: 0,
|
|
202
|
-
skewX: 0,
|
|
203
|
-
skewY: 0,
|
|
204
|
-
scale: 1,
|
|
205
|
-
rotate: '0deg',
|
|
206
|
-
rotateY: '0deg',
|
|
207
|
-
rotateX: '0deg',
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function ensureBaseHasDefaults(base: ViewStyle, ...pseudos: (ViewStyle | null | undefined)[]) {
|
|
211
|
-
for (const pseudo of pseudos) {
|
|
212
|
-
if (!pseudo) continue
|
|
213
|
-
for (const key in pseudo) {
|
|
214
|
-
const val = pseudo[key]
|
|
215
|
-
if (key === 'transform') {
|
|
216
|
-
if (typeof val === 'string') {
|
|
217
|
-
continue
|
|
218
|
-
}
|
|
219
|
-
for (const t of val) {
|
|
220
|
-
const tkey = Object.keys(t)[0]
|
|
221
|
-
const defaultVal = defaults[tkey]
|
|
222
|
-
const tDefaultVal = { [tkey]: defaultVal } as any
|
|
223
|
-
if (!base.transform) {
|
|
224
|
-
base.transform = [tDefaultVal]
|
|
225
|
-
} else {
|
|
226
|
-
if (!base.transform.find((x) => x[tkey])) {
|
|
227
|
-
base.transform.push(tDefaultVal)
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
} else {
|
|
232
|
-
if (!(key in base)) {
|
|
233
|
-
base[key] = defaults[key]
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function merge(base: ViewStyle, next: ViewStyle) {
|
|
241
|
-
if (!next.transform || !base.transform) {
|
|
242
|
-
Object.assign(base, next)
|
|
243
|
-
return
|
|
244
|
-
}
|
|
245
|
-
const { transform, ...rest } = next
|
|
246
|
-
Object.assign(base, rest)
|
|
247
|
-
for (const t of transform) {
|
|
248
|
-
const key = Object.keys(t)[0]
|
|
249
|
-
const existing = base.transform.find((x) => key in x)
|
|
250
|
-
if (existing) {
|
|
251
|
-
existing[key] = t[key]
|
|
252
|
-
} else {
|
|
253
|
-
base.transform.push(t)
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
function loadMediaQueryFeature() {
|
|
259
|
-
const mediaPropNames = Object.keys(mediaState)
|
|
260
|
-
|
|
261
|
-
return createDefinition({
|
|
262
|
-
Component: (props: any) => {
|
|
263
|
-
const mediaKeys = mediaPropNames.filter((x) => x in props)
|
|
264
|
-
|
|
265
|
-
useIsomorphicLayoutEffect(() => {
|
|
266
|
-
for (const key of mediaKeys) {
|
|
267
|
-
addMediaQueryListener(key, props._utils.forceUpdate)
|
|
268
|
-
}
|
|
269
|
-
return () => {
|
|
270
|
-
for (const key of mediaKeys) {
|
|
271
|
-
removeMediaQueryListener(key, props._utils.forceUpdate)
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}, [mediaKeys.join(',')])
|
|
275
|
-
|
|
276
|
-
return null
|
|
277
|
-
},
|
|
278
|
-
propNames: mediaPropNames,
|
|
279
|
-
})
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// TODO
|
|
283
|
-
// measureLayout: createDefinition({
|
|
284
|
-
// Component: (props) => {
|
|
285
|
-
// console.log('measure', props)
|
|
286
|
-
// return null
|
|
287
|
-
// },
|
|
288
|
-
// propNames: ['onLayout'],
|
|
289
|
-
// }),
|